Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Commit b79c030

Browse files
authored
Merge pull request #1410 from rspec/remove-deprecated-allow_message_expectations_on_nil-example-method
Remove deprecated `allow_message_expectations_on_nil` example method
2 parents 91ddf83 + f9b5486 commit b79c030

File tree

4 files changed

+26
-57
lines changed

4 files changed

+26
-57
lines changed

Changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Breaking Changes:
99
(Phil Pirozhkov, #1400)
1010
* Change the default setting for `RSpec::Mocks::Configuration#verify_partial_doubles`
1111
to `true`. (Phil Pirozhkov, #1409)
12+
* Remove deprecated `allow_message_expectations_on_nil` example method.
13+
(Phil Pirozhkov, #1410)
1214

1315
Bug Fixes:
1416

lib/rspec/mocks/example_methods.rb

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -192,16 +192,6 @@ def class_spy(*args)
192192
class_double(*args).as_null_object
193193
end
194194

195-
# Disables warning messages about expectations being set on nil.
196-
#
197-
# By default warning messages are issued when expectations are set on
198-
# nil. This is to prevent false-positives and to catch potential bugs
199-
# early on.
200-
# @deprecated Use {RSpec::Mocks::Configuration#allow_message_expectations_on_nil} instead.
201-
def allow_message_expectations_on_nil
202-
RSpec::Mocks.space.proxy_for(nil).warn_about_expectations = false
203-
end
204-
205195
# Stubs the named constant with the given value.
206196
# Like method stubs, the constant will be restored
207197
# to its original value (or lack of one, if it was

spec/rspec/mocks/nil_expectation_warning_spec.rb

Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,27 @@ module Mocks
2121
)).to_stderr
2222
end
2323

24-
it 'does not issue a warning when expectations are set to be allowed' do
25-
allow_message_expectations_on_nil
26-
27-
expect {
28-
expect(nil).to receive(:foo)
29-
expect(nil).to_not receive(:bar)
30-
}.not_to output.to_stderr
31-
32-
nil.foo
33-
end
34-
3524
context 'configured to allow expectation on nil' do
3625
include_context 'with isolated configuration'
3726

38-
it 'does not issue a warning when expectations are set to be allowed' do
39-
RSpec::Mocks.configuration.allow_message_expectations_on_nil = true
27+
before { RSpec::Mocks.configuration.allow_message_expectations_on_nil = true }
4028

29+
it 'does not issue a warning when expectations are set to be allowed' do
4130
expect {
4231
expect(nil).to receive(:foo)
4332
expect(nil).not_to receive(:bar)
4433
}.not_to output.to_stderr
4534

4635
nil.foo
4736
end
37+
38+
describe "marshalled `nil`" do
39+
include_context "with monkey-patched marshal"
40+
41+
it 'doesnt error when marshalled' do
42+
expect(Marshal.dump(nil)).to eq Marshal.dump_without_rspec_mocks(nil)
43+
end
44+
end
4845
end
4946

5047
context 'configured to disallow expectations on nil' do
@@ -63,29 +60,5 @@ module Mocks
6360
dbl.nil?
6461
end
6562
end
66-
67-
RSpec.describe "#allow_message_expectations_on_nil" do
68-
include_context "with monkey-patched marshal"
69-
70-
it "does not affect subsequent examples" do
71-
allow_message_expectations_on_nil
72-
RSpec::Mocks.teardown
73-
RSpec::Mocks.setup
74-
75-
expect {
76-
expect(nil).to receive(:foo)
77-
}.to output(a_string_including(
78-
"An expectation of `:foo` was set on `nil`",
79-
"#{__FILE__}:#{__LINE__ - 3}"
80-
)).to_stderr
81-
82-
nil.foo
83-
end
84-
85-
it 'doesnt error when marshalled' do
86-
allow_message_expectations_on_nil
87-
expect(Marshal.dump(nil)).to eq Marshal.dump_without_rspec_mocks(nil)
88-
end
89-
end
9063
end
9164
end

spec/rspec/mocks/partial_double_spec.rb

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,17 +123,21 @@ def call(name)
123123
end
124124
end
125125

126-
it "uses reports nil in the error message" do
127-
allow_message_expectations_on_nil
126+
context 'configured to allow expectation on nil' do
127+
include_context 'with isolated configuration'
128128

129-
nil_var = nil
130-
expect(nil_var).to receive(:foobar)
131-
expect {
132-
verify nil_var
133-
}.to raise_error(
134-
RSpec::Mocks::MockExpectationError,
135-
%Q|(nil).foobar(*(any args))\n expected: 1 time with any arguments\n received: 0 times with any arguments|
136-
)
129+
it "uses reports nil in the error message" do
130+
RSpec::Mocks.configuration.allow_message_expectations_on_nil = true
131+
132+
nil_var = nil
133+
expect(nil_var).to receive(:foobar)
134+
expect {
135+
verify nil_var
136+
}.to raise_error(
137+
RSpec::Mocks::MockExpectationError,
138+
%Q|(nil).foobar(*(any args))\n expected: 1 time with any arguments\n received: 0 times with any arguments|
139+
)
140+
end
137141
end
138142

139143
it "includes the class name in the error when mocking a class method that is called an extra time with the wrong args" do

0 commit comments

Comments
 (0)