Sha256: 6f50e9c296956c4c8ac1ccb4d3ae3f83e1e8f7f5fbbcbdbe0099d90318814347

Contents?: true

Size: 1.26 KB

Versions: 5

Compression:

Stored size: 1.26 KB

Contents

module RR
  # RR::StubProbeCreator uses RR::StubProbeCreator#method_missing to create
  # a Scenario that acts like a stub 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_stub(subject).method_name(arg1, arg2) do |return_value|
  #     return_value.method_name.should == :return_value
  #     my_return_value
  #   end
  #
  #   probe_stub(User) do |m|
  #     m.find do |user|
  #       mock(user).valid? {false}
  #       user
  #     end
  #   end
  #
  #   user = User.find('4')
  #   user.valid? # false
  class StubProbeCreator < 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.implemented_by(double.original_method)
        scenario.any_number_of_times
        if args.empty?
          scenario.with_any_args
        else
          scenario.with(*args)
        end
        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.2 lib/rr/stub_probe_creator.rb
rr-0.2.3 lib/rr/stub_probe_creator.rb
rr-0.2.4 lib/rr/stub_probe_creator.rb
rr-0.2.1 lib/rr/stub_probe_creator.rb
rr-0.2.5 lib/rr/stub_probe_creator.rb