analytics-ruby 2.2.6.pre → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,120 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Segment
4
- class Analytics
5
- describe Analytics do
6
- let(:analytics) { Segment::Analytics.new :write_key => WRITE_KEY, :stub => true }
7
-
8
- describe '#track' do
9
- it 'errors without an event' do
10
- expect { analytics.track(:user_id => 'user') }.to raise_error(ArgumentError)
11
- end
12
-
13
- it 'errors without a user_id' do
14
- expect { analytics.track(:event => 'Event') }.to raise_error(ArgumentError)
15
- end
16
-
17
- it 'does not error with the required options' do
18
- expect do
19
- analytics.track Queued::TRACK
20
- sleep(1)
21
- end.to_not raise_error
22
- end
23
- end
24
-
25
- describe '#identify' do
26
- it 'errors without a user_id' do
27
- expect { analytics.identify :traits => {} }.to raise_error(ArgumentError)
28
- end
29
-
30
- it 'does not error with the required options' do
31
- analytics.identify Queued::IDENTIFY
32
- sleep(1)
33
- end
34
- end
35
-
36
- describe '#alias' do
37
- it 'errors without from' do
38
- expect { analytics.alias :user_id => 1234 }.to raise_error(ArgumentError)
39
- end
40
-
41
- it 'errors without to' do
42
- expect { analytics.alias :previous_id => 1234 }.to raise_error(ArgumentError)
43
- end
44
-
45
- it 'does not error with the required options' do
46
- expect do
47
- analytics.alias ALIAS
48
- sleep(1)
49
- end.to_not raise_error
50
- end
51
- end
52
-
53
- describe '#group' do
54
- it 'errors without group_id' do
55
- expect { analytics.group :user_id => 'foo' }.to raise_error(ArgumentError)
56
- end
57
-
58
- it 'errors without user_id or anonymous_id' do
59
- expect { analytics.group :group_id => 'foo' }.to raise_error(ArgumentError)
60
- end
61
-
62
- it 'does not error with the required options' do
63
- expect do
64
- analytics.group Queued::GROUP
65
- sleep(1)
66
- end.to_not raise_error
67
- end
68
- end
69
-
70
- describe '#page' do
71
- it 'errors without user_id or anonymous_id' do
72
- expect { analytics.page :name => 'foo' }.to raise_error(ArgumentError)
73
- end
74
-
75
- it 'does not error with the required options' do
76
- expect do
77
- analytics.page Queued::PAGE
78
- sleep(1)
79
- end.to_not raise_error
80
- end
81
- end
82
-
83
- describe '#screen' do
84
- it 'errors without user_id or anonymous_id' do
85
- expect { analytics.screen :name => 'foo' }.to raise_error(ArgumentError)
86
- end
87
-
88
- it 'does not error with the required options' do
89
- expect do
90
- analytics.screen Queued::SCREEN
91
- sleep(1)
92
- end.to_not raise_error
93
- end
94
- end
95
-
96
- describe '#flush' do
97
- it 'flushes without error' do
98
- expect do
99
- analytics.identify Queued::IDENTIFY
100
- analytics.flush
101
- end.to_not raise_error
102
- end
103
- end
104
-
105
- describe '#respond_to?' do
106
- it 'responds to all public instance methods of Segment::Analytics::Client' do
107
- expect(analytics).to respond_to(*Segment::Analytics::Client.public_instance_methods(false))
108
- end
109
- end
110
-
111
- describe '#method' do
112
- Segment::Analytics::Client.public_instance_methods(false).each do |public_method|
113
- it "returns a Method object with '#{public_method}' as argument" do
114
- expect(analytics.method(public_method).class).to eq(Method)
115
- end
116
- end
117
- end
118
- end
119
- end
120
- end
data/spec/spec_helper.rb DELETED
@@ -1,128 +0,0 @@
1
- # https://github.com/codecov/codecov-ruby#usage
2
- require 'simplecov'
3
- SimpleCov.start
4
- require 'codecov'
5
- SimpleCov.formatter = SimpleCov::Formatter::Codecov
6
-
7
- require 'segment/analytics'
8
- require 'active_support/time'
9
- require './spec/helpers/runscope_client'
10
-
11
- # Setting timezone for ActiveSupport::TimeWithZone to UTC
12
- Time.zone = 'UTC'
13
-
14
- module Segment
15
- class Analytics
16
- WRITE_KEY = 'testsecret'
17
-
18
- TRACK = {
19
- :event => 'Ruby Library test event',
20
- :properties => {
21
- :type => 'Chocolate',
22
- :is_a_lie => true,
23
- :layers => 20,
24
- :created => Time.new
25
- }
26
- }
27
-
28
- IDENTIFY = {
29
- :traits => {
30
- :likes_animals => true,
31
- :instrument => 'Guitar',
32
- :age => 25
33
- }
34
- }
35
-
36
- ALIAS = {
37
- :previous_id => 1234,
38
- :user_id => 'abcd'
39
- }
40
-
41
- GROUP = {}
42
-
43
- PAGE = {
44
- :name => 'home'
45
- }
46
-
47
- SCREEN = {
48
- :name => 'main'
49
- }
50
-
51
- USER_ID = 1234
52
- GROUP_ID = 1234
53
-
54
- # Hashes sent to the client, snake_case
55
- module Queued
56
- TRACK = TRACK.merge :user_id => USER_ID
57
- IDENTIFY = IDENTIFY.merge :user_id => USER_ID
58
- GROUP = GROUP.merge :group_id => GROUP_ID, :user_id => USER_ID
59
- PAGE = PAGE.merge :user_id => USER_ID
60
- SCREEN = SCREEN.merge :user_id => USER_ID
61
- end
62
-
63
- # Hashes which are sent from the worker, camel_cased
64
- module Requested
65
- TRACK = TRACK.merge({
66
- :userId => USER_ID,
67
- :type => 'track'
68
- })
69
-
70
- IDENTIFY = IDENTIFY.merge({
71
- :userId => USER_ID,
72
- :type => 'identify'
73
- })
74
-
75
- GROUP = GROUP.merge({
76
- :groupId => GROUP_ID,
77
- :userId => USER_ID,
78
- :type => 'group'
79
- })
80
-
81
- PAGE = PAGE.merge :userId => USER_ID
82
- SCREEN = SCREEN.merge :userId => USER_ID
83
- end
84
- end
85
- end
86
-
87
- # A worker that doesn't consume jobs
88
- class NoopWorker
89
- def run
90
- # Does nothing
91
- end
92
- end
93
-
94
- # A backoff policy that returns a fixed list of values
95
- class FakeBackoffPolicy
96
- def initialize(interval_values)
97
- @interval_values = interval_values
98
- end
99
-
100
- def next_interval
101
- raise 'FakeBackoffPolicy has no values left' if @interval_values.empty?
102
- @interval_values.shift
103
- end
104
- end
105
-
106
- # usage:
107
- # it "should return a result of 5" do
108
- # eventually(options: {timeout: 1}) { long_running_thing.result.should eq(5) }
109
- # end
110
-
111
- module AsyncHelper
112
- def eventually(options = {})
113
- timeout = options[:timeout] || 2
114
- interval = options[:interval] || 0.1
115
- time_limit = Time.now + timeout
116
- loop do
117
- begin
118
- yield
119
- return
120
- rescue RSpec::Expectations::ExpectationNotMetError => error
121
- raise error if Time.now >= time_limit
122
- sleep interval
123
- end
124
- end
125
- end
126
- end
127
-
128
- include AsyncHelper