Sha256: f296583e1cb1531319c5ec8f65304788f16dd4c481a4fb6bbc0119b8ad2ac197

Contents?: true

Size: 1.05 KB

Versions: 9

Compression:

Stored size: 1.05 KB

Contents

module RR
  # RR::DoNotAllowCreator uses RR::DoNotAllowCreator#method_missing to create
  # a Scenario that expects never to be called.
  #
  # The following example mocks method_name with arg1 and arg2
  # returning return_value.
  #
  #   do_not_allow(subject).method_name(arg1, arg2) { return_value }
  #
  # The DoNotAllowCreator also supports a block sytnax.
  #
  #    do_not_allow(subject) do |m|
  #      m.method1 # Do not allow method1 with any arguments
  #      m.method2(arg1, arg2) # Do not allow method2 with arguments arg1 and arg2
  #      m.method3.with_no_args # Do not allow method3 with no arguments
  #    end
  class DoNotAllowCreator < Creator
    module InstanceMethods
      protected
      def method_missing(method_name, *args, &returns)
        double = @space.create_double(@subject, method_name)
        scenario = @space.create_scenario(double)
        if args.empty?
          scenario.with_any_args
        else
          scenario.with(*args)
        end
        scenario.never.returns(&returns)
        scenario
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

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