2013-05-17 30 views
3

我的应用程序控制器中包含一些第三方库。Rspec,确保在Rails控制器类上调用方法

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其失败......然后......我想确保,该方法被调用合适的参数。

回答

0

我不知道这个宝石,但我看了一眼at the code,发现it checks如果它已经做了它应该做的事情使用trace_method_exists?

所以,你可以尝试这样的:

it "is tracing #show on metric Custom/FU" do 
    expect(SearchController.trace_method_exists?(:show, "Custom/FU")).to be_false 
end 
相关问题