mix_tape 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -65,6 +65,13 @@ Don't forget to set your MixPanel API token:
65
65
  config.token = '12345'
66
66
  end
67
67
 
68
+ If you are in a dev or test environment and don't want to send events to MixPanel:
69
+
70
+ MixTape.config do |config|
71
+ config.fake = true
72
+ config.console_logging = true
73
+ end
74
+
68
75
  And then execute:
69
76
 
70
77
  $ bundle
@@ -1,15 +1,25 @@
1
1
  module MixTape
2
2
 
3
3
  class << self
4
- attr_accessor :token
4
+ attr_accessor :token, :fake, :console_logging
5
5
 
6
6
  def client
7
- raise(ArgumentError, %{MixPanel token is undefined.}) if token.empty?
8
- @client ||= Mixpanel::Tracker.new(token, async: true)
7
+ raise(ArgumentError, %{MixPanel token is undefined.}) if token.empty? && !fake
8
+ @client = mix_client
9
9
  end
10
10
 
11
11
  def config(&block)
12
12
  instance_eval &block
13
13
  end
14
+
15
+ private
16
+
17
+ def mix_client
18
+ if !!fake
19
+ FakeTracker.new(console_logging)
20
+ else
21
+ Mixpanel::Tracker.new(token, async: true)
22
+ end
23
+ end
14
24
  end
15
- end
25
+ end
@@ -0,0 +1,19 @@
1
+ module MixTape
2
+
3
+ class FakeTracker
4
+ attr_reader :console_logging
5
+
6
+ def initialize(console_logging)
7
+ @console_logging = console_logging
8
+ end
9
+
10
+ def track(name, args={})
11
+ puts "FakeTracker.track #{name}, #{args}" if console_logging
12
+ end
13
+
14
+ def set(name, args={})
15
+ puts "FakeTracker.set #{name}, #{args}" if console_logging
16
+ end
17
+ end
18
+
19
+ end
@@ -1,3 +1,3 @@
1
1
  module MixTape
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/mix_tape.rb CHANGED
@@ -2,6 +2,7 @@ require "mixpanel"
2
2
  require "mix_tape/client"
3
3
  require "mix_tape/version"
4
4
  require "mix_tape/builder"
5
+ require "mix_tape/fake_tracker"
5
6
 
6
7
  module MixTape
7
8
  end
@@ -42,4 +42,4 @@ describe "Triggering Events" do
42
42
  client.should_receive(:set).with("1", expected_properties)
43
43
  MixTape.set_button_click(user.id, user, button)
44
44
  end
45
- end
45
+ end
@@ -10,11 +10,22 @@ describe 'Configuraton' do
10
10
  end
11
11
 
12
12
  it "raises when token not defined" do
13
- MixTape.config{ |config|config.token = '' }
13
+ MixTape.config{ |config| config.token = '' }
14
14
 
15
15
  expect{
16
16
  MixTape.client
17
17
  }.to raise_error("MixPanel token is undefined.")
18
18
  end
19
- end
20
19
 
20
+ it "uses MixPanel if all goes well" do
21
+ MixTape.config{ |config| config.token = '1234' }
22
+
23
+ expect(MixTape.client).to be_a Mixpanel::Tracker
24
+ end
25
+
26
+ it "uses FakeTracker if we set it up" do
27
+ MixTape.config{ |config| config.fake = true }
28
+
29
+ expect(MixTape.client).to be_a MixTape::FakeTracker
30
+ end
31
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'FakeTracker' do
4
+ context 'logging' do
5
+ let(:client) { MixTape::FakeTracker.new(true) }
6
+
7
+ it "logs track events to the console" do
8
+ Object.any_instance.should_receive(:puts)
9
+ client.track "button_click"
10
+ end
11
+
12
+ it "logs set events to the console" do
13
+ Object.any_instance.should_receive(:puts)
14
+ client.set 1
15
+ end
16
+ end
17
+
18
+ context 'no logging' do
19
+ let(:client) { MixTape::FakeTracker.new(false) }
20
+
21
+ it "does not log anything" do
22
+ Object.any_instance.should_not_receive(:puts)
23
+ client.track "button_click"
24
+ client.set 1
25
+ end
26
+ end
27
+ end
data/spec/spec_helper.rb CHANGED
@@ -5,4 +5,4 @@ RSpec.configure do |config|
5
5
  config.color_enabled = true
6
6
  config.tty = true
7
7
  config.formatter = :documentation # :progress, :html, :textmate
8
- end
8
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mix_tape
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-20 00:00:00.000000000 Z
12
+ date: 2013-08-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -90,11 +90,13 @@ files:
90
90
  - lib/mix_tape.rb
91
91
  - lib/mix_tape/builder.rb
92
92
  - lib/mix_tape/client.rb
93
+ - lib/mix_tape/fake_tracker.rb
93
94
  - lib/mix_tape/version.rb
94
95
  - lib/tasks/documentation.rake
95
96
  - mix_tape.gemspec
96
97
  - spec/lib/mix_tape/builder_spec.rb
97
98
  - spec/lib/mix_tape/config_spec.rb
99
+ - spec/lib/mix_tape/fake_tracker_spec.rb
98
100
  - spec/spec_helper.rb
99
101
  homepage: ''
100
102
  licenses:
@@ -124,4 +126,5 @@ summary: Tidy up your mixpanel commits
124
126
  test_files:
125
127
  - spec/lib/mix_tape/builder_spec.rb
126
128
  - spec/lib/mix_tape/config_spec.rb
129
+ - spec/lib/mix_tape/fake_tracker_spec.rb
127
130
  - spec/spec_helper.rb