Using Capybara matchers in a controller spec with ActionController::TestResponse
I'm calling render_views
in my rspec controller spec so I can test the content of the response directly rather than using separate view specs.
Sure enough the view is rendered and returned in response.body
.
The problem is how to actually parse the content of the page in an expressive way. I'm trying to use Capybara matchers like has_content
, has_field
etc. which work fine in the request specs, but they don't work with Actio开发者_StackOverflow社区nController::TestResponse
or with the string returned from .body
.
Where's the rspec API for parsing the view?
What's the point of render_views
if I can't inspect them?
If you want to spec rendered views I suggest to do that in a request/acceptance/feature spec, not controller. Controller specs should be treated more like unit specs for controllers. render_views can be used if you want to make sure that a view renders without any problems, but you shouldn't go any deeper in terms of speccing that view.
精彩评论