Skip to content


expect ... to (vs lambda ... should) needs documentation #78

nbt opened this Issue · 4 comments

2 participants


I pored over the online docs and never found expect ... to to be documented. Plenty of examples, but nothing that suggested it was preferable over lambda ... should. Even searching for 'expect' in the search box turned up nothing. I admit that I don't understand the structure of rpec well enough to know if this belongs in core documentation or expectations, but it ought to be somewhere.

RSpec member

I'm not sure that I would say expect ... to is preferred over lambda ... should; some people prefer lambda ... should simply because it's more immediately understandable so someone who knows ruby (and knows lambdas) well but is unfamiliar with some of rspec's syntactic sugar like expect ... to. expect ... to is simply some suger provided by rspec that you can use or not use as you like.

The relish docs use expect ... to in a few places: Built in matcher, expect change, raise error matcher, throw symbol matcher.

What specific documentation would you like to see added? Pull requests for improved docs happily accepted :).


Hi Myron: I'm not claiming that expect {...}.to is preferable to lambda {...}.should -- I'm just saying that it doesn't appear to be actually documented except as an example for other things. Case in point: I didn't know expect was merely syntactic sugar for lambda. (Does this mean you can write the grammatically improbable expect {...}.should?)

Perhaps there should be a section on all the syntactic sugar that rspec offers. I'm not sufficiently comfortable with the structure of the documentation (let alone cucumber and relish) to construct a pull request. But if all the syntactic equivalents are in one place, and if you point me at it, I could take a stab at something.

@nbt nbt closed this
@nbt nbt reopened this

Crottles. Wrong button.

RSpec member

More documentation has been added in 5dd161e

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.