Class: Caricature::Verification
- Defined in:
- lib/caricature/verification.rb,
lib/caricature/bacon/integration.rb
Overview
Describes a verification of a method call. This corresponds kind of to an assertion
Instance Method Summary collapse
-
#allow_any_arguments ⇒ Object
allow any arguments ignore the argument constraint.
-
#any_args? ⇒ Boolean
indicates whether this verification can be for any arguments.
- #error ⇒ Object
- #init_plugin ⇒ Object
-
#initialize(method_name, recorder, mode = :instance) ⇒ Verification
constructor
Initializes a new instance of a
Verification
. -
#matches?(method_name, *args) ⇒ Boolean
figure out if this argument variation matches the provided args.
-
#successful? ⇒ Boolean
indicate that this method verification is successful.
-
#with(*args) ⇒ Object
constrain this verification to the provided arguments.
- #with_block_args(*args) ⇒ Object
Constructor Details
#initialize(method_name, recorder, mode = :instance) ⇒ Verification
Initializes a new instance of a Verification
8 9 10 11 |
# File 'lib/caricature/verification.rb', line 8 def initialize(method_name, recorder, mode=:instance) @method_name, @args, @any_args, @recorder, @mode, @block_args = method_name, [], true, recorder, mode, nil init_plugin end |
Instance Method Details
#allow_any_arguments ⇒ Object
allow any arguments ignore the argument constraint
35 36 37 38 |
# File 'lib/caricature/verification.rb', line 35 def allow_any_arguments @any_args = true self end |
#any_args? ⇒ Boolean
indicates whether this verification can be for any arguments
18 19 20 |
# File 'lib/caricature/verification.rb', line 18 def any_args? @any_args end |
#error ⇒ Object
45 46 47 |
# File 'lib/caricature/verification.rb', line 45 def error @recorder.error end |
#init_plugin ⇒ Object
13 14 15 |
# File 'lib/caricature/verification.rb', line 13 def init_plugin end |
#matches?(method_name, *args) ⇒ Boolean
figure out if this argument variation matches the provided args.
41 42 43 |
# File 'lib/caricature/verification.rb', line 41 def matches?(method_name, *args) @method_name == method_name and any_args? or @args == args end |
#successful? ⇒ Boolean
indicate that this method verification is successful
50 51 52 53 54 55 56 57 |
# File 'lib/caricature/verification.rb', line 50 def successful? a = any_args? ? [:any] : @args begin @recorder.was_called?(@method_name, @block_args, @mode, *a) rescue ArgumentError false end end |
#with(*args) ⇒ Object
constrain this verification to the provided arguments
23 24 25 26 27 28 |
# File 'lib/caricature/verification.rb', line 23 def with(*args) @any_args = args.first.is_a?(Symbol) and args.first == :any @args = args # @callback = b if b self end |
#with_block_args(*args) ⇒ Object
30 31 32 |
# File 'lib/caricature/verification.rb', line 30 def with_block_args(*args) @block_args = args end |