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

Expect vs Should syntax #83

Closed
maurogeorge opened this Issue Aug 7, 2013 · 12 comments

Comments

Projects
None yet
9 participants
@maurogeorge

maurogeorge commented Aug 7, 2013

In the following text Myron says to use this on new projects.

You guys think this is a good section to better specs? I personaly have use this on new projects with configuration to use only new syntax.

@gabetax

This comment has been minimized.

Show comment
Hide comment
@gabetax

gabetax Aug 8, 2013

+1

expect syntax is mature. Given that should is deprecated in 3, and removed from 4, I would recommend switching all the documentation to use expect by default, and then adding an "expect vs should" section. It's a waste for brand new rspec users to learn a syntax that's going away when the new syntax is available today.

gabetax commented Aug 8, 2013

+1

expect syntax is mature. Given that should is deprecated in 3, and removed from 4, I would recommend switching all the documentation to use expect by default, and then adding an "expect vs should" section. It's a waste for brand new rspec users to learn a syntax that's going away when the new syntax is available today.

@jandudulski

This comment has been minimized.

Show comment
Hide comment
@jandudulski

jandudulski commented Aug 8, 2013

👍

@jguice

This comment has been minimized.

Show comment
Hide comment
@jguice

jguice Oct 1, 2013

If expect is to be used instead of should, can the other examples be updated to reflect that? :)

e.g. the "Use contexts" guideline...

jguice commented Oct 1, 2013

If expect is to be used instead of should, can the other examples be updated to reflect that? :)

e.g. the "Use contexts" guideline...

@maurogeorge

This comment has been minimized.

Show comment
Hide comment
@maurogeorge

maurogeorge Oct 2, 2013

@jguice all examples are now using the expect syntax.

The context guideline, and all one-liner syntax(with implicit subject) still use the should syntax. More info about it here on a answer of Stack Overflow by Myron

maurogeorge commented Oct 2, 2013

@jguice all examples are now using the expect syntax.

The context guideline, and all one-liner syntax(with implicit subject) still use the should syntax. More info about it here on a answer of Stack Overflow by Myron

@jguice

This comment has been minimized.

Show comment
Hide comment
@jguice

jguice Oct 2, 2013

Ah! I think what is confusing in the contexts example is that, when going from BAD to GOOD, not only is the context added but the "it" is changed to a one-liner which also makes the "expect" become a "should". It seems like the only changes from a BAD example to a GOOD example should be directly related to the particular guideline being illustrated for maximum clarity ;)

Also adding a note to the Expect vs. Should guideline about the one-line format still (acceptably) using should might be helpful.

I found a minor typo on Expect vs. Should too: "Configure the Rspec to only accept the new syntax on new projects, to avoid have the 2 syntax all over the place." (the "have" should be a "having").

Let me know if I should create a pull request or new issue for these :)

jguice commented Oct 2, 2013

Ah! I think what is confusing in the contexts example is that, when going from BAD to GOOD, not only is the context added but the "it" is changed to a one-liner which also makes the "expect" become a "should". It seems like the only changes from a BAD example to a GOOD example should be directly related to the particular guideline being illustrated for maximum clarity ;)

Also adding a note to the Expect vs. Should guideline about the one-line format still (acceptably) using should might be helpful.

I found a minor typo on Expect vs. Should too: "Configure the Rspec to only accept the new syntax on new projects, to avoid have the 2 syntax all over the place." (the "have" should be a "having").

Let me know if I should create a pull request or new issue for these :)

@maurogeorge

This comment has been minimized.

Show comment
Hide comment
@maurogeorge

maurogeorge Oct 3, 2013

@jguice I like the idea of have a note on Expect vs. Should section. Something like:

In one line expects or with implicit subject we still use the should syntax, since is no change here on new syntax

And add the link to Myron answer on Stack Overflow.

maurogeorge commented Oct 3, 2013

@jguice I like the idea of have a note on Expect vs. Should section. Something like:

In one line expects or with implicit subject we still use the should syntax, since is no change here on new syntax

And add the link to Myron answer on Stack Overflow.

@andreareginato

This comment has been minimized.

Show comment
Hide comment
@andreareginato

andreareginato Oct 3, 2013

Collaborator

If you find the time guys, would be perfect to add this little note.

Collaborator

andreareginato commented Oct 3, 2013

If you find the time guys, would be perfect to add this little note.

@yujinakayama

This comment has been minimized.

Show comment
Hide comment
@yujinakayama

yujinakayama Oct 6, 2013

By the way, for people who are willing to maintain existing should syntax specs, I'd like to recommend converting them to expect syntax by using Transpec.

yujinakayama commented Oct 6, 2013

By the way, for people who are willing to maintain existing should syntax specs, I'd like to recommend converting them to expect syntax by using Transpec.

@maurogeorge

This comment has been minimized.

Show comment
Hide comment
@maurogeorge

maurogeorge Oct 6, 2013

Done in here #91

maurogeorge commented Oct 6, 2013

Done in here #91

@voltechs

This comment has been minimized.

Show comment
Hide comment
@voltechs

voltechs Apr 21, 2014

typo.

s/since is no change/since there is no change/

voltechs commented Apr 21, 2014

typo.

s/since is no change/since there is no change/

@mltsy

This comment has been minimized.

Show comment
Hide comment
@mltsy

mltsy Nov 16, 2015

I agree that expect is the correct syntax to use for block expectations, but for one-liners, it's actually still perfectly okay to use should, as it's a method from a different class entirely (it's not the same should) and it sounds and looks much better than it { is_expected.to ... }. The only reason the other should was removed was because it required monkey-patching Object. That is not the case with this should, and it has not been removed as of RSpec 3.4, and doesn't look like it will be.

I think both syntaxes for one-liners should be on the "GOOD" list.

mltsy commented Nov 16, 2015

I agree that expect is the correct syntax to use for block expectations, but for one-liners, it's actually still perfectly okay to use should, as it's a method from a different class entirely (it's not the same should) and it sounds and looks much better than it { is_expected.to ... }. The only reason the other should was removed was because it required monkey-patching Object. That is not the case with this should, and it has not been removed as of RSpec 3.4, and doesn't look like it will be.

I think both syntaxes for one-liners should be on the "GOOD" list.

@Argus9

This comment has been minimized.

Show comment
Hide comment
@Argus9

Argus9 Oct 6, 2017

+1 at @mltsy's point. Are we crossing wires here? I feel like should reads a lot better than is_expected.to in one-liner cases.

Argus9 commented Oct 6, 2017

+1 at @mltsy's point. Are we crossing wires here? I feel like should reads a lot better than is_expected.to in one-liner cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment