Class: ArgumentSpecification::Argument
- Inherits:
-
Object
- Object
- ArgumentSpecification::Argument
- Defined in:
- lib/argspec/argument.rb
Instance Attribute Summary collapse
-
#actual ⇒ Object
readonly
Returns the value of attribute actual.
Instance Method Summary collapse
-
#initialize(actual) ⇒ Argument
constructor
Create a new argument.
-
#should(matcher) ⇒ Object
Ensure the argument matches.
-
#should_not(matcher) ⇒ Object
Ensure the argument does not match.
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
#actual ⇒ Object (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
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. 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
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. end |