Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails RSpec禁用旁路\u救援_Ruby On Rails_Rspec - Fatal编程技术网

Ruby on rails RSpec禁用旁路\u救援

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

我有一个相当大的rails应用程序,带有一系列控制器规格。我的所有控制器都继承自具有默认错误处理程序的
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块访问示例及其元数据。谢谢