Class: Ward::Matchers::Acceptance

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

Overview

Tests whether the validation value is accepted.

An “accepted” value one which is exactly true, “t”, “true”, “1”, “y”, or “yes”.

Examples:


class Person
  validate do |person|
    person.name.is.accepted
  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

Constructor Details

#initialize(expected = nil, *extra_args) ⇒ Acceptance

Creates a new matcher instance.

Parameters:

  • expected (Object) (defaults to: nil)

    The expected value for the matcher.



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

def initialize(expected = nil, *extra_args)
  expected = Array(expected || %w( t true y yes 1 ) + [1])
  @include_matcher = Include.new(expected)

  super(expected, *extra_args)
end

Instance Method Details

#matches?(actual) ⇒ Boolean

Returns whether the given value is accepted.

Parameters:

  • actual (Object)

    The validation value.

Returns:

  • (Boolean)


37
38
39
# File 'lib/ward/matchers/acceptance.rb', line 37

def matches?(actual)
  actual == true or @include_matcher.matches?(actual)
end