-
-
Save jfernandez-pwnhealth/01656e94aa1c28c12a000be6bd8ae451 to your computer and use it in GitHub Desktop.
Stubbing controller_name & action_name in Rails 3 with rspec 2.5
This file contains hidden or 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
| module ApplicationHelper | |
| def foo | |
| controller_name == 'widgets' && action_name == 'index' | |
| end | |
| end |
This file contains hidden or 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
| require 'spec_helper' | |
| describe ApplicationHelper do | |
| describe '#foo' do | |
| context "on Widgets#index" do | |
| it "returns true" do | |
| controller.stub(:controller_name).and_return('widgets') | |
| controller.stub(:action_name).and_return('index') | |
| helper.foo.should be_true | |
| end | |
| end | |
| context "not on Widgets#index" do | |
| it "returns false" do | |
| controller.stub(:controller_name).and_return('widgets') | |
| controller.stub(:action_name).and_return('show') | |
| helper.foo.should be_false | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment