Class: Ward::Matchers::Predicate

Inherits:
Matcher
  • Object
show all
Defined in:
lib/ward/matchers/predicate.rb

Overview

Tests that a predicate method responds with true.

Examples:

Validating that the predicate method responds with true.


class Person
  validate do |person|
    person.is.important?
  end
end

Instance Attribute Summary

Attributes inherited from Matcher

#expected, #extra_args

Instance Method Summary collapse

Methods inherited from Matcher

#customise_error_values, error_id, #initialize

Constructor Details

This class inherits a constructor from Ward::Matchers::Matcher

Instance Method Details

#matches?(actual) ⇒ Boolean

Returns whether the given value is responds true to the predicate.

Parameters:

  • actual (Object)

    The validation value.

Returns:

  • (Boolean)

Raises:

  • (ArgumentError)


22
23
24
25
26
27
# File 'lib/ward/matchers/predicate.rb', line 22

def matches?(actual)
  raise ArgumentError, "#{actual.inspect} does not respond " \
    "to #{expected}" unless actual.respond_to?(@expected)

  actual.__send__(@expected)
end