Sha256: ae312553163e0f1fb666d99c29bd5dbb79080db402d34a5b8dc900ede4431cae

Contents?: true

Size: 857 Bytes

Versions: 9

Compression:

Stored size: 857 Bytes

Contents

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

Version data entries

9 entries across 9 versions & 1 rubygems

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