In my spec_helper.rb file I have specifically set it to config.render_views but the response.body I get back is still empty. Here is my basic spec
describe "#index" do
it "should list all rooms" do
get 'index'
stub(Person).all
end
it "responds with 200 response code" do
response.should be_ok
end
it "renders the index template" do
pp response.body
response.should render_template("people/index")
end
end
Is there anything else that could have shorted this behavior? It's fine when I go through the browser. I am on Rspec 2.5.0
Have you tried having render_views
in your controller spec file? That works for me.
Another thing I noticed is that you only access the index page once in your test cases - the first one to be precise. The rest will return empty html content because there is no response.
This is how I will implement it. But if you already have config.render_views
in the *spec_helper.rb* file and that works, you can do without the render_views
in the controller spec.
describe MyController
render_views
before :each do
get :index
end
describe "#index" do
it "should list all rooms" do
stub(Person).all
end
it "responds with 200 response code" do
response.should be_ok
end
it "renders the index template" do
pp response.body
response.should render_template("people/index")
end
end
end
EDIT:
The subtle change here is the before
blobk in which I call get :index
for every it
block.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With