Module: RSpec::Mocks

Defined in:
lib/rspec/mocks.rb,
lib/rspec/mocks/mock.rb,
lib/rspec/mocks/space.rb,
lib/rspec/mocks/proxy.rb,
lib/rspec/mocks/errors.rb,
lib/rspec/mocks/syntax.rb,
lib/rspec/mocks/targets.rb,
lib/rspec/mocks/version.rb,
lib/rspec/mocks/stub_chain.rb,
lib/rspec/mocks/deprecation.rb,
lib/rspec/mocks/order_group.rb,
lib/rspec/mocks/test_double.rb,
lib/rspec/mocks/mutate_const.rb,
lib/rspec/mocks/configuration.rb,
lib/rspec/mocks/method_double.rb,
lib/rspec/mocks/proxy_for_nil.rb,
lib/rspec/mocks/example_methods.rb,
lib/rspec/mocks/error_generator.rb,
lib/rspec/mocks/matchers/receive.rb,
lib/rspec/mocks/argument_matchers.rb,
lib/rspec/mocks/any_instance/chain.rb,
lib/rspec/mocks/message_expectation.rb,
lib/rspec/mocks/argument_list_matcher.rb,
lib/rspec/mocks/any_instance/recorder.rb,
lib/rspec/mocks/matchers/have_received.rb,
lib/rspec/mocks/instance_method_stasher.rb,
lib/rspec/mocks/any_instance/stub_chain.rb,
lib/rspec/mocks/extensions/instance_exec.rb,
lib/rspec/mocks/any_instance/message_chains.rb,
lib/rspec/mocks/any_instance/stub_chain_chain.rb,
lib/rspec/mocks/any_instance/expectation_chain.rb

Defined Under Namespace

Modules: AnyInstance, ArgumentMatchers, Deprecation, ExampleMethods, Matchers, RecursiveConstMethods, Syntax, TestDouble, Version Classes: AllowanceTarget, AnyInstanceAllowanceTarget, AnyInstanceExpectationTarget, ArgumentListMatcher, Configuration, Constant, ConstantMutator, ExpectationTarget, MessageExpectation, Mock, Space, TargetBase

Constant Summary

KERNEL_METHOD_METHOD =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

::Kernel.instance_method(:method)
UnsupportedMatcherError =
Class.new(StandardError)
NegationUnsupportedError =
Class.new(StandardError)
ConstantStubber =

Keeps backwards compatibility since we had released an rspec-mocks that only supported stubbing. Later, we released the hide_const feature and decided that the term "mutator" was a better term to wrap up the concept of both stubbing and hiding.

ConstantMutator

Class Attribute Summary (collapse)

Class Method Summary (collapse)

Class Attribute Details

+ (Object) space

Returns the value of attribute space



8
9
10
# File 'lib/rspec/mocks.rb', line 8

def space
  @space
end

Class Method Details

+ (Object) any_instance_recorder_for(klass)



29
30
31
# File 'lib/rspec/mocks.rb', line 29

def any_instance_recorder_for(klass)
  space.any_instance_recorder_for(klass)
end

+ (Object) configuration



48
49
50
# File 'lib/rspec/mocks/configuration.rb', line 48

def self.configuration
  @configuration ||= Configuration.new
end

+ (Object) method_handle_for(object, method_name)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Used internally to get a method handle for a particular object and method name.

Includes handling for a few special cases:

  • Objects that redefine #method (e.g. an HTTPRequest struct)
  • BasicObject subclasses that mixin a Kernel dup (e.g. SimpleDelegator)


44
45
46
47
48
49
50
# File 'lib/rspec/mocks.rb', line 44

def method_handle_for(object, method_name)
  if ::Kernel === object
    KERNEL_METHOD_METHOD.bind(object).call(method_name)
  else
    object.method(method_name)
  end
end

+ (Object) proxy_for(object)



25
26
27
# File 'lib/rspec/mocks.rb', line 25

def proxy_for(object)
  space.proxy_for(object)
end

+ (Object) setup(host)



10
11
12
13
14
15
# File 'lib/rspec/mocks.rb', line 10

def setup(host)
  (class << host; self; end).class_eval do
    include RSpec::Mocks::ExampleMethods
  end
  self.space ||= RSpec::Mocks::Space.new
end

+ (Object) teardown



21
22
23
# File 'lib/rspec/mocks.rb', line 21

def teardown
  space.reset_all
end

+ (Object) verify



17
18
19
# File 'lib/rspec/mocks.rb', line 17

def verify
  space.verify_all
end