Class: RSpec::Matchers::BuiltIn::BaseMatcher Private
- Inherits:
-
Object
- Object
- RSpec::Matchers::BuiltIn::BaseMatcher
- Includes:
- MatchAliases, 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, BeFalsey, BeNil, BePredicate, BeTruthy, Cover, Eq, Eql, Equal, Exist, Include, Match, MatchArray, StartAndEndWith, YieldControl, YieldWithNoArgs
Constant Summary
- 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)
- - (Object) actual readonly private
- - (Object) expected readonly private
- - (Object) rescued_exception readonly private
Instance Method Summary (collapse)
- - (Object) description private
- - (Boolean) diffable? private
- - (Object) failure_message_for_should private
- - (Object) failure_message_for_should_not private
-
- (BaseMatcher) initialize(expected = UNDEFINED)
constructor
private
A new instance of BaseMatcher.
- - (Object) match_unless_raises(*exceptions) private
- - (Boolean) matches?(actual) private
-
- (Boolean) supports_block_expectations?
private
Most matchers are value matchers (i.e. meant to work with
expect(value)
) rather than block matchers (i.e. meant to work withexpect { }
), so this defaults to false.
Methods included from MatchAliases
Methods included from Pretty
#_pretty_print, #expected_to_sentence, #name, #name_to_sentence, #split_words, #to_sentence, #to_word, #underscore
Constructor Details
- (BaseMatcher) initialize(expected = UNDEFINED)
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.
A new instance of BaseMatcher
22 23 24 |
# File 'lib/rspec/matchers/built_in/base_matcher.rb', line 22 def initialize(expected = UNDEFINED) @expected = expected unless UNDEFINED.equal?(expected) end |
Instance Attribute Details
- (Object) actual (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.
20 21 22 |
# File 'lib/rspec/matchers/built_in/base_matcher.rb', line 20 def actual @actual end |
- (Object) expected (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.
20 21 22 |
# File 'lib/rspec/matchers/built_in/base_matcher.rb', line 20 def expected @expected end |
- (Object) rescued_exception (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.
20 21 22 |
# File 'lib/rspec/matchers/built_in/base_matcher.rb', line 20 def rescued_exception @rescued_exception end |
Instance Method Details
- (Object) description
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.
51 52 53 |
# File 'lib/rspec/matchers/built_in/base_matcher.rb', line 51 def description defined?(@expected) ? "#{name_to_sentence} #{@expected.inspect}" : name_to_sentence end |
- (Boolean) diffable?
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.
55 56 57 |
# File 'lib/rspec/matchers/built_in/base_matcher.rb', line 55 def diffable? false end |
- (Object) failure_message_for_should
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.
41 42 43 44 |
# File 'lib/rspec/matchers/built_in/base_matcher.rb', line 41 def assert_ivars :@actual "expected #{@actual.inspect} to #{name_to_sentence}#{to_sentence expected}" end |
- (Object) failure_message_for_should_not
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.
46 47 48 49 |
# File 'lib/rspec/matchers/built_in/base_matcher.rb', line 46 def assert_ivars :@actual "expected #{@actual.inspect} not to #{name_to_sentence}#{to_sentence expected}" end |
- (Object) match_unless_raises(*exceptions)
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.
31 32 33 34 35 36 37 38 39 |
# File 'lib/rspec/matchers/built_in/base_matcher.rb', line 31 def match_unless_raises(*exceptions) exceptions.unshift Exception if exceptions.empty? begin yield true rescue *exceptions => @rescued_exception false end end |
- (Boolean) matches?(actual)
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.
26 27 28 29 |
# File 'lib/rspec/matchers/built_in/base_matcher.rb', line 26 def matches?(actual) @actual = actual match(expected, actual) end |
- (Boolean) supports_block_expectations?
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.
Most matchers are value matchers (i.e. meant to work with expect(value)
)
rather than block matchers (i.e. meant to work with expect { }
), so
this defaults to false. Block matchers must override this to return true.
63 64 65 |
# File 'lib/rspec/matchers/built_in/base_matcher.rb', line 63 def supports_block_expectations? false end |