您可以将action_name方法存根到您想要的任何值:
describe 'when called from "index" action' do before helper.stub!(:action_name).and_return('index') end it 'should do' do helper.do_something.should == 'do' end end describe 'when called from "other" action' do before helper.stub!(:action_name).and_return('other') end it 'should do' do helper.do_something.should == 'dont' end end