Class: ArgumentSpecification::Matchers::Satisfy
- Inherits:
-
BaseMatcher
- Object
- BaseMatcher
- ArgumentSpecification::Matchers::Satisfy
- Defined in:
- lib/argspec/matchers/satisfy.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
Attributes inherited from BaseMatcher
Instance Method Summary collapse
-
#failure_message ⇒ Object
The failure message when using ‘should’.
-
#failure_message_when_negated ⇒ Object
The failure message when using ‘should not’.
-
#initialize(description) ⇒ Satisfy
constructor
Create a new matcher instance.
-
#matches? ⇒ Boolean
Check if the actual object matches.
Methods inherited from BaseMatcher
Constructor Details
#initialize(description) ⇒ Satisfy
Create a new matcher instance
Arguments:
description: (String)
Example:
>> ArgumentSpecification::Matchers::Satisfy.new('always pass')
=> #<ArgumentSpecification::Matchers::Satisfy:0x00000000000000 @block=#<Proc:0x00000000000000>>
17 18 19 |
# File 'lib/argspec/matchers/satisfy.rb', line 17 def initialize(description) @description = description end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
6 7 8 |
# File 'lib/argspec/matchers/satisfy.rb', line 6 def description @description end |
Instance Method Details
#failure_message ⇒ Object
The failure message when using ‘should’
Example:
>> matcher.failure_message
=> "'test' should always pass"
27 28 29 30 31 32 33 34 35 |
# File 'lib/argspec/matchers/satisfy.rb', line 27 def actual = prettify_args(@actual) if @description "'#{actual}' should #{@description}" else "'#{actual}' should satisfy the requirements" end end |
#failure_message_when_negated ⇒ Object
The failure message when using ‘should not’
Example:
>> matcher.failure_message_when_negated
=> "':test' should not always pass"
43 44 45 46 47 48 49 50 51 |
# File 'lib/argspec/matchers/satisfy.rb', line 43 def actual = prettify_args(@actual) if @description "'#{actual}' should not #{@description}" else "'#{actual}' should not satisfy the requirements" end end |
#matches? ⇒ Boolean
Check if the actual object matches
Example:
>> matcher.matches?
=> true
59 60 61 62 63 |
# File 'lib/argspec/matchers/satisfy.rb', line 59 def matches? return @block.call(@actual) if @block false end |