Skip to content

Commit

Permalink
Add RSpec 4 deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
pirj committed Mar 15, 2021
1 parent 97c972b commit a74c7a7
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 6 additions & 0 deletions lib/rspec/mocks/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,19 @@ 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
Syntax.disable_expect
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
Expand Down
3 changes: 3 additions & 0 deletions lib/rspec/mocks/example_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 17 additions & 5 deletions spec/rspec/mocks/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down
11 changes: 11 additions & 0 deletions spec/rspec/mocks/example_methods_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a74c7a7

Please sign in to comment.