class Stannum::Constraints::Equality
An Equality
constraint uses ==
to compare the actual and expected objects.
@example Using an Equality
constraint
string = 'Greetings, programs!' constraint = Stannum::Constraints::Equality.new(string) constraint.matches?(nil) #=> false constraint.matches?('something') #=> false constraint.matches?('a string') #=> true constraint.matches?(string.dup) #=> true constraint.matches?(string) #=> true
Constants
- NEGATED_TYPE
The :type of the error generated for a matching object.
- TYPE
The :type of the error generated for a non-matching object.
Attributes
expected_value[R]
@return [Object] the expected object.
Public Class Methods
new(expected_value, **options)
click to toggle source
@param expected_value
[Object] The expected object. @param options [Hash<Symbol, Object>] Configuration options for the
constraint. Defaults to an empty Hash.
Calls superclass method
Stannum::Constraints::Base::new
# File lib/stannum/constraints/equality.rb, line 27 def initialize(expected_value, **options) @expected_value = expected_value super(expected_value: expected_value, **options) end
Public Instance Methods
matches?(actual)
click to toggle source
Checks that the object is the expected value.
@return [true, false] true if the object is the expected value, otherwise
false.
@see Stannum::Constraint#matches?
# File lib/stannum/constraints/equality.rb, line 42 def matches?(actual) expected_value == actual end
Also aliased as: match?