Permalink
Browse files

Merge remote-tracking branch 'upstream/master'

  • Loading branch information...
2 parents 944c46a + c21d5eb commit 1b330581187641e8e6d51d4f2c23fd4b63ecf1e1 @gavinhughes committed Feb 3, 2012
View
@@ -7,6 +7,8 @@
* Rack::Test now respects ports when changing hosts [Jo Liss]
* #603: Rack::Test now preserves the original referer URL when following a
redirect [Rob van Dijk]
+* Rack::Test now does not send a referer when calling `visit` multiple times
+ [Jo Liss]
### Added
View
@@ -1,6 +1,7 @@
# Capybara
[![Build Status](https://secure.travis-ci.org/jnicklas/capybara.png)](http://travis-ci.org/jnicklas/capybara)
+[![Dependency Status](https://gemnasium.com/jnicklas/capybara.png)](https://gemnasium.com/jnicklas/capybara)
Capybara helps you test Rails and Rack applications by simulating how a real
user would interact with your app. It is agnostic about the driver running your
@@ -40,17 +40,17 @@ def reload
protected
def wait_until(seconds=Capybara.default_wait_time)
- start_time = Time.now
+ retries = (seconds.to_f / 0.05).round
begin
yield
rescue => e
raise e unless driver.wait?
raise e unless (driver.respond_to?(:invalid_element_errors) and driver.invalid_element_errors.include?(e.class)) or e.is_a?(Capybara::ElementNotFound)
- raise e if (Time.now - start_time) >= seconds
+ raise e if retries.zero?
sleep(0.05)
- raise Capybara::FrozenInTime, "time appears to be frozen, Capybara does not work with libraries which freeze time, consider using time travelling instead" if Time.now == start_time
reload if Capybara.automatic_reload
+ retries -= 1
retry
end
end
@@ -18,30 +18,28 @@ def options
def visit(path, attributes = {})
reset_host!
- process(:get, path, attributes)
- follow_redirects!
+ process_and_follow_redirects(:get, path, attributes)
end
def submit(method, path, attributes)
path = request_path if not path or path.empty?
- process(method, path, attributes)
- follow_redirects!
+ process_and_follow_redirects(method, path, attributes, {'HTTP_REFERER' => current_url})
end
def follow(method, path, attributes = {})
return if path.gsub(/^#{request_path}/, '').start_with?('#')
- process(method, path, attributes)
- follow_redirects!
+ process_and_follow_redirects(method, path, attributes, {'HTTP_REFERER' => current_url})
end
- def follow_redirects!
+ def process_and_follow_redirects(method, path, attributes = {}, env = {})
+ process(method, path, attributes, env)
5.times do
- process(:get, last_response["Location"]) if last_response.redirect?
+ process(:get, last_response["Location"], {}, env) if last_response.redirect?
end
raise Capybara::InfiniteRedirectError, "redirected more than 5 times, check for infinite redirects." if last_response.redirect?
end
- def process(method, path, attributes = {})
+ def process(method, path, attributes = {}, env = {})
new_uri = URI.parse(path)
method.downcase! unless method.is_a? Symbol
@@ -60,7 +58,7 @@ def process(method, path, attributes = {})
end
reset_cache!
- send(method, path, attributes, env)
+ send(method, path, attributes, env.merge(options[:headers] || {}))
end
def current_url
@@ -107,20 +105,4 @@ def request_path
rescue Rack::Test::Error
""
end
-
- def env
- env = {}
- begin
- if last_response.redirect?
- env["HTTP_REFERER"] = last_request.env["HTTP_REFERER"]
- else
- env["HTTP_REFERER"] = last_request.url
- end
- rescue Rack::Test::Error
- # no request yet
- end
- env.merge!(options[:headers]) if options[:headers]
- env
- end
-
end
@@ -307,9 +307,6 @@
end
it "should send no referer when visiting a second page" do
- if @driver.is_a? Capybara::RackTest::Driver
- pending 'Rack::Test sends referer on subsequent visit'
- end
@driver.visit '/get_referer'
@driver.visit '/get_referer'
@driver.body.should include 'No referer'
@@ -318,12 +315,18 @@
it "should send a referer when following a link" do
@driver.visit '/referer_base'
@driver.find('//a[@href="/get_referer"]').first.click
- @driver.body.should include '/referer_base'
+ @driver.body.should match %r{http://.*/referer_base}
end
it "should preserve the original referer URL when following a redirect" do
@driver.visit('/referer_base')
@driver.find('//a[@href="/redirect_to_get_referer"]').first.click
- @driver.body.should include('/referer_base')
+ @driver.body.should match %r{http://.*/referer_base}
+ end
+
+ it "should send a referer when submitting a form" do
+ @driver.visit '/referer_base'
+ @driver.find('//input').first.click
+ @driver.body.should match %r{http://.*/referer_base}
end
end
@@ -131,15 +131,6 @@
@session.click_link('Click me')
@session.find(:css, "a#has-been-clicked").text.should include('Has been clicked')
end
-
- context "with frozen time" do
- it "raises an error suggesting that Capybara is stuck in time" do
- @session.visit('/with_js')
- now = Time.now
- Time.stub(:now).and_return(now)
- expect { @session.find('//isnotthere') }.to raise_error(Capybara::FrozenInTime)
- end
- end
end
describe '#wait_until' do
@@ -25,7 +25,9 @@ class TestApp < Sinatra::Base
end
get '/referer_base' do
- '<a href="/get_referer">direct link</a>; <a href="/redirect_to_get_referer">link via redirect</a>'
+ '<a href="/get_referer">direct link</a>' +
+ '<a href="/redirect_to_get_referer">link via redirect</a>' +
+ '<form action="/get_referer" method="get"><input type="submit"></form>'
end
get '/redirect_to_get_referer' do
View
@@ -12,6 +12,22 @@
config.default_selector = :xpath
end
end
+
+ # Workaround for http://code.google.com/p/selenium/issues/detail?id=3147:
+ # Rerun the example if we hit a transient "docElement is null" error
+ config.around(:each) do |example|
+ attempts = 0
+ begin
+ example.run
+ # example is just a Proc, @example is the current RSpec::Core::Example
+ e = @example.instance_variable_get('@exception') # usually nil
+ if (e.is_a?(Selenium::WebDriver::Error::UnknownError) &&
+ e.message == 'docElement is null' && (attempts += 1) < 5)
+ @example.instance_variable_set('@exception', nil)
+ redo
+ end
+ end until true
+ end
end
# Required here instead of in rspec_spec to avoid RSpec deprecation warning
2 xpath
Submodule xpath updated from 375ec5 to ddbf50

0 comments on commit 1b33058

Please sign in to comment.