RSpec controller testing - blank response.body

后端 未结 4 1454
长发绾君心
长发绾君心 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:14

    By default, rspec-rails hacks into Rails to prevent it from actually rendering view templates. You should only test the behavior of your actions & filters your controller tests, not the outcome of template rendering — that's what view specs are for.

    However, if you wish to make your controller specs render templates as the app normally would, use the render_views directive:

    describe YourController do
      render_views
      ...
    end
    

提交回复
热议问题