Why is JBuilder not returning a response body in JSON when testing RSPEC

此生再无相见时 提交于 2019-11-30 16:54:14
Kirk

For anyone that is having the same issue. I have figured it out.

You must call render_views within the controller tests you are doing. If you do that, you should then see a response.body with your JSON contained :)

You could find a solution from https://github.com/rails/jbuilder/issues/32

So in rspec/spec_helper.rb

RSpec.configure do |config|
  # https://github.com/rails/jbuilder/issues/32
  config.render_views = true
end

After above option are added, JSON result will show via jbuilder renderer

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