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
Use is_expected.to
instead of should
#215
Conversation
Even though we've switched to the `expect` syntax, we've still been using `should` for one-liners with an implicit subject. RSpec 3 introduced `is_expected.to` as an alternative. Myron Marston explains: > Some users have expressed confusion about how this should relates to the > expect syntax and if you can continue using it. It will continue to be > available in RSpec 3 (again, regardless of your syntax configuration), but > we’ve also added an alternate API that is a bit more consistent with the > expect syntax From: [New API for one-liners](http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new_api_for_oneliners_)
This feels a little bit like change for the sake of change. I don't see any benefits beyond the fact that this has the word |
Yeah, it's also a lot longer which I'm against. |
@gabebw I think it's not so much because it has the word |
I haven't been using
that I've seen on a few projects. |
I don't mind this change, though it would take getting used to. Personally, |
I actually thought that |
@mcmire The following are not the same: # monkey-patches Object, has been deprecated
# our guides state that we should use expect(subject).to here
it { subject.should be_true }
# doesn't monkey-patch Object, still available in RSpec3
# RSpec3 introduced is_expected.to as an alternative to this
it { should be_true } |
|
Since |
@JoelQ Gotcha, yeah, I see your point. |
@JoelQ still interested in this? Any further opinions here? |
I personally prefer |
I prefer |
I prefer |
I've no opinion, I enjoy the expect-ish consistency and don't personally care about the additional characters per line, but I'm also not so convicted that I'd really argue if everyone wants to continue with |
As best I can tell, the only reason this method was added was to keep people from continually asking what the one-line equivalent to Should is shorter and reads better to me, but I don't feel super strongly about it. |
So leaving aside personal preference for a moment, what about people who are new to RSpec (i.e. apprentices), do we feel that |
I liked |
Good point, @mcmire. I don't think we should let "what's most newbie/community friendly" drive all of our guides but in the face of no real functional arguments for one or the other, I think that's an okay default. How do we answer this question? |
A random person's 2 cents: I don't think it's necessary, and any "user-friendliness" is negated by the increased complexity of yet one more "no-no" to remember. Changing the RSpec config to expect the |
@robwise Currently the guides explicitly say to use Are you suggesting that we do neither and have no guideline one what to use for one liners since both |
I'm slightly leaning towards |
@JoelQ Well, completely eliminating the rule is actually an interesting idea, considering both are syntaxes are currently valid. Obviously, the invalid But, no, my original suggestion was to keep the guide as-is, thereby allowing |
Based on the documentation of RSpec, it feels like
|
More insight on that in this comment thread. |
@JoelQ any updates here? |
Previously one-liners could be written in RSpec like: it { should validate_presence_of(:name) } In RSpec 3, the `should` syntax was removed because it monkey-patched `Object`. The one-liner syntax shown above was kept because its `should` did not monkey-patch `Object`. To avoid confusion, RSpec 3 added an `expect`-style way of writing one-liners: it { is_expected.to validate_presence_of(:name) } According to Myron Marston: > Some users have expressed confusion about how this should relates to the > expect syntax and if you can continue using it. It will continue to be > available in RSpec 3 (again, regardless of your syntax configuration), but > we’ve also added an alternate API that is a bit more consistent with the > expect syntax From: [New API for one-liners](http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new_api_for_oneliners_) A proposal was made to switch to using the new `is_expected.to` syntaxin [this pull request](#215). However, responses were mixed. Given the lack of consensus one way or the other, let's remove the guideline entirely and let each project decide which syntax to use.
Previously one-liners could be written in RSpec like: it { should validate_presence_of(:name) } In RSpec 3, the `should` syntax was removed because it monkey-patched `Object`. The one-liner syntax shown above was kept because its `should` did not monkey-patch `Object`. To avoid confusion, RSpec 3 added an `expect`-style way of writing one-liners: it { is_expected.to validate_presence_of(:name) } According to Myron Marston: > Some users have expressed confusion about how this should relates to the > expect syntax and if you can continue using it. It will continue to be > available in RSpec 3 (again, regardless of your syntax configuration), but > we’ve also added an alternate API that is a bit more consistent with the > expect syntax From: [New API for one-liners](http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new_api_for_oneliners_) A proposal was made to switch to using the new `is_expected.to` syntaxin [this pull request](#215). However, responses were mixed. Given the lack of consensus one way or the other, let's remove the guideline entirely and let each project decide which syntax to use.
Previously one-liners could be written in RSpec like: it { should validate_presence_of(:name) } In RSpec 3, the `should` syntax was removed because it monkey-patched `Object`. The one-liner syntax shown above was kept because its `should` did not monkey-patch `Object`. To avoid confusion, RSpec 3 added an `expect`-style way of writing one-liners: it { is_expected.to validate_presence_of(:name) } According to Myron Marston: > Some users have expressed confusion about how this should relates to the > expect syntax and if you can continue using it. It will continue to be > available in RSpec 3 (again, regardless of your syntax configuration), but > we’ve also added an alternate API that is a bit more consistent with the > expect syntax From: [New API for one-liners](http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new_api_for_oneliners_) A proposal was made to switch to using the new `is_expected.to` syntaxin [this pull request](#215). However, responses were mixed. Given the lack of consensus one way or the other, let's remove the guideline entirely and let each project decide which syntax to use.
Given the lack of consensus here, I'm going to close this PR. Feel free to reopen and continue the discussion. I'm also opening #234 to not have a guideline at all on RSpec one-liners. |
Previously one-liners could be written in RSpec like: it { should validate_presence_of(:name) } In RSpec 3, the `should` syntax was removed because it monkey-patched `Object`. The one-liner syntax shown above was kept because its `should` did not monkey-patch `Object`. To avoid confusion, RSpec 3 added an `expect`-style way of writing one-liners: it { is_expected.to validate_presence_of(:name) } According to Myron Marston: > Some users have expressed confusion about how this should relates to the > expect syntax and if you can continue using it. It will continue to be > available in RSpec 3 (again, regardless of your syntax configuration), but > we’ve also added an alternate API that is a bit more consistent with the > expect syntax From: [New API for one-liners](http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new_api_for_oneliners_) A proposal was made to switch to using the new `is_expected.to` syntaxin [this pull request](#215). However, responses were mixed. Given the lack of consensus one way or the other, let's remove the guideline entirely and let each project decide which syntax to use.
Previously one-liners could be written in RSpec like: it { should validate_presence_of(:name) } In RSpec 3, the `should` syntax was removed because it monkey-patched `Object`. The one-liner syntax shown above was kept because its `should` did not monkey-patch `Object`. To avoid confusion, RSpec 3 added an `expect`-style way of writing one-liners: it { is_expected.to validate_presence_of(:name) } According to Myron Marston: > Some users have expressed confusion about how this should relates to the > expect syntax and if you can continue using it. It will continue to be > available in RSpec 3 (again, regardless of your syntax configuration), but > we’ve also added an alternate API that is a bit more consistent with the > expect syntax From: [New API for one-liners](http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new_api_for_oneliners_) A proposal was made to switch to using the new `is_expected.to` syntaxin [this pull request](#215). However, responses were mixed. Given the lack of consensus one way or the other, let's remove the guideline entirely and let each project decide which syntax to use.
Do we want to revisit this? I'm finding more and more that people who leave issues on shoulda-matchers tend to prefer the |
We don't promote either form. The guideline was removed in #234. I don't see a problem with converting the shoulda-matchers README to |
Oh yeah! It sure was. Cool, thanks. |
Even though we've switched to the
expect
syntax, we've still been usingshould
for one-liners with an implicit subject. RSpec 3 introducedis_expected.to
as an alternative. Myron Marston explains:From: New API for
one-liners