jb
jb copied to clipboard
jb renders an empty string in rspec controller test in both Rails4 and Rails5
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)
- git clone the repo
-
bundle install -
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 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