diff --git a/Changelog.md b/Changelog.md index 1beecb663..8a73168f6 100644 --- a/Changelog.md +++ b/Changelog.md @@ -11,6 +11,10 @@ Bug Fixes: * Support keyword argument semantics when constraining argument expectations using `with` on Ruby 3.0+ (Yusuke Endoh, #1394) +Deprecations: + +* Add RSpec 4 deprecation warnings. (Phil Pirozhkov, #????) + ### 3.10.2 / 2021-01-27 [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.10.1...v3.10.2) diff --git a/lib/rspec/mocks/configuration.rb b/lib/rspec/mocks/configuration.rb index 5962215f8..f22d833cf 100644 --- a/lib/rspec/mocks/configuration.rb +++ b/lib/rspec/mocks/configuration.rb @@ -80,6 +80,9 @@ def add_stub_and_should_receive_to(*modules) # def syntax=(*values) syntaxes = values.flatten + RSpec.deprecate('Mocks syntax configuration', + :replacement => 'the default `expect` syntax', + :call_site => nil) if syntaxes.include?(:expect) Syntax.enable_expect else @@ -87,6 +90,9 @@ def syntax=(*values) end if syntaxes.include?(:should) + RSpec.deprecate('`:should` Mocks syntax', + :replacement => 'the default `expect` syntax', + :call_site => nil) Syntax.enable_should else Syntax.disable_should diff --git a/lib/rspec/mocks/example_methods.rb b/lib/rspec/mocks/example_methods.rb index 5531b28bf..26171ef7f 100644 --- a/lib/rspec/mocks/example_methods.rb +++ b/lib/rspec/mocks/example_methods.rb @@ -199,6 +199,9 @@ def class_spy(*args) # early on. # @deprecated Use {RSpec::Mocks::Configuration#allow_message_expectations_on_nil} instead. def allow_message_expectations_on_nil + # require 'pry'; binding.pry + RSpec.deprecate("`allow_message_expectations_on_nil` example method", + :replacement => "`allow_message_expectations_on_nil` configuration option") RSpec::Mocks.space.proxy_for(nil).warn_about_expectations = false end diff --git a/spec/rspec/mocks/configuration_spec.rb b/spec/rspec/mocks/configuration_spec.rb index dd1a00f7a..8d72aec26 100644 --- a/spec/rspec/mocks/configuration_spec.rb +++ b/spec/rspec/mocks/configuration_spec.rb @@ -68,6 +68,11 @@ def sandboxed expect(::RSpec::Mocks::ExampleMethods).not_to receive(:method_added) configure_syntax :expect end + + it 'emits a deprecation warning' do + expect_deprecation_without_call_site(/Mocks syntax configuration/) + configure_syntax :expect + end end context 'when configured to :should' do @@ -89,14 +94,15 @@ def sandboxed expect(configured_syntax).to eq([:should]) end - it "does not warn about the should syntax" do - RSpec.should_not_receive(:deprecate) - Object.new.should_not_receive(:bees) - end - it 'is a no-op when configured a second time' do Syntax.default_should_syntax_host.should_not_receive(:method_added) ::RSpec::Mocks::ExampleMethods.should_not_receive(:method_undefined) + end + + it 'emits two deprecation warnings' do + configure_syntax :expect + expect_deprecation_without_call_site(/`:should` Mocks syntax/) + expect_deprecation_without_call_site(/Mocks syntax configuration/) configure_syntax :should end end @@ -124,6 +130,12 @@ def sandboxed expect(RSpec).not_to receive(:deprecate) expect(Object.new).not_to receive(:bees) end + + it 'emits two deprecation warnings' do + expect_deprecation_without_call_site(/`:should` Mocks syntax/) + expect_deprecation_without_call_site(/Mocks syntax configuration/) + configure_syntax [:should, :expect] + end end end diff --git a/spec/rspec/mocks/example_methods_spec.rb b/spec/rspec/mocks/example_methods_spec.rb index 36bb71623..846a32605 100644 --- a/spec/rspec/mocks/example_methods_spec.rb +++ b/spec/rspec/mocks/example_methods_spec.rb @@ -33,6 +33,17 @@ def test_extend_on_new_object(*to_extend, &block) expect(dbl.foo).to eq(1) end end + + describe '#allow_message_expectations_on_nil' do + it "emits a deprecation warning on use" do + expect_deprecation_with_call_site(__FILE__, __LINE__ + 3, /allow_message_expectations_on_nil/) + RSpec.describe do + it do + allow_message_expectations_on_nil + end + end.run + end + end end end end