class ArgumentSpecification::Argument

Attributes

actual[R]

Public Class Methods

new(actual, &block) click to toggle source

Create a new argument

Arguments:

actual: (Object)
block: (Block)

Example:

>> test = :test
>> ArgumentSpecification::Argument.new(test) do
>>   should_not be_nil
>> end
=> #<Argument:0x00000000000000 @actual=:test>
# File lib/argspec/argument.rb, line 20
def initialize(actual, &block)
  @actual = actual

  instance_eval(&block)
end

Public Instance Methods

and(*args, &block) click to toggle source

Alias for should

Example:

>> and be_a(Symbol)
=> #<Argument:0x00000000000000 @actual=:test>
# File lib/argspec/argument.rb, line 80
def and(*args, &block)
  should(*args, &block)
end
and_not(*args, &block) click to toggle source

Alias for should_not

Example:

>> and_not be_a(Symbol)
=> #<Argument:0x00000000000000 @actual=:test>
# File lib/argspec/argument.rb, line 90
def and_not(*args, &block)
  should_not(*args, &block)
end
should(matcher, &block) click to toggle source

Ensure the argument matches

Arguments:

matcher: (Matchers::BaseMatcher)
block: (Block)

Example:

>> should be_a(Symbol)
=> #<Argument:0x00000000000000 @actual=:test>

Raises:

ArgumentError: When the argument does not match
# File lib/argspec/argument.rb, line 39
def should(matcher, &block)
  return self unless matcher.is_a?(Matchers::BaseMatcher)

  matcher.send(:actual=, @actual)
  matcher.send(:block=, block) if block_given?

  return self if matcher.matches?

  raise ArgumentError, matcher.failure_message
end
should_not(matcher, &block) click to toggle source

Ensure the argument does not match

Arguments:

matcher: (Matchers::BaseMatcher)
block: (Block)

Example:

>> should_not be_a(Symbol)
=> #<Argument:0x00000000000000 @actual=:test>

Raises:

ArgumentError: When the argument matches
# File lib/argspec/argument.rb, line 63
def should_not(matcher, &block)
  return self unless matcher.is_a?(Matchers::BaseMatcher)

  matcher.send(:actual=, @actual)
  matcher.send(:block=, block) if block_given?

  return self unless matcher.matches?

  raise ArgumentError, matcher.failure_message_when_negated
end