Can I, as a human, view the RSpec rendered views, and if, so how?

杀马特。学长 韩版系。学妹 提交于 2019-12-23 07:10:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!