Skip to content

Commit

Permalink
More coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
sturgill committed Oct 8, 2012
1 parent 3e18aad commit 0361469
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -7,7 +7,7 @@
- [Install] (#install)
- [Rack Middleware] (#rack-middleware)
- [Usage] (#usage)
- [Initialize Mixpanel class] (#initialize-mixpanel-class)
- [Initialize Mixpanel] (#initialize-mixpanel)
- [Track Events Directly](#track-events-directly)
- [Import Events](#import-events)
- [Set Person Attributes Directly](#set-person-attributes-directly)
Expand Down Expand Up @@ -84,7 +84,7 @@ Where **options** is a hash that accepts the following keys:

## Usage

### Initialize Mixpanel Class
### Initialize Mixpanel

```ruby
@mixpanel = Mixpanel::Tracker.new YOUR_MIXPANEL_API_TOKEN, options
Expand Down
2 changes: 2 additions & 0 deletions lib/mixpanel/tracker.rb
Expand Up @@ -65,8 +65,10 @@ def send_async url
begin
url << "\n"
w.write url
1
rescue Errno::EPIPE => e
Mixpanel::Tracker.dispose_worker w
0
end
end
end
Expand Down
1 change: 1 addition & 0 deletions mixpanel.gemspec
Expand Up @@ -17,6 +17,7 @@ spec = Gem::Specification.new do |s|
s.add_dependency 'json'
s.add_dependency 'rack'
s.add_dependency 'escape'
s.add_development_dependency 'active_support'
s.add_development_dependency 'rspec'
s.add_development_dependency 'rack-test'
s.add_development_dependency 'fakeweb'
Expand Down
4 changes: 0 additions & 4 deletions spec/mixpanel/middleware_spec.rb
@@ -1,6 +1,5 @@
require 'spec_helper'
require 'mixpanel/middleware'
require 'active_support/core_ext/hash'

def exec_default_appends_on(mixpanel)
mixpanel.append_track("Visit", {:article => 1})
Expand All @@ -10,9 +9,6 @@ def exec_default_appends_on(mixpanel)
end

def check_for_default_appends_on(txt)
# puts "TEXT:\n\n"
# puts txt
# puts "\n\n"
txt.should =~ /mixpanel\.track\("Visit",\s?\{"article":1,"time":/
txt.should =~ /mixpanel\.track\("Sign in",\s?\{"time":/
txt.should =~ /mixpanel\.people\.set\(.*\);\nmixpanel.people.increment\(\"sign_in_rate\",\s?1\);/
Expand Down
1 change: 0 additions & 1 deletion spec/mixpanel/tracker_spec.rb
@@ -1,5 +1,4 @@
require 'spec_helper'
require 'active_support/core_ext/hash'

describe Mixpanel::Tracker do
before(:each) do
Expand Down
14 changes: 12 additions & 2 deletions spec/spec_helper.rb
Expand Up @@ -3,18 +3,28 @@
require 'rack/test'
require 'fakeweb'
require 'nokogiri'
require 'active_support/core_ext/hash'

Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}

MIX_PANEL_TOKEN = "e2d8b0bea559147844ffab3d607d26a6"


def mixpanel_queue_should_include(mixpanel, type, *arguments)
mixpanel.queue.each do |event_type, event_arguments|
event_arguments.should == arguments.map{|arg| arg.to_json}
event_type.should == type
# hashes store keys in an undetermined order. convert to json and back and compare hash to hash, not json to json
unjsonify(event_arguments).should == json_and_back(arguments)
end
end

def json_and_back array
unjsonify array.collect { |arg| arg.to_json }
end

def unjsonify array
array.collect { |arg| JSON.parse(arg) rescue arg }
end

# Fakeweb
FakeWeb.allow_net_connect = false
FakeWeb.register_uri(:any, /http:\/\/api\.mixpanel\.com.*/, :body => "1")

0 comments on commit 0361469

Please sign in to comment.