Class: ArgumentSpecification::Matchers::Satisfy

Inherits:
BaseMatcher
  • Object
show all
Defined in:
lib/argspec/matchers/satisfy.rb

Instance Attribute Summary collapse

Attributes inherited from BaseMatcher

#actual, #block, #metadata

Instance Method Summary collapse

Methods inherited from BaseMatcher

matcher_name

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

#descriptionObject (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_messageObject

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 failure_message
  actual = prettify_args(@actual)

  if @description
    "'#{actual}' should #{@description}"
  else
    "'#{actual}' should satisfy the requirements"
  end
end

#failure_message_when_negatedObject

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 failure_message_when_negated
  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

Returns:

  • (Boolean)


59
60
61
62
63
# File 'lib/argspec/matchers/satisfy.rb', line 59

def matches?
  return @block.call(@actual) if @block

  false
end