class Stannum::RSpec::MatchErrorsMatcher
Asserts that the expected and actual errors are equal.
Public Class Methods
new(expected)
click to toggle source
@param expected [Stannum::Errors] The expected errors.
# File lib/stannum/rspec/match_errors_matcher.rb, line 19 def initialize(expected) @expected = expected.to_a end
Public Instance Methods
description()
click to toggle source
@return [String] a short description of the matcher and expected
properties.
# File lib/stannum/rspec/match_errors_matcher.rb, line 25 def description 'match the expected errors' end
does_not_match?(actual)
click to toggle source
Checks that the given errors do not match the expected errors.
# 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()
click to toggle source
@return [String] a summary message describing a failed expectation.
# File lib/stannum/rspec/match_errors_matcher.rb, line 41 def failure_message unless errors? return 'expected the errors to match the expected errors, but the' \ ' object is not an array or Errors object' end equality_matcher.failure_message end
failure_message_when_negated()
click to toggle source
@return [String] a summary message describing a failed negated
expectation.
# File lib/stannum/rspec/match_errors_matcher.rb, line 52 def failure_message_when_negated 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.failure_message_when_negated end
matches?(actual)
click to toggle source
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.
@param actual [Object] The actual object to match.
@return [Boolean] true if the actual errors match the expected errors.
# 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
Private Instance Methods
equality_matcher()
click to toggle source
# File lib/stannum/rspec/match_errors_matcher.rb, line 78 def equality_matcher @equality_matcher ||= RSpec::SleepingKingStudios::Matchers::Core::DeepMatcher .new(@expected) rescue NameError # :nocov: @equality_matcher ||= RSpec::Matchers::BuiltIn::Eq.new(@expected_errors.to_a) # :nocov: end
errors?()
click to toggle source
# File lib/stannum/rspec/match_errors_matcher.rb, line 89 def errors? @actual.is_a?(Stannum::Errors) || @actual.is_a?(Array) end