@api private
Used internally as a base class for matchers that ship with rspec-expectations.
### Warning:
This class is for internal use, and subject to change without notice. We strongly recommend that you do not base your custom matchers on this class. If/when this changes, we will announce it and remove this warning.
# File lib/rspec/matchers/built_in/base_matcher.rb, line 19 def initialize(expected = nil) @expected = expected end
# File lib/rspec/matchers/built_in/base_matcher.rb, line 56 def ==(other) matches?(other) end
# File lib/rspec/matchers/built_in/base_matcher.rb, line 48 def description expected ? "#{name_to_sentence} #{@expected.inspect}" : name_to_sentence end
# File lib/rspec/matchers/built_in/base_matcher.rb, line 52 def diffable? false end
# File lib/rspec/matchers/built_in/base_matcher.rb, line 38 def failure_message_for_should assert_ivars :@actual, :@expected "expected #{@actual.inspect} to #{name_to_sentence}#{expected_to_sentence}" end
# File lib/rspec/matchers/built_in/base_matcher.rb, line 43 def failure_message_for_should_not assert_ivars :@actual, :@expected "expected #{@actual.inspect} not to #{name_to_sentence}#{expected_to_sentence}" end
# File lib/rspec/matchers/built_in/base_matcher.rb, line 28 def match_unless_raises(*exceptions) exceptions.unshift Exception if exceptions.empty? begin yield true rescue *exceptions => @rescued_exception false end end
# File lib/rspec/matchers/built_in/base_matcher.rb, line 23 def matches?(actual) @actual = actual match(expected, actual) end
# File lib/rspec/matchers/built_in/base_matcher.rb, line 62 def assert_ivars *ivars raise "#{self.class.name} needs to supply #{to_sentence ivars}" unless ivars.all? { |v| instance_variables.map(&:intern).include? v } end