Sha256: 6ac07e6f8ddc2135866ffa2cab774d4b6a0a8ccf5f6c285b66ae03a56102a445

Contents?: true

Size: 1.53 KB

Versions: 19

Compression:

Stored size: 1.53 KB

Contents

module RR
  module DoubleDefinitions
    module Strategies
      module Scope
        # Calling instance_of will cause all instances of the passed in Class
        # to have the Double defined.
        #
        # The following example mocks all User's valid? method and return false.
        #   mock.instance_of(User).valid? {false}
        #
        # The following example mocks and proxies User#projects and returns the
        # first 3 projects.
        #   mock.instance_of(User).projects do |projects|
        #     projects[0..2]
        #   end        
        class InstanceOfClass < ScopeStrategy
          register "instance_of"

          def initialize(*args)
            super

            if !double_definition_creator.no_subject? && !double_definition_creator.subject.is_a?(Class)
              raise ArgumentError, "instance_of only accepts class objects"
            end
          end

          protected
          def do_call
            class_handler = lambda do |return_value|
              #####
              double_injection = space.double_injection(return_value, method_name)
              Double.new(double_injection, definition)
              #####
              return_value
            end

            instance_of_subject_creator = DoubleDefinitionCreator.new
            instance_of_subject_creator.strong if definition.verify_method_signature?
            instance_of_subject_creator.stub.proxy(subject)
            instance_of_subject_creator.create(:new, &class_handler)
          end
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 3 rubygems

Version Path
adva-0.3.2 test/rr/lib/rr/double_definitions/strategies/scope/instance_of_class.rb
adva-0.3.1 test/rr/lib/rr/double_definitions/strategies/scope/instance_of_class.rb
adva-0.3.0 test/rr/lib/rr/double_definitions/strategies/scope/instance_of_class.rb
adva-0.2.4 test/rr/lib/rr/double_definitions/strategies/scope/instance_of_class.rb
adva-0.2.3 test/rr/lib/rr/double_definitions/strategies/scope/instance_of_class.rb
adva-0.2.2 test/rr/lib/rr/double_definitions/strategies/scope/instance_of_class.rb
adva-0.2.1 test/rr/lib/rr/double_definitions/strategies/scope/instance_of_class.rb
adva-0.2.0 test/rr/lib/rr/double_definitions/strategies/scope/instance_of_class.rb
adva-0.1.4 test/rr/lib/rr/double_definitions/strategies/scope/instance_of_class.rb
adva-0.1.3 test/rr/lib/rr/double_definitions/strategies/scope/instance_of_class.rb
adva-0.1.2 test/rr/lib/rr/double_definitions/strategies/scope/instance_of_class.rb
adva-0.1.1 test/rr/lib/rr/double_definitions/strategies/scope/instance_of_class.rb
adva-0.1.0 test/rr/lib/rr/double_definitions/strategies/scope/instance_of_class.rb
adva-0.0.1 test/rr/lib/rr/double_definitions/strategies/scope/instance_of_class.rb
jferris-rr-0.7.1.0.1239654108 lib/rr/double_definitions/strategies/scope/instance_of_class.rb
rr-0.8.1 lib/rr/double_definitions/strategies/scope/instance_of_class.rb
rr-0.7.1 lib/rr/double_definitions/strategies/scope/instance_of_class.rb
rr-0.7.0 lib/rr/double_definitions/strategies/scope/instance_of_class.rb
rr-0.8.0 lib/rr/double_definitions/strategies/scope/instance_of_class.rb