我有一个尺寸不错的rails应用程序,上面有一堆控制器规格。我的所有控制器都是从具有默认错误处理程序的ApiController继承的:
class Api::V1::ApiController < ApplicationController
rescue_from StandardError, with: :default_error_handler我想要的行为是:
通过在全局上使用rspec的方便的bypass_rescue函数,我可以获得#1:
RSpec.configure do |config|
config.before :each do
bypass_rescue
end
end然而,我需要一些方法来说明不应该绕过救援的少数情况。理想的情况是:
describe Api::V1::SomeController do
it 'handles an exception' do
dont_bypass_rescue
get :something_that_throws_an_exception
end
end不过,我似乎找不到一个很好的方法来完成这个任务。有什么建议吗?
发布于 2015-07-16 19:06:33
你可以这样做:
config.before(:each, type: :controller) do |example|
bypass_rescue unless example.metadata[:with_rescue]
end然后:
describe Api::V1::SomeController do
it 'handles an exception', with_rescue: true do
get :something_that_throws_an_exception
end
endhttps://stackoverflow.com/questions/31462221
复制相似问题