Sha256: 4517ca61231a8430e06d2a3dfe0ffcac5820a7a3ad72afb047a35716627f6902

Contents?: true

Size: 759 Bytes

Versions: 9

Compression:

Stored size: 759 Bytes

Contents

module RR
  # RR::MockCreator uses RR::MockCreator#method_missing to create
  # a Scenario that acts like a mock.
  #
  # The following example mocks method_name with arg1 and arg2
  # returning return_value.
  #
  #   mock(subject).method_name(arg1, arg2) { return_value }
  #
  # The MockCreator also supports a block sytnax.
  #
  #    mock(subject) do |m|
  #      m.method_name(arg1, arg2) { return_value }
  #    end
  class MockCreator < Creator
    module InstanceMethods
      protected
      def method_missing(method_name, *args, &returns)
        double = @space.create_double(@subject, method_name)
        scenario = @space.create_scenario(double)
        scenario.with(*args).once.returns(&returns)
        scenario
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rr-0.1.13 lib/rr/mock_creator.rb
rr-0.1.15 lib/rr/mock_creator.rb
rr-0.1.12 lib/rr/mock_creator.rb
rr-0.1.14 lib/rr/mock_creator.rb
rr-0.2.2 lib/rr/mock_creator.rb
rr-0.2.4 lib/rr/mock_creator.rb
rr-0.2.1 lib/rr/mock_creator.rb
rr-0.2.3 lib/rr/mock_creator.rb
rr-0.2.5 lib/rr/mock_creator.rb