Class: RR::MockCreator
- Inherits:
-
Object
- Object
- RR::MockCreator
- Defined in:
- lib/rr/mock_creator.rb
Overview
RR::MockCreator uses RR::MockCreator#method_missing to create a Scenario that acts like a mock.
The following example mocks method_name with arg1 and arg2 returning return_value.
mock(subject).method_name(arg1, arg2) { return_value }
The MockCreator also supports a block sytnax.
mock(subject) do |m|
m.method_name(arg1, arg2) { return_value }
end
Instance Method Summary collapse
-
#initialize(space, subject) {|_self| ... } ⇒ MockCreator
constructor
A new instance of MockCreator.
Constructor Details
#initialize(space, subject) {|_self| ... } ⇒ MockCreator
Returns a new instance of MockCreator.
18 19 20 21 22 |
# File 'lib/rr/mock_creator.rb', line 18 def initialize(space, subject) @space = space @subject = subject yield(self) if block_given? end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &returns) ⇒ Object (protected)
25 26 27 28 29 30 |
# File 'lib/rr/mock_creator.rb', line 25 def method_missing(method_name, *args, &returns) double = @space.create_double(@subject, method_name) scenario = @space.create_scenario(double) scenario.with(*args).once.returns(&returns) scenario end |