Module: Caricature::Interception
- Defined in:
- lib/caricature/isolator.rb,
lib/caricature/clr/isolator.rb
Overview
Groups the methods for interception together this is a mix-in for the created isolations for classes
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.included(base) ⇒ Object
mixes in the class methods of this module when it gets included in a class.
Instance Method Summary collapse
-
#did_class_receive?(method_name, &block) ⇒ Boolean
Verifies whether the specified class method has been called You can specify constraints in the block.
-
#did_raise_class_event?(event_name, &b) ⇒ Boolean
Verifies whether the specified event was raised.
-
#did_raise_event?(event_name, &b) ⇒ Boolean
Verifies whether the specified event was raised.
-
#did_receive?(method_name, &block) ⇒ Boolean
Verifies whether the specified method has been called You can specify constraints in the block.
-
#isolation_context ⇒ Object
the context of this isolation instance.
-
#raise_class_event(event_name, *args, &block) ⇒ Object
Raises an event on the isolation You can specify the arguments in the block or as parameters.
-
#raise_event(event_name, *args, &block) ⇒ Object
Raises an event on the isolation You can specify the arguments in the block or as parameters.
-
#when_class_receives(method_name, &block) ⇒ Object
Replaces the call to the class of the proxy with the one you create with this method.
-
#when_receiving(method_name, &block) ⇒ Object
Replaces the call to the proxy with the one you create with this method.
-
#with_subject(*args, &b) ⇒ Object
Initializes the underlying subject It expects the constructor parameters if they are needed.
Class Method Details
.included(base) ⇒ Object
mixes in the class methods of this module when it gets included in a class.
65 66 67 |
# File 'lib/caricature/isolator.rb', line 65 def self.included(base) base.extend ClassMethods end |
Instance Method Details
#did_class_receive?(method_name, &block) ⇒ Boolean
Verifies whether the specified class method has been called You can specify constraints in the block
The most complex configuration you can make currently is one that is constrained by arguments. This is likely to be extended in the future to allow for more complex verifications.
Example:
an_isolation.did_class_receive?(:a_method) do |method_call|
method_call.with(3, "a")
end.should.be.successful
is equivalent to:
an_isolation.did_class_receive?(:a_method).with(3, "a").should.be.successful
You will probably be using this method only when you’re interested in whether a method has been called during the course of the test you’re running.
153 154 155 |
# File 'lib/caricature/isolator.rb', line 153 def did_class_receive?(method_name, &block) self.class.did_receive?(method_name, &block) end |
#did_raise_class_event?(event_name, &b) ⇒ Boolean
Verifies whether the specified event was raised
You will probably be using this method only when you’re interested in whether an event has been raised during the course of the test you’re running.
99 100 101 |
# File 'lib/caricature/clr/isolator.rb', line 99 def did_raise_class_event?(event_name, &b) self.class.did_raise_event? event_name, &b end |
#did_raise_event?(event_name, &b) ⇒ Boolean
Verifies whether the specified event was raised
You will probably be using this method only when you’re interested in whether an event has been raised during the course of the test you’re running.
91 92 93 |
# File 'lib/caricature/clr/isolator.rb', line 91 def did_raise_event?(event_name, &b) isolation_context.verify_event_raise event_name, :instance, &b end |
#did_receive?(method_name, &block) ⇒ Boolean
Verifies whether the specified method has been called You can specify constraints in the block
The most complex configuration you can make currently is one that is constrained by arguments. This is most likely to be extended in the future to allow for more complex verifications.
Example:
an_isolation.did_receive?(:a_method) do |method_call|
method_call.with(3, "a")
end.should.be.successful
is equivalent to:
an_isolation.did_receive?(:a_method).with(3, "a").should.be.successful
You will probably be using this method only when you’re interested in whether a method has been called during the course of the test you’re running.
131 132 133 |
# File 'lib/caricature/isolator.rb', line 131 def did_receive?(method_name, &block) isolation_context.verify method_name, &block end |
#isolation_context ⇒ Object
the context of this isolation instance. this context takes care of responding to method calls etc.
71 72 73 |
# File 'lib/caricature/isolator.rb', line 71 def isolation_context self.class.isolation_context end |
#raise_class_event(event_name, *args, &block) ⇒ Object
Raises an event on the isolation You can specify the arguments in the block or as parameters
Example
an_isolation.raise_class_event :on_property_changed do |raiser|
raiser.with an_isolation, System::EventArgs.empty
end
is equivalent to:
an_isolation.raise_class_event :on_property_changed, an_isolation, System::EventArgs.empty
or
an_isolation.raise_class_event(:on_property_changed).with(an_isolation, System::EventArgs.empty)
You will most likely use this method when you want to verify logic in an event handler
83 84 85 |
# File 'lib/caricature/clr/isolator.rb', line 83 def raise_class_event(event_name, *args, &block) self.class.raise_event event_name, *args, &block end |
#raise_event(event_name, *args, &block) ⇒ Object
Raises an event on the isolation You can specify the arguments in the block or as parameters
Example
an_isolation.raise_event :on_property_changed do |raiser|
raiser.with an_isolation, System::EventArgs.empty
end
is equivalent to:
an_isolation.raise_event :on_property_changed, an_isolation, System::EventArgs.empty
or
an_isolation.raise_event(:on_property_changed).with(an_isolation, System::EventArgs.empty)
You will most likely use this method when you want to verify logic in an event handler
61 62 63 |
# File 'lib/caricature/clr/isolator.rb', line 61 def raise_event(event_name, *args, &block) isolation_context.add_event_expectation event_name, :instance, *args, &block end |
#when_class_receives(method_name, &block) ⇒ Object
Replaces the call to the class of the proxy with the one you create with this method. You can specify more specific criteria in the block to configure the expectation.
Example:
an_isolation.when_class_receives(:a_method) do |method_call|
method_call.with(3, "a").return(5)
end
is equivalent to:
an_isolation.when_class_receives(:a_method).with(3, "a").return(5)
You will most likely use this method when you want your stubs to return something else than nil when they get called during the run of the test they are defined in.
109 110 111 |
# File 'lib/caricature/isolator.rb', line 109 def when_class_receives(method_name, &block) self.class.when_receiving method_name, &block end |
#when_receiving(method_name, &block) ⇒ Object
Replaces the call to the proxy with the one you create with this method. You can specify more specific criteria in the block to configure the expectation.
Example:
an_isolation.when_receiving(:a_method) do |method_call|
method_call.with(3, "a").return(5)
end
is equivalent to:
an_isolation.when_receiving(:a_method).with(3, "a").return(5)
You will most likely use this method when you want your stubs to return something else than nil when they get called during the run of the test they are defined in.
90 91 92 |
# File 'lib/caricature/isolator.rb', line 90 def when_receiving(method_name, &block) isolation_context.create_override method_name, &block end |
#with_subject(*args, &b) ⇒ Object
Initializes the underlying subject It expects the constructor parameters if they are needed.
159 160 161 162 163 |
# File 'lib/caricature/isolator.rb', line 159 def with_subject(*args, &b) isolation_context.instance = self.class.superclass.new *args b.call self if b self end |