Class: RSpec::Mocks::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/mocks/configuration.rb

Overview

Provides configuration options for rspec-mocks.

Instance Method Summary (collapse)

Constructor Details

- (Configuration) initialize

A new instance of Configuration

6
7
8
9
10
# File 'lib/rspec/mocks/configuration.rb', line 6
def initialize
  @yield_receiver_to_any_instance_implementation_blocks = false
  @should_warn_about_any_instance_blocks = true
  @marshal_patched = false
end

Instance Method Details

- (Object) add_stub_and_should_receive_to(*modules)

Adds stub and should_receive to the given modules or classes. This is usually only necessary if you application uses some proxy classes that "strip themselves down" to a bare minimum set of methods and remove stub and should_receive in the process.

Examples:

RSpec.configure do |rspec|
  rspec.mock_with :rspec do |mocks|
    mocks.add_stub_and_should_receive_to Delegator
  end
end
40
41
42
43
44
# File 'lib/rspec/mocks/configuration.rb', line 40
def add_stub_and_should_receive_to(*modules)
  modules.each do |mod|
    Syntax.enable_should(mod)
  end
end

- (Boolean) marshal_patched?

Returns:

  • (Boolean)
71
72
73
# File 'lib/rspec/mocks/configuration.rb', line 71
def marshal_patched?
  @marshal_patched
end

- (Object) patch_marshal_to_support_partial_doubles=(val)

67
68
69
# File 'lib/rspec/mocks/configuration.rb', line 67
def patch_marshal_to_support_partial_doubles=(val)
  @marshal_patched = val
end

- (Boolean) should_warn_about_any_instance_blocks?

Returns:

  • (Boolean)
21
22
23
# File 'lib/rspec/mocks/configuration.rb', line 21
def should_warn_about_any_instance_blocks?
  @should_warn_about_any_instance_blocks
end

- (Object) syntax

60
61
62
63
64
65
# File 'lib/rspec/mocks/configuration.rb', line 60
def syntax
  syntaxes = []
  syntaxes << :should  if Syntax.should_enabled?
  syntaxes << :expect if Syntax.expect_enabled?
  syntaxes
end

- (Object) syntax=(values)

46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/rspec/mocks/configuration.rb', line 46
def syntax=(values)
  if Array(values).include?(:expect)
    Syntax.enable_expect
  else
    Syntax.disable_expect
  end
  if Array(values).include?(:should)
    Syntax.enable_should
  else
    Syntax.disable_should
  end
end

- (Object) yield_receiver_to_any_instance_implementation_blocks=(arg)

16
17
18
19
# File 'lib/rspec/mocks/configuration.rb', line 16
def yield_receiver_to_any_instance_implementation_blocks=(arg)
  @should_warn_about_any_instance_blocks = false
  @yield_receiver_to_any_instance_implementation_blocks = arg
end

- (Boolean) yield_receiver_to_any_instance_implementation_blocks?

Returns:

  • (Boolean)
12
13
14
# File 'lib/rspec/mocks/configuration.rb', line 12
def yield_receiver_to_any_instance_implementation_blocks?
  @yield_receiver_to_any_instance_implementation_blocks
end