Open skalee opened 8 years ago
I've never needed to use the same matchers between the tests, so I haven't run into this. If this is an issue for you I'd be happy to review a PR that fixes this problem.
This is an issue for me, for instance, I can't re-use Airborne matchers to "deeply" match JSON types and values. Adding the let(:response)
from @skalee works, but I'd rather not have to litter that around my specs.
Agreed, it would be "nice to have" to use rspec matchers like
expect(response).to be_success
expect(response).to be_unprocessable
expect(response).to be_forbidden
Checking equality on status 200 is obvious. But I always forget when I see a 403 or 422 that one of those is un-processable and one is forbidden. And then which is which. :)
Yeah, I know it's listed in gotchas already. Though it's a real inconvenience: it makes reusing RSpec matchers difficult.
There are some useful stock RSpec::Rails matchers which rely on
response
object presence. For example:Furthermore, many developers tend to write they very own matchers to be used in specs. Now they need to prepare yet another set of matchers for acceptance specs.
What's the reason for such behavior? I could implement the fake response object if there are no objections. If there are reasons to keep things as they are now, then I'd like to share with my workaround. Perhaps it's worth adding to the README:
The
response
object mimics Capybara response so it doesn't depend on Rails'ActionDispatch::Response
.