2016-09-26 54 views
0

我正在使用mixpanel-ruby庫發送分析事件。跟蹤器是在初始化器定義:運行測試時不發射mixpanel-ruby事件

require 'mixpanel-ruby' 
$mixpanel = Mixpanel::Tracker.new(Figaro.env.mixpanel_token) 

if Rails.env.development? 
    # Silence local SSL errors 
    Mixpanel.config_http do |http| 
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE 
    end 
end 

在我的控制器,我火了這樣的活動:

def resume 
    @study.resume! 
    redirect_to studies_url, notice: 'Study resumed' 
    $mixpanel.track(current_user.id, 'Resume study') 
end 

這種運作良好,但是當我用rspec spec運行測試套件的事件被解僱,這並不理想,因爲它吃我的每月活動津貼,更不用說偏斜數據。

如何防止這些在測試環境中發射?

回答

2

無論是使用代理(puffingbilly等)來模擬mixpanel服務或定製的消費者從https://github.com/mixpanel/mixpanel-ruby/issues/35

配置像

$mixpanel = if Rails.env.test? 
    Mixpanel::Tracker.new(Figaro.env.mixpanel_token) do |type, message| 
     # You can just discard the track in here if you'd like, or you can 
     # put it somewhere if you want to test your tracking 
     # track_log << [type, message] 
    end 
else 
    Mixpanel::Tracker.new(Figaro.env.mixpanel_token) # Use the default if we're not testing 
end