2012-02-04 78 views
1

我正在用sinatra在webrat中寫一些測試,並且作爲我需要會話的一部分。錯誤的參數類型類(預期的模塊)(TypeError)

webrat wiki提到我需要撥打use Rack::Session::Cookie而不是enable :sessions - 我已經這樣做了。

這個特殊的測試是這樣的:

class RegisterNewUserTest < Test::Unit::TestCase 
    include Webrat::Methods 
    include Webrat::Matchers 
    include Webrat::Session 


    def app 
    Rack::Builder.parse_file('config.ru').first 
    end 

    def register_new_user 
    visit '/signup' 
    fill_in "user[email]", :with => "[email protected]" 
    set_hidden_field "user[password]", :to => "password" 
    set_hidden_field "user[password_confirmation]", :to => "password" 
    click_button "Register" 
    end 
end 

當我運行它,我得到以下錯誤:

in `include': wrong argument type Class (expected Module) (TypeError) 
     from test.rb:77:in `<class:RegisterNewUserTest>' 
     from test.rb:74:in `<main>' 

當我刪除Webrat::Session它消失了,但後來我的測試是沒用的。

+1

你需要提一個問題;) – BoltClock 2012-03-09 07:31:40

回答

3

你試圖包含一個類,這在ruby中是不可能的。嘗試使用它的一個實例:)。看webrat的規格:

rack_test_session = Rack::Test::Session.new(Rack::MockSession.new(app)) 
相關問題