Created
June 27, 2012 18:09
-
-
Save samwgoldman/3005777 to your computer and use it in GitHub Desktop.
Capybara session reset issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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