I'm writing some tests in webrat with sinatra, and as part of that I need sessions.
The webrat wiki mentions that I need to call use Rack::Session::Cookie
instead of enable :sessions
- I have done this.
This particular test looks like this:
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
When I run it, I get the following error:
in `include': wrong argument type Class (expected Module) (TypeError)
from test.rb:77:in `<class:RegisterNewUserTest>'
from test.rb:74:in `<main>'
When I remove Webrat::Session
it goes away, but then my test is useless.
You're trying to include a class, which is not possible in ruby. Try using an instance of it :). Looking at webrat spec:
rack_test_session = Rack::Test::Session.new(Rack::MockSession.new(app))