Sha256: f4ad1c284a9a5ecc3d3d35567b8b6dd197e2787937ebec3e65f4b9967a640de5

Contents?: true

Size: 1.17 KB

Versions: 4

Compression:

Stored size: 1.17 KB

Contents

module RR
  # RR::ProbeCreator uses RR::ProbeCreator#method_missing to create
  # a Scenario that acts like a probe.
  #
  # The following example probes method_name with arg1 and arg2
  # returning the actual value of the method. The block is an after callback
  # that intercepts the return value. Mocks or other modifications can
  # be done to the return value.
  #
  #   probe(subject).method_name(arg1, arg2) { |return_value| }
  #
  # The ProbeCreator also supports a block sytnax. The block accepts
  # a after_call callback, instead of a return value as with MockCreator
  # and StubCreator.
  #
  #    probe(User) do |m|
  #      m.find('4') do |user|
  #        mock(user).valid? {false}
  #      end
  #    end
  #
  #   user = User.find('4')
  #   user.valid? # false
  class ProbeCreator < Creator
    module InstanceMethods
      protected
      def method_missing(method_name, *args, &after_call)
        double = @space.create_double(@subject, method_name)
        scenario = @space.create_scenario(double)
        scenario.with(*args).once.implemented_by(double.original_method)
        scenario.after_call(&after_call) if after_call
        scenario
      end      
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rr-0.1.12 lib/rr/probe_creator.rb
rr-0.1.13 lib/rr/probe_creator.rb
rr-0.1.14 lib/rr/probe_creator.rb
rr-0.1.15 lib/rr/probe_creator.rb