Class: RSpec::Rails::Matchers::BaseMatcher
- Inherits:
-
Object
- Object
- RSpec::Rails::Matchers::BaseMatcher
- Includes:
- Matchers::Composable, DefaultFailureMessages
- Defined in:
- lib/rspec/rails/matchers/base_matcher.rb
Overview
@ api private
Direct Known Subclasses
BeANew, HaveHttpStatus::GenericStatus, HaveHttpStatus::NumericCode, HaveHttpStatus::SymbolicStatus
Defined Under Namespace
Modules: DefaultFailureMessages
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 Method Summary collapse
-
#description ⇒ String
private
Generates a description using Matchers::EnglishPhrasing.
-
#diffable? ⇒ Boolean
private
Matchers are not diffable by default.
- #expects_call_stack_jump? ⇒ Boolean private
-
#initialize(expected = UNDEFINED) ⇒ BaseMatcher
constructor
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 withexpect { }
), so this defaults to false.
Methods included from DefaultFailureMessages
#failure_message, #failure_message_when_negated
Constructor Details
#initialize(expected = UNDEFINED) ⇒ BaseMatcher
Returns a new instance of BaseMatcher.
19 20 21 |
# File 'lib/rspec/rails/matchers/base_matcher.rb', line 19 def initialize(expected = UNDEFINED) @expected = expected unless UNDEFINED.equal?(expected) end |
Instance Method Details
#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 Matchers::EnglishPhrasing.
51 52 53 54 55 |
# File 'lib/rspec/rails/matchers/base_matcher.rb', line 51 def description desc = RSpec::Matchers::EnglishPhrasing.split_words(self.class.matcher_name) desc << RSpec::Matchers::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.
60 61 62 |
# File 'lib/rspec/rails/matchers/base_matcher.rb', line 60 def diffable? false 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.
73 74 75 |
# File 'lib/rspec/rails/matchers/base_matcher.rb', line 73 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.
38 39 40 41 42 43 44 45 46 |
# File 'lib/rspec/rails/matchers/base_matcher.rb', line 38 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.
27 28 29 30 |
# File 'lib/rspec/rails/matchers/base_matcher.rb', line 27 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.
68 69 70 |
# File 'lib/rspec/rails/matchers/base_matcher.rb', line 68 def supports_block_expectations? false end |