Class: RSpec::Matchers::BuiltIn::BaseMatcher Private
- Includes:
- DefaultFailureMessages, HashFormatting, Composable
- Defined in:
- lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/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 and rspec-rails.
### 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
All, Be, BeAKindOf, BeAnInstanceOf, BeBetween, BeComparedTo, BeFalsey, BeNil, BeTruthy, BeWithin, Change, ChangeRelatively, Compound, ContainExactly, Cover, DynamicPredicate, Eq, Eql, Equal, Exist, HaveAttributes, Include, Match, Output, RespondTo, Satisfy, SpecificValuesChange, StartOrEndWith, YieldControl, YieldSuccessiveArgs, YieldWithArgs, YieldWithNoArgs
Defined Under Namespace
Modules: DefaultFailureMessages, HashFormatting
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.
Used to detect when no arg is passed to ‘initialize`. `nil` cannot be used because it’s a valid value to pass.
Object.new.freeze
Instance Attribute Summary collapse
- #actual ⇒ Object readonly private
- #expected ⇒ Object readonly private
- #matcher_name ⇒ Object private
- #rescued_exception ⇒ Object readonly private
Class Method Summary collapse
- .matcher_name ⇒ Object private
Instance Method Summary collapse
- #actual_formatted ⇒ Object private
-
#description ⇒ String
private
Generates a description using EnglishPhrasing.
-
#diffable? ⇒ Boolean
private
Matchers are not diffable by default.
- #expected_formatted ⇒ Object private
- #expects_call_stack_jump? ⇒ Boolean private
-
#initialize(expected = UNDEFINED) ⇒ BaseMatcher
constructor
private
A new instance of BaseMatcher.
-
#match_unless_raises(*exceptions) ⇒ Object
private
Used to wrap a block of code that will indicate failure by raising one of the named exceptions.
-
#matches?(actual) ⇒ Boolean
private
Indicates if the match is successful.
-
#supports_block_expectations? ⇒ Boolean
private
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.
- #supports_value_expectations? ⇒ Boolean private
Methods included from DefaultFailureMessages
#failure_message, #failure_message_when_negated, has_default_failure_messages?
Methods included from HashFormatting
Methods included from Composable
#===, #and, #description_of, #or, should_enumerate?, surface_descriptions_in, unreadable_io?, #values_match?
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.
28 29 30 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/matchers/built_in/base_matcher.rb', line 28 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.
23 24 25 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/matchers/built_in/base_matcher.rb', line 23 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.
23 24 25 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/matchers/built_in/base_matcher.rb', line 23 def expected @expected end |
#matcher_name ⇒ 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.
107 108 109 110 111 112 113 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/matchers/built_in/base_matcher.rb', line 107 def matcher_name if defined?(@matcher_name) @matcher_name else self.class.matcher_name end 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.
23 24 25 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/matchers/built_in/base_matcher.rb', line 23 def rescued_exception @rescued_exception end |
Class Method Details
.matcher_name ⇒ 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.
102 103 104 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/matchers/built_in/base_matcher.rb', line 102 def self.matcher_name @matcher_name ||= underscore(name.split('::').last) end |
Instance Method Details
#actual_formatted ⇒ 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.
97 98 99 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/matchers/built_in/base_matcher.rb', line 97 def actual_formatted RSpec::Support::ObjectFormatter.format(@actual) end |
#description ⇒ String
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.
Generates a description using EnglishPhrasing.
60 61 62 63 64 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/matchers/built_in/base_matcher.rb', line 60 def description desc = EnglishPhrasing.split_words(self.class.matcher_name) desc << EnglishPhrasing.list(@expected) if defined?(@expected) desc 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.
Matchers are not diffable by default. Override this to make your subclass diffable.
69 70 71 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/matchers/built_in/base_matcher.rb', line 69 def diffable? false end |
#expected_formatted ⇒ 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.
92 93 94 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/matchers/built_in/base_matcher.rb', line 92 def expected_formatted RSpec::Support::ObjectFormatter.format(@expected) end |
#expects_call_stack_jump? ⇒ 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.
87 88 89 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/matchers/built_in/base_matcher.rb', line 87 def expects_call_stack_jump? false 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.
Used to wrap a block of code that will indicate failure by raising one of the named exceptions.
This is used by rspec-rails for some of its matchers that wrap rails’ assertions.
47 48 49 50 51 52 53 54 55 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/matchers/built_in/base_matcher.rb', line 47 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.
Indicates if the match is successful. Delegates to ‘match`, which should be defined on a subclass. Takes care of consistently initializing the `actual` attribute.
36 37 38 39 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/matchers/built_in/base_matcher.rb', line 36 def matches?(actual) @actual = actual match(expected, actual) end |
#supports_block_expectations? ⇒ 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.
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.
77 78 79 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/matchers/built_in/base_matcher.rb', line 77 def supports_block_expectations? false end |
#supports_value_expectations? ⇒ 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.
82 83 84 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-expectations-3.12.2/lib/rspec/matchers/built_in/base_matcher.rb', line 82 def supports_value_expectations? true end |