Class: RSpec::Rails::Matchers::BaseMatcher Private
- Inherits:
-
Object
- Object
- RSpec::Rails::Matchers::BaseMatcher
- Includes:
- Matchers::Composable, DefaultFailureMessages
- Defined in:
- lib/rspec/rails/matchers/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.
Base class to build matchers. Should not be instantiated directly.
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
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 withexpect { }
), so this defaults to false.
Methods included from DefaultFailureMessages
#failure_message, #failure_message_when_negated
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/rails/matchers/base_matcher.rb', line 21 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.
53 54 55 56 57 |
# File 'lib/rspec/rails/matchers/base_matcher.rb', line 53 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.
62 63 64 |
# File 'lib/rspec/rails/matchers/base_matcher.rb', line 62 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.
75 76 77 |
# File 'lib/rspec/rails/matchers/base_matcher.rb', line 75 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.
40 41 42 43 44 45 46 47 48 |
# File 'lib/rspec/rails/matchers/base_matcher.rb', line 40 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.
29 30 31 32 |
# File 'lib/rspec/rails/matchers/base_matcher.rb', line 29 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.
70 71 72 |
# File 'lib/rspec/rails/matchers/base_matcher.rb', line 70 def supports_block_expectations? false end |