Take a look at this helper function:
def show_welcome_banner?
(controller_name == 'competition' && action_name == 'index') ||
(controller_name == 'submissions' && action_name == 'show')
end
He expects the controller_name and action_name functions to be defined.
I tried using this in my RSpec mapping:
describe PageHelper do
it "should know when the welcome banner is to be shown" do
helper.stub!(:controller_name).and_return('index')
show_welcome_banner?.should == false
end
end
But that will not work.
How could I drown the INSIDE functions for an assistant? Perhaps using instance_eval? Thank!
EDIT , tried to use
controller.stub!(:controller_name).and_return('index')
but got
1) PageHelper should know when the welcome banner is to be shown
Failure/Error: show_welcome_banner?.should == false
NameError:
undefined local variable or method `controller_name' for #<RSpec::Core::ExampleGroup::Nested_1:0x1059a10b8>
# ./app/helpers/page_helper.rb:16:in `show_welcome_banner?'
# ./spec/helpers/page_helper_spec.rb:7
The helper is placed in spec / helper / page_helper_spec.rb ..
source
share