5
Załóżmy, że mam następujący kod w application_helper.rb:pobierania „ACTION_NAME” lub „administrator danych” od pomocnika specyfikacji
def do_something
if action_name == 'index'
'do'
else
'dont'
end
end
który zrobi coś, jeśli nazywa się wewnątrz akcji index.
Q: Jak mogę przepisać spec pomocnika za to w application_helper_spec.rb symulować połączenia z „index” działania?
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
niedopałek! na pomocnika, cholernie nieodebrane to wypróbowałem, zrobiłem stub! (: action_name) .and_return ('index'), nie helper.stub! (: action_name) .and_return ('index') Dzięki rsim :) – edthix