Sha256: c6c2b4df24ebb26e0b8510ff1e4f810865b0269f6f403d912fa2080e20f43ab6

Contents?: true

Size: 1.13 KB

Versions: 5

Compression:

Stored size: 1.13 KB

Contents

module RR
  # RR::MockProbeCreator uses RR::MockProbeCreator#method_missing to create
  # a Scenario that acts like a mock with probing capabilities.
  #
  # Passing a block allows you to intercept the return value.
  # The return value can be modified, validated, and/or overridden by
  # passing in a block. The return value of the block will replace
  # the actual return value.
  #
  #   probe(subject).method_name(arg1, arg2) do |return_value|
  #     return_value.method_name.should == :return_value
  #     my_return_value
  #   end
  #
  #   probe(User) do |m|
  #     m.find('4') do |user|
  #       mock(user).valid? {false}
  #       user
  #     end
  #   end
  #
  #   user = User.find('4')
  #   user.valid? # false
  class MockProbeCreator < 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

5 entries across 5 versions & 1 rubygems

Version Path
rr-0.2.3 lib/rr/mock_probe_creator.rb
rr-0.2.5 lib/rr/mock_probe_creator.rb
rr-0.2.4 lib/rr/mock_probe_creator.rb
rr-0.2.2 lib/rr/mock_probe_creator.rb
rr-0.2.1 lib/rr/mock_probe_creator.rb