mixpanel_test-rails 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in mixpanel_test-rails.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,2 @@
1
+ module MixpanelTest
2
+ end
@@ -0,0 +1,14 @@
1
+ module MixpanelTest
2
+ class CucumberGenerator < Rails::Generators::Base
3
+ source_root File.expand_path('../templates', __FILE__)
4
+
5
+ def generate_cucumber
6
+ copy_file "mixpanel_steps.rb", "features/step_definitions/mixpanel_steps.rb"
7
+ copy_file "mixpanel_test_service.rb", "features/support/mixpanel_test_service.rb"
8
+ puts "(1a) If you're using the mixpanel gem, then set the config parameter :url to \"localhost:3001\" and the :test_service_hostname to \"localhost:3001\" (the johncant/mixpanel fork definitely contains these options)"
9
+ puts "(1b) If you're not using the mixpanel gem, then replace the hostname in the Mixpanel javascript file url with \"localhost:3001\"."
10
+ puts "PROFIT!!!!!! mixpanel_test_service will then hijack all the API data for the purpose of testing."
11
+ puts "If that didn't work, please change this gem or mixpanel_test_service or mixpanel and submit a pull request."
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,57 @@
1
+ #When
2
+
3
+ # Ignore a mixpanel event
4
+ When /^I discard that Mixpanel "([^\"]*)" event$/ do |event_name|
5
+ step "Mixpanel should receive a \"#{event_name}\" event"
6
+ end
7
+
8
+ # Check that Mixpanel received a specific event
9
+ Then /^(?:|Mixpanel )should receive (?:|a|an) "([^\"]*)" event$/ do |event_name|
10
+ @last_mixpanel_event = mixpanel_synchronize_until do
11
+
12
+ mixpanel_test_service.transaction do
13
+ matching_events = mixpanel_test_service.events.find_all do |ev|
14
+ ev["event"] == event_name
15
+ end
16
+ assert matching_events.count <= 1, "More than one \"#{event_name}\" events were received"
17
+
18
+ if matching_events.count == 1
19
+ next mixpanel_test_service.events.delete(matching_events.first)
20
+ else
21
+ next false
22
+ end
23
+ end
24
+ end
25
+
26
+ assert_not_nil @last_mixpanel_event, "Mixpanel did not receive any \"#{event_name}\" events"
27
+ end
28
+
29
+ # Check that a page visit was recorded
30
+ Then /^(?:|Mixpanel )should track (?:|the |a )page(?:| visit| view| hit)$/ do
31
+ step "Mixpanel should receive a \"mp_page_view\" event" # TODO - find out the exact event name
32
+ end
33
+
34
+ Then /^(?:|Mixpanel )should see "([^\"]*)" (?:|as |for )the "([^\"]*)" property$/ do |value, key|
35
+ assert_equal value, @last_mixpanel_event["properties"][key]
36
+ end
37
+
38
+ # Check that Mixpanel will show something up in the stream
39
+ Then /^(?:|Mixpanel )should show "([^\"]*)" in the stream(?: and (?:|as |for )the "([^\"]*)" property)?$/ do |value, key|
40
+ step "Mixpanel should see \"#{value}\" as the \"mp_note\" property"
41
+ step "Mixpanel should see \"#{value}\" as the \"#{key}\" property" if key
42
+ end
43
+
44
+ # Check that a url is used as a Mixpanel property
45
+ Then /^(?:|Mixpanel )should see the url for (.+?) (?:|as |for )the "([^\"]*)" property$/ do |path, key|
46
+ step "Mixpanel should see \"#{path_to(path)}\" as the \"#{key}\" property"
47
+ end
48
+
49
+ Then /^the Mixpanel stream should contain "([^\"]*)"$/ do |text|
50
+ notes = @last_mixpanel_event["properties"]["mp_note"]
51
+ assert notes.include?(text), "Expected property mp_note (\"#{notes}\") to contain \"#{text}\""
52
+ end
53
+
54
+ Then /^the Mixpanel stream should contain the word "([^\"]*)"$/ do |test|
55
+ notes = @last_mixpanel_event["properties"]["mp_note"]
56
+ assert notes.match(Regexp.new(/(\W|^)#{Regexp.escape(test)}(\W|$)/)),
57
+ end
@@ -0,0 +1,40 @@
1
+ # Mixpanel test service.
2
+ # Use this with my Mixpanel gem fork (johncant/mixpanel) or replace the mixpanel javascript file url hostname with localhost:3001. This will proxy the Mixpanel javascript file through the Mixpanel test service, which will edit it slightly. Then, all Mixpanel API calls will go to the Mixpanel test service instead, where you can run tests on them.
3
+ require "mixpanel_test/service"
4
+ require "test/unit"
5
+
6
+ module MixpanelTestHelpers
7
+ mattr_accessor :mixpanel_test_service
8
+
9
+ def mixpanel_synchronize_until(secs = 2)
10
+ start_time = Time.now
11
+
12
+ until (res=yield) || Time.now >= start_time+2.seconds
13
+ sleep 0.05
14
+ end
15
+
16
+ res || nil
17
+ end
18
+
19
+ end
20
+
21
+ World(MixpanelTestHelpers)
22
+
23
+ Before "@mixpanel" do
24
+ begin
25
+ MixpanelTestHelpers.mixpanel_test_service ||= MixpanelTest::Service.new(:port => 3001) # Don't shut this down until the end of the process. There are likely to be so many mixpanel tests that the overhead would really slow down the tests.
26
+ MixpanelTestHelpers.mixpanel_test_service.transaction do
27
+ MixpanelTestHelpers.mixpanel_test_service.events.clear
28
+ end
29
+ rescue
30
+ MixpanelTestHelpers.mixpanel_test_service = nil
31
+ end
32
+ end
33
+
34
+ at_exit do
35
+ if MixpanelTestHelpers.mixpanel_test_service
36
+ MixpanelTestHelpers.mixpanel_test_service.stop
37
+ Thread.pass until MixpanelTestHelpers.mixpanel_test_service.stopped?
38
+ end
39
+ end
40
+
@@ -0,0 +1,7 @@
1
+ require "mixpanel_test-rails/version"
2
+
3
+ module MixpanelTest
4
+ module Rails
5
+ # Your code goes here...
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module MixpanelTest
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "mixpanel_test/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "mixpanel_test-rails"
7
+ s.version = MixpanelTest::VERSION
8
+ s.authors = ["John Cant"]
9
+ s.email = ["a.johncant@gmail.com"]
10
+ s.homepage = "https://github.com/johncant/mixpanel_test-rails"
11
+ s.summary = %q{Cucumber steps for testing mixpanel integration}
12
+ s.description = %q{Cucumber steps for testing mixpanel integration}
13
+
14
+ s.rubyforge_project = "mixpanel_test-rails"
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ # specify any dependencies here; for example:
21
+ # s.add_development_dependency "rspec"
22
+ s.add_runtime_dependency "mixpanel_test_service"
23
+ s.add_runtime_dependency "rails", ">= 3.0.0"
24
+ end
data/readme.md ADDED
@@ -0,0 +1,15 @@
1
+ <h1>Purpose</h1>
2
+ <p>This gem provides some cucumber steps for use with <a href="https://github.com/johncant/mixpanel_test_service">mixpanel_test_service.</p>
3
+ <p>Feel free to add other types of test helpers</p>
4
+ <h2>Usage</h2>
5
+ <pre>
6
+ # Add this to your Gemfile
7
+ gem "mixpanel_test-rails"
8
+
9
+ # Run this
10
+ rails g mixpanel_test:cucumber # Generates cucumber steps and tells you how to set up the rest
11
+ </pre>
12
+
13
+ <h2>Limitations</h2>
14
+
15
+ <p>This gem has no tests. However, version 0.0.1 is being used to test <a href="http://behiring.com">BeHiring</a></p>
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mixpanel_test-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - John Cant
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-10 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mixpanel_test_service
16
+ requirement: &22835080 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *22835080
25
+ - !ruby/object:Gem::Dependency
26
+ name: rails
27
+ requirement: &22834460 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 3.0.0
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *22834460
36
+ description: Cucumber steps for testing mixpanel integration
37
+ email:
38
+ - a.johncant@gmail.com
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - .gitignore
44
+ - Gemfile
45
+ - Rakefile
46
+ - lib/generators/mixpanel_test.rb
47
+ - lib/generators/mixpanel_test/cucumber/cucumber_generator.rb
48
+ - lib/generators/mixpanel_test/cucumber/templates/mixpanel_steps.rb
49
+ - lib/generators/mixpanel_test/cucumber/templates/mixpanel_test_service.rb
50
+ - lib/mixpanel_test/rails.rb
51
+ - lib/mixpanel_test/version.rb
52
+ - mixpanel_test-rails.gemspec
53
+ - readme.md
54
+ homepage: https://github.com/johncant/mixpanel_test-rails
55
+ licenses: []
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubyforge_project: mixpanel_test-rails
74
+ rubygems_version: 1.8.15
75
+ signing_key:
76
+ specification_version: 3
77
+ summary: Cucumber steps for testing mixpanel integration
78
+ test_files: []