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

Commit a74c7a7

Browse files
committed
Add RSpec 4 deprecations
1 parent 97c972b commit a74c7a7

File tree

5 files changed

+41
-5
lines changed

5 files changed

+41
-5
lines changed

Changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ Bug Fixes:
1111
* Support keyword argument semantics when constraining argument expectations using
1212
`with` on Ruby 3.0+ (Yusuke Endoh, #1394)
1313

14+
Deprecations:
15+
16+
* Add RSpec 4 deprecation warnings. (Phil Pirozhkov, #????)
17+
1418
### 3.10.2 / 2021-01-27
1519
[Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.10.1...v3.10.2)
1620

lib/rspec/mocks/configuration.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,19 @@ def add_stub_and_should_receive_to(*modules)
8080
#
8181
def syntax=(*values)
8282
syntaxes = values.flatten
83+
RSpec.deprecate('Mocks syntax configuration',
84+
:replacement => 'the default `expect` syntax',
85+
:call_site => nil)
8386
if syntaxes.include?(:expect)
8487
Syntax.enable_expect
8588
else
8689
Syntax.disable_expect
8790
end
8891

8992
if syntaxes.include?(:should)
93+
RSpec.deprecate('`:should` Mocks syntax',
94+
:replacement => 'the default `expect` syntax',
95+
:call_site => nil)
9096
Syntax.enable_should
9197
else
9298
Syntax.disable_should

lib/rspec/mocks/example_methods.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ def class_spy(*args)
199199
# early on.
200200
# @deprecated Use {RSpec::Mocks::Configuration#allow_message_expectations_on_nil} instead.
201201
def allow_message_expectations_on_nil
202+
# require 'pry'; binding.pry
203+
RSpec.deprecate("`allow_message_expectations_on_nil` example method",
204+
:replacement => "`allow_message_expectations_on_nil` configuration option")
202205
RSpec::Mocks.space.proxy_for(nil).warn_about_expectations = false
203206
end
204207

spec/rspec/mocks/configuration_spec.rb

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ def sandboxed
6868
expect(::RSpec::Mocks::ExampleMethods).not_to receive(:method_added)
6969
configure_syntax :expect
7070
end
71+
72+
it 'emits a deprecation warning' do
73+
expect_deprecation_without_call_site(/Mocks syntax configuration/)
74+
configure_syntax :expect
75+
end
7176
end
7277

7378
context 'when configured to :should' do
@@ -89,14 +94,15 @@ def sandboxed
8994
expect(configured_syntax).to eq([:should])
9095
end
9196

92-
it "does not warn about the should syntax" do
93-
RSpec.should_not_receive(:deprecate)
94-
Object.new.should_not_receive(:bees)
95-
end
96-
9797
it 'is a no-op when configured a second time' do
9898
Syntax.default_should_syntax_host.should_not_receive(:method_added)
9999
::RSpec::Mocks::ExampleMethods.should_not_receive(:method_undefined)
100+
end
101+
102+
it 'emits two deprecation warnings' do
103+
configure_syntax :expect
104+
expect_deprecation_without_call_site(/`:should` Mocks syntax/)
105+
expect_deprecation_without_call_site(/Mocks syntax configuration/)
100106
configure_syntax :should
101107
end
102108
end
@@ -124,6 +130,12 @@ def sandboxed
124130
expect(RSpec).not_to receive(:deprecate)
125131
expect(Object.new).not_to receive(:bees)
126132
end
133+
134+
it 'emits two deprecation warnings' do
135+
expect_deprecation_without_call_site(/`:should` Mocks syntax/)
136+
expect_deprecation_without_call_site(/Mocks syntax configuration/)
137+
configure_syntax [:should, :expect]
138+
end
127139
end
128140
end
129141

spec/rspec/mocks/example_methods_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ def test_extend_on_new_object(*to_extend, &block)
3333
expect(dbl.foo).to eq(1)
3434
end
3535
end
36+
37+
describe '#allow_message_expectations_on_nil' do
38+
it "emits a deprecation warning on use" do
39+
expect_deprecation_with_call_site(__FILE__, __LINE__ + 3, /allow_message_expectations_on_nil/)
40+
RSpec.describe do
41+
it do
42+
allow_message_expectations_on_nil
43+
end
44+
end.run
45+
end
46+
end
3647
end
3748
end
3849
end

0 commit comments

Comments
 (0)