Class: RSpec::Matchers::BuiltIn::BaseMatcher Private
- Inherits:
-
Object
- Object
- RSpec::Matchers::BuiltIn::BaseMatcher
- Includes:
- Pretty
- Defined in:
- lib/rspec/matchers/built_in/base_matcher.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
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.
Direct Known Subclasses
Be, BeAKindOf, BeAnInstanceOf, BeFalse, BeNil, BePredicate, BeTrue, Cover, Eq, Eql, Equal, Exist, Include, Match, MatchArray, StartAndEndWith, YieldControl, YieldWithNoArgs
Constant Summary collapse
- UNDEFINED =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Object.new.freeze
Instance Attribute Summary collapse
- #actual ⇒ Object readonly private
- #expected ⇒ Object readonly private
- #rescued_exception ⇒ Object readonly private
Instance Method Summary collapse
- #==(other) ⇒ Object private
- #description ⇒ Object private
- #diffable? ⇒ Boolean private
- #failure_message_for_should ⇒ Object private
- #failure_message_for_should_not ⇒ Object private
-
#initialize(expected = UNDEFINED) ⇒ BaseMatcher
constructor
private
A new instance of BaseMatcher.
- #match_unless_raises(*exceptions) ⇒ Object private
- #matches?(actual) ⇒ Boolean private
Methods included from Pretty
#_pretty_print, #expected_to_sentence, #name, #name_to_sentence, #split_words, #to_sentence, #to_word, #underscore
Constructor Details
#initialize(expected = UNDEFINED) ⇒ BaseMatcher
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of BaseMatcher.
21 22 23 |
# File 'lib/rspec/matchers/built_in/base_matcher.rb', line 21 def initialize(expected = UNDEFINED) @expected = expected unless UNDEFINED.equal?(expected) end |
Instance Attribute Details
#actual ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
19 20 21 |
# File 'lib/rspec/matchers/built_in/base_matcher.rb', line 19 def actual @actual end |
#expected ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
19 20 21 |
# File 'lib/rspec/matchers/built_in/base_matcher.rb', line 19 def expected @expected end |
#rescued_exception ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
19 20 21 |
# File 'lib/rspec/matchers/built_in/base_matcher.rb', line 19 def rescued_exception @rescued_exception end |
Instance Method Details
#==(other) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
58 59 60 |
# File 'lib/rspec/matchers/built_in/base_matcher.rb', line 58 def ==(other) matches?(other) end |
#description ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
50 51 52 |
# File 'lib/rspec/matchers/built_in/base_matcher.rb', line 50 def description defined?(@expected) ? "#{name_to_sentence} #{@expected.inspect}" : name_to_sentence end |
#diffable? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
54 55 56 |
# File 'lib/rspec/matchers/built_in/base_matcher.rb', line 54 def diffable? false end |
#failure_message_for_should ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
40 41 42 43 |
# File 'lib/rspec/matchers/built_in/base_matcher.rb', line 40 def assert_ivars :@actual "expected #{@actual.inspect} to #{name_to_sentence}#{expected_to_sentence}" end |
#failure_message_for_should_not ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
45 46 47 48 |
# File 'lib/rspec/matchers/built_in/base_matcher.rb', line 45 def assert_ivars :@actual "expected #{@actual.inspect} not to #{name_to_sentence}#{expected_to_sentence}" end |
#match_unless_raises(*exceptions) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
30 31 32 33 34 35 36 37 38 |
# File 'lib/rspec/matchers/built_in/base_matcher.rb', line 30 def match_unless_raises(*exceptions) exceptions.unshift Exception if exceptions.empty? begin yield true rescue *exceptions => @rescued_exception false end end |
#matches?(actual) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
25 26 27 28 |
# File 'lib/rspec/matchers/built_in/base_matcher.rb', line 25 def matches?(actual) @actual = actual match(expected, actual) end |