Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make AePageObjects::Waiter.wait_until detect frozen time #97

Merged
merged 1 commit into from
Oct 16, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/ae_page_objects/exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,7 @@ class WindowNotFound < Error

class WaitTimeoutError < Error
end

class FrozenInTime < Error
end
end
1 change: 1 addition & 0 deletions lib/ae_page_objects/util/waiter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def self.wait_until(timeout = nil, &block)
end

sleep(0.05)
raise FrozenInTime, "Time appears to be frozen" if Time.now == start_time
end

result
Expand Down
27 changes: 21 additions & 6 deletions test/unit/waiter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,33 @@ def test_wait_until__timeout
assert_equal false, result
end

def test_wait_until__frozen_time
Capybara.stubs(:default_wait_time).returns(5)
Time.stubs(:now).returns(1)

block = mock
block.expects(:called).times(1)

raised = assert_raises FrozenInTime do
Waiter.wait_until do
block.called
end
end
assert_equal "Time appears to be frozen", raised.message
end

def test_wait_until__set_wait_time
Capybara.expects(:default_wait_time).never

block_calls = sequence('calls')
time_calls = sequence('time')

10.times {|n| Time.expects(:now).in_sequence(time_calls).returns(n)}
9.times { Capybara.expects(:using_wait_time).in_sequence(block_calls).with(0).yields.returns(false) }
9.times { |n| Time.expects(:now).in_sequence(time_calls).returns(n) }
4.times { Capybara.expects(:using_wait_time).in_sequence(block_calls).with(0).yields.returns(false) }
Capybara.expects(:using_wait_time).in_sequence(block_calls).with(0).yields.returns(true)

block = mock
block.expects(:called).times(10)
block.expects(:called).times(5)
result = Waiter.wait_until(10) do
block.called
end
Expand All @@ -62,11 +77,11 @@ def test_wait_until__set_wait_time_time_out
block_calls = sequence('calls')
time_calls = sequence('time')

11.times { |n| Time.expects(:now).in_sequence(time_calls).returns(n) }
10.times { Capybara.expects(:using_wait_time).in_sequence(block_calls).with(0).yields.returns(false) }
12.times { |n| Time.expects(:now).in_sequence(time_calls).returns(n) }
6.times { Capybara.expects(:using_wait_time).in_sequence(block_calls).with(0).yields.returns(false) }

block = mock
block.expects(:called).times(10)
block.expects(:called).times(6)
result = Waiter.wait_until(10) do
block.called
end
Expand Down