[英]How to tell Rails to unload a controller (in Rspec test)
在控制器测试中,我想检查是否按预期定义了新的文物特征。 为了测试它,我正在做类似的事情:
describe 'newrelic_ignore' do
let(:load_class) do
load Rails.root.join("app/controllers/foo_controller.rb")
end
before do
Project::Application.send(:remove_const, 'FooController')
stub_const('NewRelic::Agent::Instrumentation::ControllerInstrumentation', Module.new)
end
it "should inject newrelic_ignore" do
Module.any_instance.should_receive(:newrelic_ignore).with(no_args())
load_class
end
end
似乎我正在尝试在错误的位置删除常量,导致:
pry(main)> Project::Application.send(:remove_const, 'FooController')
NameError: constant Project::Application::FooController not defined
有人可以给我提示这些住所吗? 此外,如果有人知道一种更方便的测试方法,我将不胜感激。
这应该工作
Object.send(:remove_const, :FooController)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.