jb icon indicating copy to clipboard operation
jb copied to clipboard

jb renders an empty string in rspec controller test in both Rails4 and Rails5

Open gfx opened this issue 8 years ago • 1 comments

It sometimes renders an empty string with status 200, or sometimes just raises 404. The app below reproduces the former, though.

The demo is based on Rails5 but I have found this problem on my Rails4 app.

How to reproduce it

https://github.com/gfx/test_jb (Rails5)

  1. git clone the repo
  2. bundle install
  3. bundle exec rspec

will shows:

$ bundle exec rspec
F

Failures:

  1) FoosController#index should eq "[]"
     Failure/Error: expect(response.body).to eq("[]")

       expected: "[]"
            got: ""

       (compared using ==)
     # ./spec/controllers/foos_controller_spec.rb:8:in `block (3 levels) in <top (required)>'

Finished in 0.06748 seconds (files took 4.92 seconds to load)
1 example, 1 failure

Failed examples:

rspec ./spec/controllers/foos_controller_spec.rb:5 # FoosController#index should eq "[]"

curl http://localhost:3000/foos.json with rails server does return [] as expected.

gfx avatar Mar 14 '17 03:03 gfx

@gfx hello Please check my comment in #18. Try to set rspec render_views setting to true:

RSpec.configure do |config|
  config.render_views = true
end

dks17 avatar Mar 23 '18 11:03 dks17