Class: Caricature::Expectation
- 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
-
#args ⇒ Object
the arguments that this expectation needs to be constrained by.
-
#block ⇒ Object
the block that will be used.
-
#block=(val) ⇒ Object
sets the block callback.
-
#block_args ⇒ Object
contains the arguments that will be passed on to the block.
-
#block_callback ⇒ Object
The block that will be used as value provider for the block in the method.
-
#call_super? ⇒ Boolean
indicates whether super needs to be called somewhere.
-
#callback ⇒ Object
contains the callback if one is given.
-
#error_args ⇒ Object
the error_args that this expectation will raise an error with.
-
#event_args ⇒ Object
the arguments that will be used for the event.
-
#event_handler ⇒ Object
the block that will be used# the block that will be used.
-
#event_name ⇒ Object
the block that will be used.
- #event_recorder(&b) ⇒ Object
-
#events ⇒ Object
the events attached to the context.
-
#events=(evts) ⇒ Object
Set the registered events for this expectation.
-
#execute(*margs, &b) ⇒ Object
executes this expectation with its configuration.
-
#has_block_callback? ⇒ Boolean
indicates whether this expectation has a block as value provider for the method call block.
-
#has_callback? ⇒ Boolean
indicates whether this expecation has a callback it needs to execute.
-
#has_error_args? ⇒ Boolean
indicates whether this expecation will raise an event.
-
#has_event_handler? ⇒ Boolean
indicates whether this expectation has an event handler to be called.
-
#has_return_callback? ⇒ Boolean
a flag to indicate it has a return value callback.
-
#has_return_value? ⇒ Boolean
indicates whether this expectation will return a value.
-
#initialize(options = {}) ⇒ Expectation
constructor
Initializes a new instance of an expectation.
-
#method_name ⇒ Object
gets the method_name to which this expectation needs to listen to.
-
#raises_event? ⇒ Boolean
indicates whether this expectation has an event that needs to be raised.
-
#raises_registered? ⇒ Boolean
indicates whether to raise the registered event handlers.
-
#return_callback ⇒ Object
contains the callback that is used to return the value when this expectation is executed.
-
#return_value ⇒ Object
the value that this expecation will return when executed.
-
#super ⇒ Object
indicator for the mode to call the super
:before,:afterandnil. -
#super_before? ⇒ Boolean
call the super before the expectation.
-
#to_s ⇒ Object
(also: #inspect)
:nodoc:.
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(={}) collected[:any_args] = true collected.merge!() end |
Instance Method Details
#args ⇒ Object
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 |
#block ⇒ Object
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_args ⇒ Object
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_callback ⇒ Object
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
185 186 187 |
# File 'lib/caricature/expectation.rb', line 185 def call_super? !collected[:super].nil? end |
#callback ⇒ Object
contains the callback if one is given
123 124 125 |
# File 'lib/caricature/expectation.rb', line 123 def callback collected[:callback] end |
#error_args ⇒ Object
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_args ⇒ Object
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_handler ⇒ Object
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_name ⇒ Object
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 |
#events ⇒ Object
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
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
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.
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
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
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.
175 176 177 |
# File 'lib/caricature/expectation.rb', line 175 def has_return_value? !collected[:return_value].nil? end |
#method_name ⇒ Object
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
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
68 69 70 |
# File 'lib/caricature/clr/expectation.rb', line 68 def raises_registered? !!collected[:raise_subscriptions] end |
#return_callback ⇒ Object
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_value ⇒ Object
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 |
#super ⇒ Object
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
180 181 182 |
# File 'lib/caricature/expectation.rb', line 180 def super_before? collected[:super] == :before end |
#to_s ⇒ Object 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 |