-
-
Notifications
You must be signed in to change notification settings - Fork 397
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
Should we support expect { }.should blah
when both syntaxes are enabled?
#170
Comments
I'm OK with adding it in the interest of good will toward readers of the tutorial, but I'd prefer to do so with a deprecation warning (less problematic than an exception) and removal in 3.0. |
@myronmarston I missed that you had already commented on deprecating it. I guess we're on the same page. |
My use of the syntax in the tutorial was an error, since fixed. I agree with deprecating it. |
Agreed with deprecating it. "I expect to" seems pretty reasonable, whereas "I expect should" seems a little off somehow, even if grammatically correct. I only noticed this in the first place after I wrote |
👍 |
Excellent. When is this slated for release? |
It's already been released :). I cut a 2.11.3 release last night. Here's the diff: |
Awesome. Thanks. :-) |
@myronmarston Here's a reasonable use case for keeping "expect ... should":
Maybe "expect" isn't the semantically correct method name when assigning the ExpectationTarget to a variable but it definitely reads better on the second line. I suppose it could also be broken up as:
(I try to avoid chaining methods on the end of really long or multi-line blocks for readability if I can avoid it.) |
FWIW, my preferred code formatting for block expectations is: expect {
do_something
}.to raise_error(ArgumentError) |
Why would you want to do that? |
@dchelimsky mainly to break things up for readability, perhaps even moving the block into a helper method. Multi-line blocks with chained methods tacked on can look odd sometimes.
Why prevent it? |
We haven't prevented it. This is ruby. You're welcome to alias What's supported out of the box with RSpec isn't meant to limit what you choose to do with it. |
Well, the
|
If a majority of RSpec users wanted this, I'd definitely be open to it. As far as I know, you're the only one who has ever asked for it. On top of that, I think it would be confusing to leave an un-deprecated |
Fixes rspec/rspec-expectations#170. --- This commit was imported from rspec/rspec-expectations@4808a0b.
Before the new syntax changes in RSpec 2.11, the following undocumented syntax worked but was not intended:
It worked because
expect
simply returned the block passed to it, but first extended the block with a module that addedto
andto_not
as aliases forshould
andshould_not
, respectively. So, the object returned byexpect
was the block andshould
/should_not
worked fine on it.In RSpec 2.11,
expect
now returns an object that wraps the target of an expectation.to
andto_not
trigger the matcher checking against the target object, butshould
andshould_not
are not explicitly defined--soexpect { }.should
attempts to match against theExpectationTarget
object, not against the block that it wraps.I don't think
expect { }.should
was ever intended to be supported (it was a side effect of the implementation) but it appears to have seen a fair bit of use--for example, it was used in @mhartl's rails tutorial, so people copied it (see the discussion here).I don't have a strong feeling either way but wanted to open up this ticket for discussion. If we did add back support, I'd want to make it print a deprecation warning and we'd remove it in 3.0.
Thoughts?
/cc @alindeman @dchelimsky @mhartl
The text was updated successfully, but these errors were encountered: