Ruby on rails RSpec禁用旁路\u救援
我有一个相当大的rails应用程序,带有一系列控制器规格。我的所有控制器都继承自具有默认错误处理程序的Ruby on rails RSpec禁用旁路\u救援,ruby-on-rails,rspec,Ruby On Rails,Rspec,我有一个相当大的rails应用程序,带有一系列控制器规格。我的所有控制器都继承自具有默认错误处理程序的ApiController: class Api::V1::ApiController < ApplicationController rescue_from StandardError, with: :default_error_handler 然而,我需要一些方法来指定不应绕过救援的少数情况。理想情况下,类似于: describe Api::V1::SomeController
ApiController
:
class Api::V1::ApiController < ApplicationController
rescue_from StandardError, with: :default_error_handler
然而,我需要一些方法来指定不应绕过救援的少数情况。理想情况下,类似于:
describe Api::V1::SomeController do
it 'handles an exception' do
dont_bypass_rescue
get :something_that_throws_an_exception
end
end
config.before(:each, type: :controller) do |example|
bypass_rescue unless example.metadata[:with_rescue]
end
不过,我似乎找不到一个好办法来实现这一点。有什么建议吗?您可以做如下操作:
describe Api::V1::SomeController do
it 'handles an exception' do
dont_bypass_rescue
get :something_that_throws_an_exception
end
end
config.before(:each, type: :controller) do |example|
bypass_rescue unless example.metadata[:with_rescue]
end
然后:
嗯,这比我想象的要简单得多。不知道可以从before块访问示例及其元数据。谢谢