class RSpec::Matchers::BuiltIn::Match
@api private Provides the implementation for ‘match`. Not intended to be instantiated directly.
Public Class Methods
new(expected)
click to toggle source
Calls superclass method
RSpec::Matchers::BuiltIn::BaseMatcher::new
# File lib/rspec/matchers/built_in/match.rb, line 8 def initialize(expected) super(expected) @expected_captures = nil end
Public Instance Methods
description()
click to toggle source
@api private @return [String]
# File lib/rspec/matchers/built_in/match.rb, line 15 def description if @expected_captures && @expected.match(actual) "match #{surface_descriptions_in(expected).inspect} with captures #{surface_descriptions_in(@expected_captures).inspect}" else "match #{surface_descriptions_in(expected).inspect}" end end
diffable?()
click to toggle source
@api private @return [Boolean]
# File lib/rspec/matchers/built_in/match.rb, line 25 def diffable? true end
with_captures(*captures)
click to toggle source
Used to specify the captures we match against @return [self]
# File lib/rspec/matchers/built_in/match.rb, line 31 def with_captures(*captures) @expected_captures = captures self end
Private Instance Methods
can_safely_call_match?(expected, actual)
click to toggle source
# File lib/rspec/matchers/built_in/match.rb, line 45 def can_safely_call_match?(expected, actual) return false unless actual.respond_to?(:match) !(RSpec::Matchers.is_a_matcher?(expected) && (String === actual || Regexp === actual)) end
match(expected, actual)
click to toggle source
# File lib/rspec/matchers/built_in/match.rb, line 38 def match(expected, actual) return match_captures(expected, actual) if @expected_captures return true if values_match?(expected, actual) return false unless can_safely_call_match?(expected, actual) actual.match(expected) end
match_captures(expected, actual)
click to toggle source
# File lib/rspec/matchers/built_in/match.rb, line 52 def match_captures(expected, actual) match = actual.match(expected) if match match = ReliableMatchData.new(match) if match.names.empty? values_match?(@expected_captures, match.captures) else expected_matcher = @expected_captures.last values_match?(expected_matcher, Hash[match.names.zip(match.captures)]) || values_match?(expected_matcher, Hash[match.names.map(&:to_sym).zip(match.captures)]) || values_match?(@expected_captures, match.captures) end else false end end