Module: RSpec::Wait

Defined in:
lib/rspec/wait.rb,
lib/rspec/wait/proxy.rb,
lib/rspec/wait/target.rb,
lib/rspec/wait/handler.rb,
lib/rspec/wait/version.rb

Overview

The RSpec::Wait module is included into RSpec’s example environment, making the wait_for, wait, and with_wait methods available inside each spec.

Defined Under Namespace

Modules: Handler Classes: NegativeHandler, PositiveHandler, Proxy, Target

Constant Summary collapse

DEFAULT_TIMEOUT =
10.0
DEFAULT_DELAY =
0.1
DEFAULT_CLONE_MATCHER =
false
VERSION =
::Gem::Version.new("1.0.1")

Class Method Summary collapse

Class Method Details

.wait(arg = nil, timeout: arg, delay: nil, clone_matcher: nil) ⇒ Object



28
29
30
# File 'lib/rspec/wait.rb', line 28

def wait(arg = nil, timeout: arg, delay: nil, clone_matcher: nil)
  Proxy.new(timeout: timeout, delay: delay, clone_matcher: clone_matcher)
end

.wait_for(*args, &block) ⇒ Object

Raises:

  • (ArgumentError)


21
22
23
24
25
26
# File 'lib/rspec/wait.rb', line 21

def wait_for(*args, &block)
  raise ArgumentError, "The `wait_for` method only accepts a block." if args.any?
  raise ArgumentError, "The `wait_for` method requires a block." unless block

  Target.new(block)
end

.with_wait(timeout: nil, delay: nil, clone_matcher: nil) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/rspec/wait.rb', line 32

def with_wait(timeout: nil, delay: nil, clone_matcher: nil)
  original_timeout = RSpec.configuration.wait_timeout
  original_delay = RSpec.configuration.wait_delay
  original_clone_matcher = RSpec.configuration.clone_wait_matcher

  RSpec.configuration.wait_timeout = timeout unless timeout.nil?
  RSpec.configuration.wait_delay = delay unless delay.nil?
  RSpec.configuration.clone_wait_matcher = clone_matcher unless clone_matcher.nil?

  yield
ensure
  RSpec.configuration.wait_timeout = original_timeout
  RSpec.configuration.wait_delay = original_delay
  RSpec.configuration.clone_wait_matcher = original_clone_matcher
end