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) ⇒ Object
Alias for should.
-
#and_not(*args) ⇒ Object
Alias for should_not.
-
#initialize(actual, &block) ⇒ Argument
constructor
Create a new argument.
-
#should(matcher) ⇒ Object
Ensure the argument matches.
-
#should_not(matcher) ⇒ 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) ⇒ Object
Alias for should
Example:
>> and be_a(Symbol)
=> #<Argument:0x00000000000000 @actual=:test>
76 77 78 |
# File 'lib/argspec/argument.rb', line 76 def and(*args) should(*args) end |
#and_not(*args) ⇒ Object
Alias for should_not
Example:
>> and_not be_a(Symbol)
=> #<Argument:0x00000000000000 @actual=:test>
86 87 88 |
# File 'lib/argspec/argument.rb', line 86 def and_not(*args) should_not(*args) end |
#should(matcher) ⇒ Object
Ensure the argument matches
Arguments:
matcher: (Matchers::BaseMatcher)
Example:
>> should be_a(Symbol)
=> #<Argument:0x00000000000000 @actual=:test>
Raises:
ArgumentError: When the argument does not match
38 39 40 41 42 43 44 45 46 |
# File 'lib/argspec/argument.rb', line 38 def should(matcher) return self unless matcher.is_a?(Matchers::BaseMatcher) matcher.send(:actual=, @actual) return self if matcher.matches? raise ArgumentError, matcher. end |
#should_not(matcher) ⇒ Object
Ensure the argument does not match
Arguments:
matcher: (Matchers::BaseMatcher)
Example:
>> should_not be_a(Symbol)
=> #<Argument:0x00000000000000 @actual=:test>
Raises:
ArgumentError: When the argument matches
60 61 62 63 64 65 66 67 68 |
# File 'lib/argspec/argument.rb', line 60 def should_not(matcher) return self unless matcher.is_a?(Matchers::BaseMatcher) matcher.send(:actual=, @actual) return self unless matcher.matches? raise ArgumentError, matcher. end |