Class: RR::StubCreator
- Inherits:
-
Object
- Object
- RR::StubCreator
- Defined in:
- lib/rr/stub_creator.rb
Overview
RR::StubCreator uses RR::StubCreator#method_missing to create a Scenario that acts like a stub.
The following example stubs method_name with arg1 and arg2 returning return_value.
stub(subject).method_name(arg1, arg2) { return_value }
The StubCreator also supports a block sytnax.
stub(subject) do |m|
m.method_name(arg1, arg2) { return_value }
end
Instance Method Summary collapse
-
#initialize(space, subject) {|_self| ... } ⇒ StubCreator
constructor
A new instance of StubCreator.
Constructor Details
#initialize(space, subject) {|_self| ... } ⇒ StubCreator
Returns a new instance of StubCreator.
18 19 20 21 22 |
# File 'lib/rr/stub_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 31 32 33 34 |
# File 'lib/rr/stub_creator.rb', line 25 def method_missing(method_name, *args, &returns) double = @space.create_double(@subject, method_name) scenario = @space.create_scenario(double) scenario.returns(&returns) if args.empty? scenario.with_any_args else scenario.with(*args) end end |