【发布时间】:2013-05-17 09:12:45
【问题描述】:
我的应用程序控制器中包含一些第 3 方库。
require 'new_relic/agent/method_tracer'
class ApplicationController < ApplicationController::Base
end
我想在我的其他控制器中使用它,例如在我的 SearchController 中
class SearchController < ApplicationController
add_method_tracer :show, 'Custom/FU'
end
我知道,我可以通过rspec检查控制器中库提供的方法是否存在:
require 'spec_helper'
describe SearchController do
it "has newrelic method tracer enabled" do
SearchController.should respond_to :add_method_tracer
end
end
但是这个解决方案没有检查正确的方法参数。
我如何确保(通过 rspec 测试)SearchController 具有:
add_method_tracer :show, 'Custom/FU'
存在行,并且使用正确的参数调用它?
简单地说,我想要一个测试,当有人意外从控制器中删除 add_method_tracer 时,它会失败......并且......我想确保使用正确的参数调用该方法。
【问题讨论】:
标签: ruby-on-rails testing rspec