Skip to content

Instantly share code, notes, and snippets.

@swapnilchincholkar
Created November 12, 2013 08:13
Show Gist options
  • Save swapnilchincholkar/7427314 to your computer and use it in GitHub Desktop.
Save swapnilchincholkar/7427314 to your computer and use it in GitHub Desktop.
Using 'render_views' while writing controller specs.
/ app/views/shared/_header.html.haml
= render 'users/links'
/ app/views/users/index.html.haml
= render 'shared/header'
- @users.each |user|
= user.name
= user.email
= render 'shared/footer'
# specs/controllers/users_controllers_spec.rb
# Initially while writing controller specs, I was writing them as follows
require 'spec_helper'
describe UsersController do
it "should get users list" do
get :index
assigns[:users].blank?.should == false
end
end
# In above test case, only 'app/views/users/index.html.haml' will be rendered &
# nested partials such as 'shared/header', 'shared/footer' & 'users/links' will not be renderd
# hence if there is any error in any of those nested partials will not be catched by above test case
# in order to render nested partials in a test case we should use 'render_views' as follows
require 'spec_helper'
describe UsersController do
render_views
it "should get users list" do
get :index
assigns[:users].blank?.should == false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment