lib/rr/scenario_creator.rb in rr-0.3.1 vs lib/rr/scenario_creator.rb in rr-0.3.2
- old
+ new
@@ -14,10 +14,11 @@
def initialize(space)
@space = space
@strategy = nil
@probe = false
+ @instance_of = nil
end
def create!(subject, method_name, *args, &handler)
@subject = subject
@method_name = method_name
@@ -27,10 +28,17 @@
@scenario = @space.scenario(@double)
transform!
@scenario
end
+# def instance_of(subject=NO_SUBJECT_ARG, method_name=nil, &definition)
+# return self if subject === NO_SUBJECT_ARG
+# raise ArgumentError, "instance_of only accepts class objects" unless subject.is_a?(Class)
+# @instance_of = true
+# RR::Space.scenario_method_proxy(self, subject, method_name, &definition)
+# end
+
# This method sets the Scenario to have a mock strategy. A mock strategy
# sets the default state of the Scenario to expect the method call
# with arguments exactly one time. The Scenario's expectations can be
# changed.
#
@@ -57,11 +65,11 @@
# method_name_2(arg_1, arg_2) {return_value_2}
# end
def mock(subject=NO_SUBJECT_ARG, method_name=nil, &definition)
strategy_error! if @strategy
@strategy = :mock
- return self if subject === NO_SUBJECT_ARG
+ return self if subject.__id__ === NO_SUBJECT_ARG.__id__
RR::Space.scenario_method_proxy(self, subject, method_name, &definition)
end
# This method sets the Scenario to have a stub strategy. A stub strategy
# sets the default state of the Scenario to expect the method call
@@ -92,19 +100,35 @@
# method_name_2(arg_1, arg_2) {return_value_2}
# end
def stub(subject=NO_SUBJECT_ARG, method_name=nil, &definition)
strategy_error! if @strategy
@strategy = :stub
- return self if subject === NO_SUBJECT_ARG
+ return self if subject.__id__ === NO_SUBJECT_ARG.__id__
RR::Space.scenario_method_proxy(self, subject, method_name, &definition)
end
+ # This method sets the Scenario to have a do_not_call strategy.
+ # A do_not_call strategy sets the default state of the Scenario
+ # to expect never to be called. The Scenario's expectations can be
+ # changed.
+ #
+ # The following example sets the expectation that subject.method_name
+ # will never be called with arg1 and arg2.
+ #
+ # do_not_allow(subject).method_name(arg1, arg2)
+ #
+ # do_not_call also supports a block sytnax.
+ # do_not_call(subject) do |m|
+ # m.method1 # Do not allow method1 with any arguments
+ # m.method2(arg1, arg2) # Do not allow method2 with arguments arg1 and arg2
+ # m.method3.with_no_args # Do not allow method3 with no arguments
+ # end
def do_not_call(subject=NO_SUBJECT_ARG, method_name=nil, &definition)
strategy_error! if @strategy
probe_when_do_not_call_error! if @probe
@strategy = :do_not_call
- return self if subject === NO_SUBJECT_ARG
+ return self if subject.__id__ === NO_SUBJECT_ARG.__id__
RR::Space.scenario_method_proxy(self, subject, method_name, &definition)
end
alias_method :dont_call, :do_not_call
alias_method :do_not_allow, :do_not_call
alias_method :dont_allow, :do_not_call
@@ -155,10 +179,10 @@
# "My new return value"
# end
def probe(subject=NO_SUBJECT_ARG, method_name=nil, &definition)
probe_when_do_not_call_error! if @strategy == :do_not_call
@probe = true
- return self if subject === NO_SUBJECT_ARG
+ return self if subject.__id__ === NO_SUBJECT_ARG.__id__
RR::Space.scenario_method_proxy(self, subject, method_name, &definition)
end
protected
def transform!