5
Hãy nói rằng tôi có đoạn mã sau vào application_helper.rb:tìm nạp 'ACTION_NAME' hoặc 'điều khiển' từ helper đặc tả
def do_something
if action_name == 'index'
'do'
else
'dont'
end
end
mà sẽ làm một cái gì đó nếu gọi trong action index.
Hỏi: Làm cách nào để viết lại thông số trợ giúp cho điều này trong application_helper_spec.rb để mô phỏng cuộc gọi từ hành động 'chỉ mục'?
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
còn sơ khai! tại helper, damn bỏ lỡ cố gắng mà ra, tôi đã khai! (: action_name) .and_return ('index'), không helper.stub! (: action_name) .and_return ('index') Cảm ơn rsim :) – edthix