mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Don't rely on Time.now for wait duration
This means that the wait time is less accurate (possibly too long), but it should make Capybara work when Time.now is stubbed somehow
This commit is contained in:
parent
83d8574c1d
commit
09761965ce
2 changed files with 3 additions and 12 deletions
|
@ -40,17 +40,17 @@ module Capybara
|
|||
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
|
||||
|
|
|
@ -131,15 +131,6 @@ shared_examples_for "session with javascript support" do
|
|||
@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
|
||||
|
|
Loading…
Reference in a new issue