RSpec controller testing - blank response.body

后端 未结 4 1421
长发绾君心
长发绾君心 2021-01-30 03:08

I am stuck with a problem when testing my controllers with RSpec - the response.body call always returns an empty string. In browser everything renders correctly, and cucumber f

4条回答
  •  爱一瞬间的悲伤
    2021-01-30 03:17

    By default, RSpec-rails configuration disables rendering of templates for controller specs

    One of the ways to fix this is by making sure to enable the render_views setting in your rails_helper.rb file. In this way, you make it able to work globally in all your tests.

    RSpec.configure do |config|
      config.render_views
    end
    

    Or use render_views declaration an individual group:

    describe User do
      render_views
    end
    

    You can read more about this here.

提交回复
热议问题