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

前端 未结 2 610
有刺的猬
有刺的猬 2021-01-03 19:20

When testing a JSON response from an RSPEC controller test using DHH\'s JBuilder, my response.body is always \"{}\". It works fine in development/production modes AND when

2条回答
  •  庸人自扰
    2021-01-03 19:39

    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

提交回复
热议问题