Ruby on rails 如何Rspec测试只需要文件的方法

Ruby on rails 如何Rspec测试只需要文件的方法,ruby-on-rails,ruby,rspec,Ruby On Rails,Ruby,Rspec,在我的rails引擎的config.rb中,我有这样一个公共方法 def require_this_file require 'this_file' end 所需的文件正在向ApplicationController添加筛选器 module ActionController class Base before_filter :do_something def do_something end end end 在rspec中测试这一点的常规方法是什么 试图

在我的rails引擎的config.rb中,我有这样一个公共方法

def require_this_file
  require 'this_file'
end
所需的文件正在向ApplicationController添加筛选器

module ActionController
  class Base
    before_filter :do_something

    def do_something
    end
  end
end

在rspec中测试这一点的常规方法是什么

试图脱离should语法。这是我的一位同事提出的,LOC为100%。谢谢

let(:some_file) { 'file' } 

it 'adds_file' do
  expect(@configuration).to receive(:require).with(some_file)
  @configuration.require_this_file
end

这似乎是一个不必要的测试。我不确定这是一个在方法中需要模块的好方法。但您可以简单地测试是否存在特定于此模块的方法,如:
controller.should\u response to?(:a\u method)
.mcfinnigan-我也这么认为,因为这就像我在测试Ruby,但我希望将loc覆盖率保持在100%。为什么动态地包括一个文件?只需要从初始值设定项中获取它,然后就可以使用它了。一旦需要,您就不能取消对文件的要求;您不能为每个请求添加该功能,因为许多应用程序正在使用该功能,所以这是动态的。消费应用程序可以在初始值设定项中添加功能。并非所有应用程序都依赖此功能,因此并非所有应用程序都需要此功能