Class: Caricature::Expectation

Inherits:
Object
  • Object
show all
Includes:
EventExpectationSyntax, ExpectationSyntax
Defined in:
lib/caricature/expectation.rb,
lib/caricature/clr/expectation.rb

Overview

Adds event support to the expectation this is only applicable to clr isolations and not to ruby isolations

Instance Method Summary collapse

Methods included from EventExpectationSyntax

#raise_event, #raise_subscriptions

Methods included from ExpectationSyntax

#actual_raise, #any_args?, #pass_block, #raise, #return, #super_after, #super_before, #with

Constructor Details

#initialize(options = {}) ⇒ Expectation

Initializes a new instance of an expectation



164
165
166
167
# File 'lib/caricature/expectation.rb', line 164

def initialize(options={})
  collected[:any_args] = true
  collected.merge!(options)
end

Instance Method Details

#argsObject

the arguments that this expectation needs to be constrained by



159
160
161
# File 'lib/caricature/expectation.rb', line 159

def args
  collected[:args]
end

#blockObject

the block that will be used



144
145
146
# File 'lib/caricature/expectation.rb', line 144

def block
  collected[:block]
end

#block=(val) ⇒ Object

sets the block callback



149
150
151
# File 'lib/caricature/expectation.rb', line 149

def block=(val)
  collected[:block] = val
end

#block_argsObject

contains the arguments that will be passed on to the block



134
135
136
# File 'lib/caricature/expectation.rb', line 134

def block_args
  collected[:block_args]
end

#block_callbackObject

The block that will be used as value provider for the block in the method



139
140
141
# File 'lib/caricature/expectation.rb', line 139

def block_callback
  collected[:block_callback]
end

#call_super?Boolean

indicates whether super needs to be called somewhere

Returns:

  • (Boolean)


185
186
187
# File 'lib/caricature/expectation.rb', line 185

def call_super?
  !collected[:super].nil?
end

#callbackObject

contains the callback if one is given



123
124
125
# File 'lib/caricature/expectation.rb', line 123

def callback
  collected[:callback]
end

#error_argsObject

the error_args that this expectation will raise an error with



108
109
110
# File 'lib/caricature/expectation.rb', line 108

def error_args
  collected[:error_args]
end

#event_argsObject

the arguments that will be used for the event



37
38
39
40
# File 'lib/caricature/clr/expectation.rb', line 37

def event_args
  evt_ags = collected[:event_args]
  evt_ags.nil? or evt_ags.empty? ? [nil, System::EventArgs.empty] : evt_ags
end

#event_handlerObject

the block that will be used# the block that will be used



43
44
45
# File 'lib/caricature/clr/expectation.rb', line 43

def event_handler
  collected[:event_handler] || lambda { |s,e| }
end

#event_nameObject

the block that will be used



32
33
34
# File 'lib/caricature/clr/expectation.rb', line 32

def event_name
  collected[:event_name]
end

#event_recorder(&b) ⇒ Object



72
73
74
# File 'lib/caricature/clr/expectation.rb', line 72

def event_recorder(&b)
  @event_recorder = b
end

#eventsObject

the events attached to the context



48
49
50
# File 'lib/caricature/clr/expectation.rb', line 48

def events
  collected[:events] ||= {}
end

#events=(evts) ⇒ Object

Set the registered events for this expectation



53
54
55
# File 'lib/caricature/clr/expectation.rb', line 53

def events=(evts)
  collected[:events]=evts
end

#execute(*margs, &b) ⇒ Object

executes this expectation with its configuration



205
206
207
208
209
210
211
212
213
214
215
# File 'lib/caricature/expectation.rb', line 205

def execute(*margs,&b)
  ags = any_args? ? :any : (margs.empty? ? collected[:args] : margs)
  do_raise_error
  do_callback(ags)
  do_block_callback(&b)
  do_event_raise if respond_to?(:events)

  return collected[:return_callback].call(*margs) if has_return_callback?
  return return_value if has_return_value? 
  nil
end

#has_block_callback?Boolean

indicates whether this expectation has a block as value provider for the method call block

Returns:

  • (Boolean)


195
196
197
# File 'lib/caricature/expectation.rb', line 195

def has_block_callback?
  !collected[:block_callback].nil?
end

#has_callback?Boolean

indicates whether this expecation has a callback it needs to execute

Returns:

  • (Boolean)


190
191
192
# File 'lib/caricature/expectation.rb', line 190

def has_callback? 
  !collected[:callback].nil?
end

#has_error_args?Boolean

indicates whether this expecation will raise an event.

Returns:

  • (Boolean)


170
171
172
# File 'lib/caricature/expectation.rb', line 170

def has_error_args?
  !collected[:error_args].nil?
end

#has_event_handler?Boolean

indicates whether this expectation has an event handler to be called

Returns:

  • (Boolean)


63
64
65
# File 'lib/caricature/clr/expectation.rb', line 63

def has_event_handler?
  !!collected[:event_handler]
end

#has_return_callback?Boolean

a flag to indicate it has a return value callback

Returns:

  • (Boolean)


200
201
202
# File 'lib/caricature/expectation.rb', line 200

def has_return_callback?
  !collected[:return_callback].nil?
end

#has_return_value?Boolean

indicates whether this expectation will return a value.

Returns:

  • (Boolean)


175
176
177
# File 'lib/caricature/expectation.rb', line 175

def has_return_value?
  !collected[:return_value].nil?
end

#method_nameObject

gets the method_name to which this expectation needs to listen to



154
155
156
# File 'lib/caricature/expectation.rb', line 154

def method_name 
  collected[:method_name]
end

#raises_event?Boolean

indicates whether this expectation has an event that needs to be raised

Returns:

  • (Boolean)


58
59
60
# File 'lib/caricature/clr/expectation.rb', line 58

def raises_event?
  !!collected[:event_name]
end

#raises_registered?Boolean

indicates whether to raise the registered event handlers

Returns:

  • (Boolean)


68
69
70
# File 'lib/caricature/clr/expectation.rb', line 68

def raises_registered?
  !!collected[:raise_subscriptions]
end

#return_callbackObject

contains the callback that is used to return the value when this expectation is executed



129
130
131
# File 'lib/caricature/expectation.rb', line 129

def return_callback
  collected[:return_callback]
end

#return_valueObject

the value that this expecation will return when executed



113
114
115
# File 'lib/caricature/expectation.rb', line 113

def return_value
  collected[:return_value]
end

#superObject

indicator for the mode to call the super :before, :after and nil



118
119
120
# File 'lib/caricature/expectation.rb', line 118

def super 
  collected[:super]
end

#super_before?Boolean

call the super before the expectation

Returns:

  • (Boolean)


180
181
182
# File 'lib/caricature/expectation.rb', line 180

def super_before?
  collected[:super] == :before
end

#to_sObject Also known as: inspect

:nodoc:



217
218
219
# File 'lib/caricature/expectation.rb', line 217

def to_s #:nodoc:
  "<Caricature::Expecation, method_name: #{method_name}, args: #{args}, error args: #{error_args}>"
end