看看这个辅助函数:
def show_welcome_banner?
(controller_name == 'competition' && action_name == 'index') ||
(controller_name == 'submissions' && action_name == 'show')
end
它期望定义controller_name 和action_name 函数。
我尝试在我的 RSpec 匹配器中使用它:
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
但这不会真正起作用。
我如何在助手内部存根函数?也许使用instance_eval?
谢谢!
EDIT,
尝试使用
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
助手已放入规范/helper/page_helper_spec.rb..
你有没有尝试过
stub!(:controller_name).and_return('index')
似乎对我有用:)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)