【发布时间】:2015-01-21 19:19:05
【问题描述】:
我应该如何在我的ApplicationController 上测试这个方法:
def success
render nothing: true, status :ok
end
我尝试使用controller.call(:success),但它返回错误。
有什么想法吗?
附加信息:
我正在使用rspec
【问题讨论】:
标签: ruby-on-rails testing rspec tdd
我应该如何在我的ApplicationController 上测试这个方法:
def success
render nothing: true, status :ok
end
我尝试使用controller.call(:success),但它返回错误。
有什么想法吗?
附加信息:
我正在使用rspec
【问题讨论】:
标签: ruby-on-rails testing rspec tdd
我会这样测试它:
it 'responds with success' do
expect(response).to be_success
end
it 'renders nothing' do
expect(response).to render_template(nil)
end
【讨论】:
success 方法是应该调用的操作,还是您尝试对success 方法进行单元测试?
success 方法只是某种帮助,它没有通往它的路径。控制器(例如UserController)会调用它,所以像这样: user.save ?成功:bad_request