2016-09-26 5 views
0

私は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

どちらか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 

のようなカスタムの消費者で構成するには(puffingbillyなど)プロキシを使用

関連する問題