Skip to content

Instantly share code, notes, and snippets.

@samwgoldman
Created June 27, 2012 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samwgoldman/3005777 to your computer and use it in GitHub Desktop.
Save samwgoldman/3005777 to your computer and use it in GitHub Desktop.
Capybara session reset issue
require "rack"
require "capybara/rspec"
App = Rack::Builder.new do
map "/" do
run proc { |env|
request = Rack::Request.new(env)
response = Rack::Response.new
if request.cookies["logged_in"]
response.write "Logged in!"
else
response.write "<a href='/login'>Log In</a>"
end
response.finish
}
end
map "/login" do
run proc { |env|
response = Rack::Response.new
response.set_cookie("logged_in", true)
response.redirect "/"
response.finish
}
end
end
Capybara.app = App
Capybara.default_driver = :selenium
RSpec.configure do |config|
config.order = "default"
end
feature "Cookie session app" do
it "can log in" do
visit "/"
click_link "Log In"
page.should have_content("Logged in!")
end
it "isn't logged in after a normal example" do
visit "/"
page.should have_no_content("Logged in!")
end
it "is going to leave selenium on a different host" do
visit "/"
click_link "Log In"
visit "http://google.com/"
end
it "should not be logged when selenium was left on a different host" do
visit "/"
page.should have_no_content("Logged in!")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment