Module: TestHelpers::Wait
- Extended by:
- Gem::Deprecate
- Defined in:
- lib/test-helpers/wait/wait.rb
Defined Under Namespace
Classes: Configuration
Class Method Summary collapse
- .configuration ⇒ Object
- .configure {|default_configuration| ... } ⇒ Object
- .default_configuration ⇒ Object
Instance Method Summary collapse
Class Method Details
.configuration ⇒ Object
3 4 5 |
# File 'lib/test-helpers/wait/wait.rb', line 3 def self.configuration default_configuration end |
.configure {|default_configuration| ... } ⇒ Object
11 12 13 |
# File 'lib/test-helpers/wait/wait.rb', line 11 def self.configure yield(default_configuration) if block_given? end |
.default_configuration ⇒ Object
7 8 9 |
# File 'lib/test-helpers/wait/wait.rb', line 7 def self.default_configuration @configuration ||= Configuration.new end |
Instance Method Details
#poll_and_assert(options = {}) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/test-helpers/wait/wait.rb', line 30 def poll_and_assert( = {}) return unless block_given? timeout = Float([:timeout] || TestHelpers::Wait.default_configuration.wait_timeout) interval = Float([:interval] || TestHelpers::Wait.default_configuration.wait_interval) end_time = ::Time.now + timeout failure = nil until ::Time.now > end_time begin result = yield return result if result rescue ::RSpec::Expectations::ExpectationNotMetError => e failure = e sleep interval end end raise failure end |
#wait_until(options = {}) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/test-helpers/wait/wait.rb', line 48 def wait_until( = {}) return unless block_given? timeout = Float([:timeout] || TestHelpers::Wait.default_configuration.wait_timeout) interval = Float([:interval] || TestHelpers::Wait.default_configuration.wait_interval) = [:error_message] || TestHelpers::Wait.default_configuration. end_time = ::Time.now + timeout until ::Time.now > end_time begin result = yield return result if result sleep interval rescue ::StandardError sleep interval end end result = yield return result if result raise Timeout::Error.new() end |