Class: Stannum::RSpec::MatchErrorsMatcher
- Inherits:
-
Object
- Object
- Stannum::RSpec::MatchErrorsMatcher
- Defined in:
- lib/stannum/rspec/match_errors_matcher.rb
Overview
Asserts that the expected and actual errors are equal.
Instance Method Summary collapse
-
#description ⇒ String
A short description of the matcher and expected properties.
-
#does_not_match?(actual) ⇒ Boolean
Checks that the given errors do not match the expected errors.
-
#failure_message ⇒ String
A summary message describing a failed expectation.
-
#failure_message_when_negated ⇒ String
A summary message describing a failed negated expectation.
-
#initialize(expected) ⇒ MatchErrorsMatcher
constructor
A new instance of MatchErrorsMatcher.
-
#matches?(actual) ⇒ Boolean
Checks that the given errors match the expected errors.
Constructor Details
#initialize(expected) ⇒ MatchErrorsMatcher
Returns a new instance of MatchErrorsMatcher.
19 20 21 |
# File 'lib/stannum/rspec/match_errors_matcher.rb', line 19 def initialize(expected) @expected = expected.to_a end |
Instance Method Details
#description ⇒ String
Returns a short description of the matcher and expected properties.
25 26 27 |
# File 'lib/stannum/rspec/match_errors_matcher.rb', line 25 def description 'match the expected errors' end |
#does_not_match?(actual) ⇒ Boolean
Checks that the given errors do not match the expected errors.
30 31 32 33 34 35 36 37 38 |
# File 'lib/stannum/rspec/match_errors_matcher.rb', line 30 def does_not_match?(actual) @actual = actual.is_a?(Stannum::Errors) ? actual.to_a : actual errors? && equality_matcher.does_not_match?(@actual) rescue NoMethodError # :nocov: errors? && !equality_matcher.matches?(@actual) # :nocov: end |
#failure_message ⇒ String
Returns a summary message describing a failed expectation.
41 42 43 44 45 46 47 48 |
# File 'lib/stannum/rspec/match_errors_matcher.rb', line 41 def unless errors? return 'expected the errors to match the expected errors, but the ' \ 'object is not an array or Errors object' end equality_matcher. end |
#failure_message_when_negated ⇒ String
Returns a summary message describing a failed negated expectation.
52 53 54 55 56 57 58 59 |
# File 'lib/stannum/rspec/match_errors_matcher.rb', line 52 def unless errors? return 'expected the errors not to match the expected errors, but ' \ 'the object is not an array or Errors object' end equality_matcher. end |
#matches?(actual) ⇒ Boolean
Checks that the given errors match the expected errors.
Returns false if the object is not a Stannum::Errors instance or an Array. Otherwise, it converts the expected and actual errors to arrays and performs a deep match.
70 71 72 73 74 |
# File 'lib/stannum/rspec/match_errors_matcher.rb', line 70 def matches?(actual) @actual = actual.is_a?(Stannum::Errors) ? actual.to_a : actual errors? && equality_matcher.matches?(@actual) end |