【发布时间】:2008-11-11 10:38:34
【问题描述】:
假设我在 application_helper.rb 中有以下代码:
def do_something
if action_name == 'index'
'do'
else
'dont'
end
end
如果在索引操作中调用它会做一些事情。
问:如何在 application_helper_spec.rb 中为此重写帮助规范以模拟来自“索引”操作的调用?
describe 'when called from "index" action' do
it 'should do' do
helper.do_something.should == 'do' # will always return 'dont'
end
end
describe 'when called from "other" action' do
it 'should do' do
helper.do_something.should == 'dont'
end
end
【问题讨论】:
标签: ruby-on-rails ruby rspec bdd