我正在用sinatra在webrat中编写一些测试,作为其中的一部分,我需要会话。
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时,它会消失,但这样我的测试就没用了。

最佳答案

您试图包含一个类,这在ruby中是不可能的尝试使用它的实例:)查看webrat规范:

rack_test_session = Rack::Test::Session.new(Rack::MockSession.new(app))

10-08 05:01