Module: RSpec::Matchers

Defined in:
lib/rspec/change_to_now/detect.rb,
lib/rspec/change_to_now/negate.rb,
lib/rspec/change_to_now.rb

Defined Under Namespace

Classes: Detect, Negate

Instance Method Summary collapse

Instance Method Details

#detect(*expected, &block) ⇒ Object

If given a block, passes if the block returns a truthy value for any of the actual items or for the key-value pair is the actual item list is a hash. Without a block, it behaves identically to include. expected must be empty if a block is provided.

Examples:

expect([2]).to detect(&:even?)
expect({a: 2}).to detect { |k,v| v.even? }
expect([1]).to detect 1


84
85
86
87
88
# File 'lib/rspec/change_to_now/detect.rb', line 84

def detect(*expected, &block)
  AliasedMatcher.new(Detect.new(*expected, &block), lambda do |old_desc|
    old_desc.gsub(Pretty.split_words('include'), Pretty.split_words('detect'))
  end)
end

#negate(matcher) ⇒ Object

Passes if provided matcher fails and vice-versa.

Examples:

expect([1]).to negate(eq(2))
expect([1]).not_to negate(eq(1))


67
68
69
# File 'lib/rspec/change_to_now/negate.rb', line 67

def negate(matcher)
  Negate.new(matcher)
end