Class: Caricature::EventVerification
- Defined in:
- lib/caricature/clr/event_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(event_name, recorder, mode = :instance) ⇒ EventVerification
constructor
Initializes a new instance of a
Verification. -
#matches?(event_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.
Constructor Details
#initialize(event_name, recorder, mode = :instance) ⇒ EventVerification
Initializes a new instance of a Verification
8 9 10 11 |
# File 'lib/caricature/clr/event_verification.rb', line 8 def initialize(event_name, recorder, mode=:instance) @event_name, @args, @any_args, @recorder, @mode = event_name, [], true, recorder, mode init_plugin end |
Instance Method Details
#allow_any_arguments ⇒ Object
allow any arguments ignore the argument constraint
31 32 33 34 |
# File 'lib/caricature/clr/event_verification.rb', line 31 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/clr/event_verification.rb', line 18 def any_args? @any_args end |
#error ⇒ Object
41 42 43 |
# File 'lib/caricature/clr/event_verification.rb', line 41 def error @recorder.event_error end |
#init_plugin ⇒ Object
13 14 15 |
# File 'lib/caricature/clr/event_verification.rb', line 13 def init_plugin end |
#matches?(event_name, *args) ⇒ Boolean
figure out if this argument variation matches the provided args.
37 38 39 |
# File 'lib/caricature/clr/event_verification.rb', line 37 def matches?(event_name, *args) @event_name == event_name and (any_args? or @args == args) end |
#successful? ⇒ Boolean
indicate that this method verification is successful
56 57 58 59 60 61 |
# File 'lib/caricature/bacon/integration.rb', line 56 def successful? a = any_args? ? [:any] : @args res = @recorder.event_raised?(@event_name, @mode, *a) raise Caricature::ArgumentMatchError.new(:failed, self.error) unless res res end |
#with(*args) ⇒ Object
constrain this verification to the provided arguments
23 24 25 26 27 28 |
# File 'lib/caricature/clr/event_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 |