class RSpec::ChangeToNow::Matchers::Detect

@api private Provides the implementation for ‘detect`. Not intended to be instantiated directly.

Public Class Methods

new(*expected, &block) click to toggle source
Calls superclass method
# File lib/rspec/change_to_now/matchers/detect.rb, line 10
def initialize(*expected, &block)
  if @block = block
    block_matcher = RSpec::Matchers::BuiltIn::Satisfy.new(&block)
    expected << block_matcher
  end
  super(*expected)
end

Public Instance Methods

description() click to toggle source

@api private @return [String]

Calls superclass method
# File lib/rspec/change_to_now/matchers/detect.rb, line 54
def description
  super.gsub(/^include/, 'detect')
end
diffable?() click to toggle source

@api private @return [Boolean]

# File lib/rspec/change_to_now/matchers/detect.rb, line 48
def diffable?
  @block.nil?
end
does_not_match?(actual) click to toggle source

@api private @return [Boolean]

Calls superclass method
# File lib/rspec/change_to_now/matchers/detect.rb, line 28
def does_not_match?(actual)
  handle_arguments_for_match(actual) do |new_actual|
    super(new_actual)
  end
end
failure_message() click to toggle source

@api private @return [String]

Calls superclass method
# File lib/rspec/change_to_now/matchers/detect.rb, line 36
def failure_message
  check_arguments || super
end
failure_message_when_negated() click to toggle source

@api private @return [String]

Calls superclass method
# File lib/rspec/change_to_now/matchers/detect.rb, line 42
def failure_message_when_negated
  check_arguments || super
end
matches?(actual) click to toggle source

@api private @return [Boolean]

Calls superclass method
# File lib/rspec/change_to_now/matchers/detect.rb, line 20
def matches?(actual)
  handle_arguments_for_match(actual) do |new_actual|
    super(new_actual)
  end
end

Private Instance Methods

block_and_arguments_together_failure_message() click to toggle source
# File lib/rspec/change_to_now/matchers/detect.rb, line 60
def block_and_arguments_together_failure_message
  "detect can take arguments or a block but not both"
end
check_arguments() click to toggle source
# File lib/rspec/change_to_now/matchers/detect.rb, line 68
def check_arguments
  block_and_arguments_together_failure_message if has_both_block_and_arguments?
end
handle_arguments_for_match(actual) { |actual| ... } click to toggle source
# File lib/rspec/change_to_now/matchers/detect.rb, line 72
def handle_arguments_for_match(actual)
  raise SyntaxError, block_and_arguments_together_failure_message if has_both_block_and_arguments?
  original_actual = actual
  actual = actual.to_a if @block && actual.is_a?(Hash)
  value = yield(actual)
  @actual = original_actual
  value
end
has_both_block_and_arguments?() click to toggle source
# File lib/rspec/change_to_now/matchers/detect.rb, line 64
def has_both_block_and_arguments?
  @block && @expected.length > 1
end