-
-
Notifications
You must be signed in to change notification settings - Fork 358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a warning when the should syntax is used. #339
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,6 +85,11 @@ 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) | ||
|
@@ -110,6 +115,68 @@ def sandboxed | |
it 'reports that both syntaxes are enabled' do | ||
expect(configured_syntax).to eq([:should, :expect]) | ||
end | ||
|
||
it "does not warn about the should syntax" do | ||
RSpec.should_not_receive(:deprecate) | ||
Object.new.should_not_receive(:bees) | ||
end | ||
end | ||
|
||
context "by default" do | ||
before do | ||
configure_default_syntax | ||
end | ||
|
||
let(:expected_arguments) { | ||
[ | ||
/Using.*without explicitly enabling/, | ||
{:replacement=>"the new `:expect` syntax or explicitly enable `:should`"} | ||
] | ||
} | ||
|
||
it "it warns about should once, regardless of how many times it is called" do | ||
expect(RSpec).to receive(:deprecate).with(*expected_arguments) | ||
o = Object.new | ||
o2 = Object.new | ||
o.should_receive(:bees) | ||
o2.should_receive(:bees) | ||
|
||
o.bees | ||
o2.bees | ||
end | ||
|
||
it "warns about should not once, regardless of how many times it is called" do | ||
expect(RSpec).to receive(:deprecate).with(*expected_arguments) | ||
o = Object.new | ||
o2 = Object.new | ||
o.should_not_receive(:bees) | ||
o2.should_not_receive(:bees) | ||
end | ||
|
||
it "warns about stubbing once, regardless of how many times it is called" do | ||
expect(RSpec).to receive(:deprecate).with(*expected_arguments) | ||
o = Object.new | ||
o2 = Object.new | ||
|
||
o.stub(:faces) | ||
o2.stub(:faces) | ||
end | ||
|
||
it "doesn't warn about stubbing after a reset and setting should" do | ||
expect(RSpec).not_to receive(:deprecate) | ||
RSpec::Mocks.configuration.reset_syntaxes_to_default | ||
RSpec::Mocks.configuration.syntax = :should | ||
o = Object.new | ||
o2 = Object.new | ||
o.stub(:faces) | ||
o2.stub(:faces) | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given that we've had some trouble with this, I'd like a spec that asserts on the correct call site being included in the deprecation warning. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you mean add the call site to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just had another look at this, it'd change the expect to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
No, I would like an additional spec added specifically for this. Having a spec for it calls it out as important (which it is).
No, setting a mock expectation on
To really have confidence that the right line is being printed, we need a spec that actually asserts on the file and line number (typically with it "includes the call site in the deprecation warning" do
obj = Object.new
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1)
obj.stub(:faces)
end Does that make sense? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think so, I'll have an experiment and work it out. |
||
|
||
it "includes the call site in the deprecation warning" do | ||
obj = Object.new | ||
expect_deprecation_with_call_site(__FILE__, __LINE__ + 1) | ||
obj.stub(:faces) | ||
end | ||
end | ||
end | ||
|
||
|
@@ -122,6 +189,10 @@ def configure_syntax(syntax) | |
def configured_syntax | ||
RSpec::Mocks.configuration.syntax | ||
end | ||
|
||
def configure_default_syntax | ||
RSpec::Mocks.configuration.reset_syntaxes_to_default | ||
end | ||
end | ||
end | ||
|
||
|
@@ -142,6 +213,14 @@ def configured_syntax | |
end | ||
end | ||
end | ||
|
||
def configure_default_syntax | ||
RSpec.configure do |rspec| | ||
rspec.mock_with :rspec do |c| | ||
c.reset_syntaxes_to_default | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You know, I'm thinking that this method doesn't really belong here:
Configuration
is for public configuration methods, not for private RSpec implementation details. I'd consider this to be a private method, not intended to be called by end users. Also, instructing a config option to emit a warning is a bit odd. (Why should the config object have that responsibility?)Maybe it belongs on the
Syntax
module instead? Thoughts?