我有一个ReportsController
,嵌套在ProjectsController
,使用#show
方法:
def show
# Some stuff
do_something(@report)
end
路线:
resources :projects do
resources :reports
end
我需要测试调用do_something
方法:
it 'calls do_something' do
expect(controller).to receive(:do_something)
project = create :project
report = create :report, project: project
get :show, params: {project_id: project.id, id: report.id}
end
我将binding.pry
置于#show
操作中,但这不会被调用。那么我的规格出了什么问题?
答案 0 :(得分:2)
问题是我没有登录:
before do
@user = create :user, :admin
sign_in_as @user
end