-
-
Notifications
You must be signed in to change notification settings - Fork 357
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
Add a warning when the should syntax is used. #339
Conversation
Somehow I missed the decision. I thought since the |
(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) |
It warns precisely once for the entire suite as opposed to on every should. 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 — |
I just worked out where the discussion was. It's on the 3.0 release post 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 — |
We have no plans to remove it. Given that we think the 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). |
It's true. I didn't look closely enough. Sorry @samphippen.
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. |
👍 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\ |
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.
Should we not be using the deprecation handling code for this?
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.
What @JonRowe said: this needs to use the normal deprecation APIs.
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.
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.
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.
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.
Should I close this but leave the branch around, I feel like we should maybe start with a community community poll first. |
@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. |
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. |
@myronmarston go at it :D |
@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 |
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.
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`")
@samphippen - code review feedback left. |
@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 |
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?
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, |
you're totally right. tired git driving leads to bad commit messages. I'll squash everything together once I'm done here. |
Signed-off-by: Sam Phippen <samphippen@googlemail.com>
@myronmarston please rereview when you can. I took most of your notes. Good catches ✨ |
Add a warning when the should syntax is used.
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? |
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. |
One other thing...we forgot a changelog entry. I added one in b34488c |
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 🐱