问题
I would like to be able see the output from the path requested within one of my view specs. Rspec has access to the rendered view, but I would like access to it myself. Does anyone know how to actually view the rendered views?
回答1:
You can use capybara with launchy, and then you can use capybara's save_and_open_page method. Read more details in this blog post.
回答2:
Do you want to see it rendered in a browser or just HTML is fine? You should be able to access HTML in an instance variable called @rendered
.
puts @rendered
# <html>...</html>
回答3:
If, like me, you either don't want to use capybara + launchy, or you can't get it to work, you can just do this:
IO.write('/tmp/test.html', rendered)
... and if you're on a mac:
`open /tmp/test.html`
来源:https://stackoverflow.com/questions/10811568/can-i-as-a-human-view-the-rspec-rendered-views-and-if-so-how