Created
November 12, 2013 08:13
-
-
Save swapnilchincholkar/7427314 to your computer and use it in GitHub Desktop.
Using 'render_views' while writing controller specs.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/ app/views/shared/_header.html.haml | |
= render 'users/links' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/ app/views/users/index.html.haml | |
= render 'shared/header' | |
- @users.each |user| | |
= user.name | |
= user.email | |
= render 'shared/footer' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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