2013-05-17 29 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 
相關問題