Class: Caricature::EventVerification

Inherits:
Object
  • Object
show all
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

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_argumentsObject

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

Returns:

  • (Boolean)


18
19
20
# File 'lib/caricature/clr/event_verification.rb', line 18

def any_args?
  @any_args
end

#errorObject



41
42
43
# File 'lib/caricature/clr/event_verification.rb', line 41

def error
  @recorder.event_error
end

#init_pluginObject



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.

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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