Skip to content
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

Merged

Conversation

fables-tales
Copy link
Member

This is for RSpec 3 with a view to letting users know that this syntax will be off by default in 4. I seem to recall that there was some discussion of this, but I couldn't find the exact issue/mailing list post. I'll bake one for rspec-expectations whilst I'm on the plane 🐱

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 44f35a5 on samphippen:warn_about_the_should_syntax into 6ef6f11 on rspec:master.

@alindeman
Copy link
Contributor

Somehow I missed the decision. I thought since the should syntax doesn't have much maintenance cost, we had no plans to deprecate or remove it, except to start enabling it only in generated spec_helper.rb files.

@alindeman
Copy link
Contributor

(If it's not obvious, I'm 👎 this change because this will spew warnings for all but the very newest test suites, and it's not entirely automatable to change the syntax)

@fables-tales
Copy link
Member Author

It warns precisely once for the entire suite as opposed to on every should.
It emits the warning once on the first should and then Not again. Hardly
"spewing warnings".

Sent from my phone please excuse my brevity.

On 4 Jul 2013, at 18:03, Andy Lindeman notifications@github.com wrote:

(If it's not obvious, I'm [image: 👎] this change because this will spew
warnings for all but the very newest test suites, and it's not entirely
automatable to change the syntax)


Reply to this email directly or view it on
GitHubhttps://github.com//pull/339#issuecomment-20484300
.

@fables-tales
Copy link
Member Author

I just worked out where the discussion was. It's on the 3.0 release post
gist. Won't link on case @myronmarston wants to keep it under wraps for
now. @alindeman you should have access to it :).

Sent from my phone please excuse my brevity.

On 4 Jul 2013, at 18:03, Andy Lindeman notifications@github.com wrote:

(If it's not obvious, I'm [image: 👎] this change because this will spew
warnings for all but the very newest test suites, and it's not entirely
automatable to change the syntax)


Reply to this email directly or view it on
GitHubhttps://github.com//pull/339#issuecomment-20484300
.

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling f14c98f on samphippen:warn_about_the_should_syntax into 6ef6f11 on rspec:master.

@myronmarston
Copy link
Member

Somehow I missed the decision. I thought since the should syntax doesn't have much maintenance cost, we had no plans to deprecate or remove it, except to start enabling it only in generated spec_helper.rb files.

We have no plans to remove it. Given that we think the expect syntax is superior, and that we'd like to move in the direction of making rspec do zero monkey patching by default, the plan we had discussed was for should to still be enabled by default in RSpec 3 but to have it issue a "you should explicitly enable this" warning, and then in RSpec 4 it will be disabled by default. That'll help make our preference clear, and help nudge folks towards explicitly configuring the syntax if they want to continue using should.

Anyhow, let's hold off on this for now. I want to get community feedback on it first (based on the RSpec 3 blog post). There are plenty of other rspec 3 things we can work on in the meantime (e.g. removing stuff that's been deprecated for a long time).

@alindeman
Copy link
Contributor

It warns precisely once for the entire suite as opposed to on every should. It emits the warning once on the first should and then Not again. Hardly "spewing warnings".

It's true. I didn't look closely enough. Sorry @samphippen.

We have no plans to remove it. Given that we think the expect syntax is superior, and that we'd like to move in the direction of making rspec do zero monkey patching by default, the plan we had discussed was for should to still be enabled by default in RSpec 3 but to have it issue a "you should explicitly enable this" warning, and then in RSpec 4 it will be disabled by default. That'll help make our preference clear, and help nudge folks towards explicitly configuring the syntax if they want to continue using should.

Ah, OK. Basically I misread the code and misinterpreted the text here. If it's possible to squash the warning by enabling the syntax explicitly, I'm supportive.

Sorry for the knee jerk reaction.

@JonRowe
Copy link
Member

JonRowe commented Jul 5, 2013

👍 but also we need to hold off merging this until we get community feedback

@myronmarston
Copy link
Member

but also we need to hold off merging this until we get community feedback

Also, I have some code review feedback but don't have the time to write it up at the moment...


def warn_about_should
if @should_warn_about_should
Kernel.warn("Should style expectations will be disabled by default in the\
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we not be using the deprecation handling code for this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What @JonRowe said: this needs to use the normal deprecation APIs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I don't like using trailing \ to concatenate multiple lines. I'd prefer to see multiple strings +'d together as that's a more normal way to do it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, as far as this message goes, I'd like something like this:

RSpec.deprecate("Using the old `:should` syntax without explicitly enabling it.",
                :replacement => "the new `:expect` syntax or explicitly enable `:should`")

You should check how that reads with the standard formatting but I think that will read well.

@fables-tales
Copy link
Member Author

Should I close this but leave the branch around, I feel like we should maybe start with a community community poll first.

@myronmarston
Copy link
Member

@samphippen - The feedback to my RSpec 3 blog post (where I mentioned we would emit a warning like this) was universally positive. I consider that to be a sufficient poll.

@myronmarston
Copy link
Member

Thanks for reminding me to review this, though...I'll try to review it this weekend. If you want to rebase before then, feel free.

@fables-tales
Copy link
Member Author

@myronmarston go at it :D

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.09%) when pulling ff83d8a on samphippen:warn_about_the_should_syntax into 80d70b4 on rspec:master.

@fables-tales
Copy link
Member Author

@myronmarston plz review when you can ❤️

opts = {:expected_from => CallerFilter.first_non_rspec_line}
::RSpec::Mocks.expect_message(self, message.to_sym, opts, &block).never
end

def stub(message_or_hash, opts={}, &block)
::RSpec::Mocks.configuration.warn_about_should
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want the warning to be in place for all of the methods added by the should syntax. that includes unstub, stub_chain, as_null_object, null_object?, received_message? and any_instance.

Actually, seeing all these methods makes me think that it would be beneficial if the warning message included the method name in it, so it should pass the method name through to the warn method you've defined. Maybe it could say something like:

RSpec.deprecate("Using :#{method_name} from the old `:should` syntax without explicitly enabling the syntax",
                :replacement => "the new `:expect` syntax or explicitly enable `:should`")

@myronmarston
Copy link
Member

@samphippen - code review feedback left.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.38%) when pulling 23eb526 on samphippen:warn_about_the_should_syntax into 80d70b4 on rspec:master.

@fables-tales
Copy link
Member Author

@myronmarston I took a quick look through your comments, I think I got them all, I added a spec for the default then should case you asked about, you were right it wasn't doing the right thing, but it does now. More review welcomed. (Also got some help from @JonRowe on this one when we bumped into each other today in london)


@warn_about_should = false
end
end
Copy link
Member

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?

@myronmarston
Copy link
Member

Looking good. Very close to being ready to merge :). Left a couple final comments. (Sorry about noticing some of this on the last review...).

Also, Update should warnings for myron's changes. is kinda a weird commit message. I haven't made any changes here.

@fables-tales
Copy link
Member Author

Also, Update should warnings for myron's changes. is kinda a weird commit message. I haven't made any changes here.

you're totally right. tired git driving leads to bad commit messages. I'll squash everything together once I'm done here.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.16%) when pulling 75f9f60 on samphippen:warn_about_the_should_syntax into 3ac6f4e on rspec:master.

Signed-off-by: Sam Phippen <samphippen@googlemail.com>
@fables-tales
Copy link
Member Author

@myronmarston please rereview when you can. I took most of your notes. Good catches ✨

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling cf4d4c9 on samphippen:warn_about_the_should_syntax into 3ac6f4e on rspec:master.

myronmarston added a commit that referenced this pull request Sep 10, 2013
Add a warning when the should syntax is used.
@myronmarston myronmarston merged commit 44b464e into rspec:master Sep 10, 2013
@myronmarston
Copy link
Member

Thanks, @samphippen! I just merged it. I also added some additional doc comments in f96edc3.

Can you take care of adding this kind of thing to rspec-expectations as well?

@myronmarston
Copy link
Member

Also, BTW: while it's nice to not a ton of tiny commits to merge, in the future please don't continually amend your commits as we do the back-and-forth of a code review. It makes it harder to see what changed since I last looked at the PR when you've amended commits or squashed them together.

myronmarston added a commit that referenced this pull request Sep 10, 2013
@myronmarston
Copy link
Member

One other thing...we forgot a changelog entry. I added one in b34488c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants