Class: Minicrest::Equals
Overview
Matcher that checks for value equality using deep comparison.
Uses Ruby’s == operator which provides value equality semantics. For data structures (Arrays, Hashes), this performs deep comparison by value rather than by reference.
Instance Method Summary collapse
-
#description ⇒ String
Returns a description of what this matcher expects.
-
#failure_message(actual) ⇒ String
Returns the failure message when the match fails.
-
#initialize(expected) ⇒ Equals
constructor
Creates a new value equality matcher.
-
#matches?(actual) ⇒ Boolean
Checks if actual equals expected by value.
-
#negated_failure_message(actual) ⇒ String
Returns the failure message when a negated match fails.
Methods inherited from Matcher
Constructor Details
#initialize(expected) ⇒ Equals
Creates a new value equality matcher.
25 26 27 28 |
# File 'lib/minicrest/equals.rb', line 25 def initialize(expected) super() @expected = expected end |
Instance Method Details
#description ⇒ String
Returns a description of what this matcher expects.
41 42 43 |
# File 'lib/minicrest/equals.rb', line 41 def description "equal to #{@expected.inspect}" end |
#failure_message(actual) ⇒ String
Returns the failure message when the match fails.
49 50 51 52 53 54 55 56 57 |
# File 'lib/minicrest/equals.rb', line 49 def (actual) = "expected #{actual.inspect}\n " \ "to equal #{@expected.inspect}" diff = compute_diff(actual) += "\n\n#{diff}" if diff end |
#matches?(actual) ⇒ Boolean
Checks if actual equals expected by value.
34 35 36 |
# File 'lib/minicrest/equals.rb', line 34 def matches?(actual) actual == @expected end |
#negated_failure_message(actual) ⇒ String
Returns the failure message when a negated match fails.
63 64 65 66 |
# File 'lib/minicrest/equals.rb', line 63 def (actual) "expected #{actual.inspect}\n " \ "not to equal #{@expected.inspect}, but they are equal" end |