Class: ArgumentSpecification::Matchers::BaseMatcher

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#actualObject

Returns the value of attribute actual.



25
26
27
# File 'lib/argspec/matchers/base_matcher.rb', line 25

def actual
  @actual
end

#blockObject

Returns the value of attribute block.



25
26
27
# File 'lib/argspec/matchers/base_matcher.rb', line 25

def block
  @block
end

#metadataObject (readonly)

Returns the value of attribute metadata.



25
26
27
# File 'lib/argspec/matchers/base_matcher.rb', line 25

def 
  
end

Class Method Details

.matcher_name(*names) ⇒ Object

Add matcher names

Arguments:

names: (Splat)

Example:

>> class TestMatcher < BaseMatcher
>>   matcher_name :test_matcher
>> end
=> TestMatcher


16
17
18
19
20
21
22
# File 'lib/argspec/matchers/base_matcher.rb', line 16

def matcher_name(*names)
  names.each do |name|
    next unless name.is_a?(Symbol)

    DSL::Matchers.register(self, name)
  end
end

Instance Method Details

#failure_messageObject

The failure message when using ‘should’

Example:

>> matcher.failure_message
=> "'test' should be a 'Symbol'"


33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/argspec/matchers/base_matcher.rb', line 33

def failure_message
  actual = prettify_args(@actual)
  matcher = prettify_matcher([:name])

  if [:args].count > 0
    args = prettify_args(*[:args])

    "'#{actual}' should #{matcher} '#{args}'"
  else
    "'#{actual}' should #{matcher}"
  end
end

#failure_message_when_negatedObject

The failure message when using ‘should not’

Example:

>> matcher.failure_message_when_negated
=> "':test' should not be a 'Symbol'"


52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/argspec/matchers/base_matcher.rb', line 52

def failure_message_when_negated
  actual = prettify_args(@actual)
  matcher = prettify_matcher([:name])

  if [:args].count > 0
    args = prettify_args(*[:args])

    "'#{actual}' should not #{matcher} '#{args}'"
  else
    "'#{actual}' should not #{matcher}"
  end
end

#matches?Boolean

Check if the actual object matches

You must override this method!

Example:

>> matcher.matches?
=> true

Raises:

  • (NotImplementedError)


73
74
75
# File 'lib/argspec/matchers/base_matcher.rb', line 73

def matches?
  raise NotImplementedError, 'You must override the matches? method in your matcher.'
end