Class: ArgumentSpecification::Argument

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(actual) ⇒ Argument

Create a new argument

Arguments:

actual: (Object)

Example:

>> test = :test
>> ArgumentSpecification::Argument.new(test)
=> #<Argument:0x00000000000000 @actual=:test>


15
16
17
# File 'lib/argspec/argument.rb', line 15

def initialize(actual)
  @actual = actual
end

Instance Attribute Details

#actualObject (readonly)

Returns the value of attribute actual.



3
4
5
# File 'lib/argspec/argument.rb', line 3

def actual
  @actual
end

Instance Method Details

#should(matcher) ⇒ Object

Ensure the argument matches

Arguments:

matcher: (Matchers::BaseMatcher)

Example:

>> argument.should be_a(Symbol)
=> nil

Raises:

ArgumentError: When the argument does not match

Raises:

  • (ArgumentError)


31
32
33
34
35
36
37
38
39
# File 'lib/argspec/argument.rb', line 31

def should(matcher)
  return nil unless matcher.is_a?(Matchers::BaseMatcher)

  matcher.send(:actual=, @actual)

  return nil if matcher.matches?

  raise ArgumentError, matcher.failure_message
end

#should_not(matcher) ⇒ Object

Ensure the argument does not match

Arguments:

matcher: (Matchers::BaseMatcher)

Example:

>> argument.should_not be_a(Symbol)
=> nil

Raises:

ArgumentError: When the argument matches

Raises:

  • (ArgumentError)


53
54
55
56
57
58
59
60
61
# File 'lib/argspec/argument.rb', line 53

def should_not(matcher)
  return nil unless matcher.is_a?(Matchers::BaseMatcher)

  matcher.send(:actual=, @actual)

  return nil unless matcher.matches?

  raise ArgumentError, matcher.failure_message_when_negated
end