【发布时间】:2018-05-22 11:24:22
【问题描述】:
我正在尝试将活动链接条件的 rspec 放在 application_helper.rb 中。 Application_helper.rb 代码:
def active_class(link_path)
current_page?(link_path) ? 'active' : ''
end
我试图为这个 active_class 方法放置 rspec,为此我使用了 stub。这是我用于 active_class 方法的 rspec 代码。 Application_helper_spec.rb 代码:
describe 'when called from "index" action' do
before
helper.stub!(:action_name).and_return('index')
end
it 'should do' do
helper.active_class.should == 'active'
end
describe 'when called from "other" action' do
before
helper.stub!(:action_name).and_return('other')
end
it 'should do' do
helper.active_class.should == 'empty'
end
我收到的错误是未定义的方法存根。我该如何克服这个问题?
【问题讨论】:
标签: activerecord rspec specifications