Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Use RSpec's preferred config.syntax = :expect #124

Closed
croaky opened this Issue · 5 comments

3 participants

@calebthompson

Is there something wrong with the current fluid syntax? The :expect syntax looks cluttered to me personally, as we have to add parens everywhere.

I like it for expect ... to_raise blocks, but that's about the only thing I like.

The README also relegates expect to a short section which explains that expect is really only around to handle edge cases. It seems to me that based on the widespread usage even there 6 months after the addition of expect that the preferred syntax is still should, and that we should only really be considering expect when it is needed.

@joshuaclayton

The expect syntax which takes a block has been in RSpec since 1.x (or earlier, I can't recall exactly when it was added). I've been using the expect syntax for a while now in both my Test-Driven Rails workshop and client projects as I've been able and I don't notice much difference over should in terms of parenthesis, line length, etc. It's probably longer, but regarding "gut feeling", the difference is negligible. What I do like is that it's more explicit in the matchers (e.g. forcing use of eq instead of ==), it's consistent with the expect { } syntax, it works with subclasses of BasicObject (which I'm a huge fan of when writing decorators), and it comes very close to mirroring Jasmine's assertion syntax (expect(user.name()).toEqual 'John Doe').

My initial gut reaction was the same as yours, @calebthompson, but after using it for a few months, the should syntax feels antiquated and kludgy. My two cents, at least.

@croaky
Owner

I created this issue for two reasons at this point:

  • discussion
  • record the part of the RSpec docs I just discovered that enforces using the expect-only style

Style preference:

  • I thought I liked should until I started trying expect.
  • I prefer expect more now.
  • It highlights the verification phase of the Four-Phase Test really well by starting each line with expect, wrapping the outcome in the warm embrace of parentheses.

Other good reasons are what Josh said:

  • Consistency across RSpec specs.
  • Consistency with Jasmine.
  • Avoids weird, confusing errors when testing delegate/proxy objects.
  • Avoids Ruby warning with should ==.
@calebthompson
@croaky
Owner

Closed: 80256d7

@croaky croaky closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.