Sha256: 9963503fe93662fa13e4f452f8f49313f26dfe749a58090135a19d527ada8c6e

Contents?: true

Size: 1.22 KB

Versions: 73

Compression:

Stored size: 1.22 KB

Contents

require "rspec"
require "rspec/wait/error"
require "rspec/wait/handler"
require "rspec/wait/proxy"
require "rspec/wait/target"

module RSpec
  module Wait
    module_function

    # From: https://github.com/rspec/rspec-expectations/blob/v3.0.0/lib/rspec/expectations/syntax.rb#L72-L74
    def wait_for(value = Target::UndefinedValue, &block)
      Target.for(value, block)
    end

    def wait(timeout = nil, options = {})
      options[:timeout] = timeout
      Proxy.new(options)
    end

    def with_wait(options)
      original_timeout = RSpec.configuration.wait_timeout
      original_delay = RSpec.configuration.wait_delay

      RSpec.configuration.wait_timeout = options[:timeout] if options[:timeout]
      RSpec.configuration.wait_delay = options[:delay] if options[:delay]

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

RSpec.configure do |config|
  config.include(RSpec::Wait)

  config.add_setting(:wait_timeout, default: 10)
  config.add_setting(:wait_delay, default: 0.1)

  config.around do |example|
    if options = example.metadata[:wait]
      with_wait(options) { example.run }
    else
      example.run
    end
  end
end

Version data entries

73 entries across 68 versions & 18 rubygems

Version Path
rspec-wait-0.0.9 lib/rspec/wait.rb
able-neo4j-1.0.0 vendor/bundle/jruby/1.9/gems/rspec-wait-0.0.7/lib/rspec/wait.rb
logstash-input-beats-2.0.2 vendor/jruby/1.9/gems/logstash-codec-json-2.0.3/vendor/gems/rspec-wait-0.0.7/lib/rspec/wait.rb
logstash-input-beats-2.0.2 vendor/jruby/1.9/gems/rspec-wait-0.0.7/lib/rspec/wait.rb
logstash-input-beats-2.0.2 vendor/jruby/1.9/gems/rspec-wait-0.0.8/lib/rspec/wait.rb
rspec-wait-0.0.8 lib/rspec/wait.rb
logstash-codec-json-2.0.3 vendor/gems/rspec-wait-0.0.7/lib/rspec/wait.rb
logstash-input-beats-0.9.2 vendor/jruby/1.9/gems/rspec-wait-0.0.7/lib/rspec/wait.rb
logstash-input-beats-0.9.1 vendor/jruby/1.9/gems/rspec-wait-0.0.7/lib/rspec/wait.rb
rspec-wait-0.0.7 lib/rspec/wait.rb
rspec-wait-0.0.6 lib/rspec/wait.rb
rspec-wait-0.0.5 lib/rspec/wait.rb
rspec-wait-0.0.4 lib/rspec/wait.rb