Class: RR::DoubleDefinitions::Strategies::Scope::InstanceOfClass

Inherits:
ScopeStrategy show all
Defined in:
lib/rr/double_definitions/strategies/scope/instance_of_class.rb

Overview

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

Instance Attribute Summary

Attributes inherited from RR::DoubleDefinitions::Strategies::Strategy

#args, #definition, #double_definition_creator, #handler, #method_name

Instance Method Summary collapse

Methods inherited from ScopeStrategy

register_self_at_double_definition_creator

Methods inherited from RR::DoubleDefinitions::Strategies::Strategy

#call, #name, register, register_self_at_double_definition_creator, #verify_subject

Methods included from Space::Reader

#space

Constructor Details

#initialize(*args) ⇒ InstanceOfClass

Returns a new instance of InstanceOfClass.



19
20
21
22
23
24
25
# File 'lib/rr/double_definitions/strategies/scope/instance_of_class.rb', line 19

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