Class: ArgumentSpecification::Argument
- Inherits:
-
Object
- Object
- ArgumentSpecification::Argument
- Includes:
- DSL::Matchers
- Defined in:
- lib/argspec/argument.rb
Instance Attribute Summary collapse
-
#actual ⇒ Object
readonly
Returns the value of attribute actual.
Instance Method Summary collapse
-
#and(*args, &block) ⇒ Object
Alias for should.
-
#and_not(*args, &block) ⇒ Object
Alias for should_not.
-
#initialize(actual, &block) ⇒ Argument
constructor
Create a new argument.
-
#should(matcher, &block) ⇒ Object
Ensure the argument matches.
-
#should_not(matcher, &block) ⇒ Object
Ensure the argument does not match.
Methods included from DSL::Matchers
Constructor Details
#initialize(actual, &block) ⇒ Argument
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>
20 21 22 23 24 |
# File 'lib/argspec/argument.rb', line 20 def initialize(actual, &block) @actual = actual instance_eval(&block) end |
Instance Attribute Details
#actual ⇒ Object (readonly)
Returns the value of attribute actual.
5 6 7 |
# File 'lib/argspec/argument.rb', line 5 def actual @actual end |
Instance Method Details
#and(*args, &block) ⇒ Object
Alias for should
Example:
>> and be_a(Symbol)
=> #<Argument:0x00000000000000 @actual=:test>
80 81 82 |
# File 'lib/argspec/argument.rb', line 80 def and(*args, &block) should(*args, &block) end |
#and_not(*args, &block) ⇒ Object
Alias for should_not
Example:
>> and_not be_a(Symbol)
=> #<Argument:0x00000000000000 @actual=:test>
90 91 92 |
# File 'lib/argspec/argument.rb', line 90 def and_not(*args, &block) should_not(*args, &block) end |
#should(matcher, &block) ⇒ Object
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
39 40 41 42 43 44 45 46 47 48 |
# 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. end |
#should_not(matcher, &block) ⇒ Object
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
63 64 65 66 67 68 69 70 71 72 |
# 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. end |