split 0.7.2 → 0.7.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,22 +6,22 @@ include Split::DashboardHelpers
6
6
  describe Split::DashboardHelpers do
7
7
  describe 'confidence_level' do
8
8
  it 'should handle very small numbers' do
9
- confidence_level(Complex(2e-18, -0.03)).should eql('Insufficient confidence')
9
+ expect(confidence_level(Complex(2e-18, -0.03))).to eq('Insufficient confidence')
10
10
  end
11
11
 
12
12
  it "should consider a z-score of 1.65 <= z < 1.96 as 90% confident" do
13
- confidence_level(1.65).should eql('90% confidence')
14
- confidence_level(1.80).should eql('90% confidence')
13
+ expect(confidence_level(1.65)).to eq('90% confidence')
14
+ expect(confidence_level(1.80)).to eq('90% confidence')
15
15
  end
16
16
 
17
17
  it "should consider a z-score of 1.96 <= z < 2.58 as 95% confident" do
18
- confidence_level(1.96).should eql('95% confidence')
19
- confidence_level(2.00).should eql('95% confidence')
18
+ expect(confidence_level(1.96)).to eq('95% confidence')
19
+ expect(confidence_level(2.00)).to eq('95% confidence')
20
20
  end
21
21
 
22
22
  it "should consider a z-score of z >= 2.58 as 99% confident" do
23
- confidence_level(2.58).should eql('99% confidence')
24
- confidence_level(3.00).should eql('99% confidence')
23
+ expect(confidence_level(2.58)).to eq('99% confidence')
24
+ expect(confidence_level(3.00)).to eq('99% confidence')
25
25
  end
26
26
  end
27
27
  end
@@ -30,7 +30,7 @@ describe Split::Dashboard do
30
30
 
31
31
  it "should respond to /" do
32
32
  get '/'
33
- last_response.should be_ok
33
+ expect(last_response).to be_ok
34
34
  end
35
35
 
36
36
  context "start experiment manually" do
@@ -42,12 +42,12 @@ describe Split::Dashboard do
42
42
  it "should display a Start button" do
43
43
  experiment
44
44
  get '/'
45
- last_response.body.should include('Start')
45
+ expect(last_response.body).to include('Start')
46
46
 
47
47
  post "/start/#{experiment.name}"
48
48
  get '/'
49
- last_response.body.should include('Reset Data')
50
- last_response.body.should_not include('Metrics:')
49
+ expect(last_response.body).to include('Reset Data')
50
+ expect(last_response.body).not_to include('Metrics:')
51
51
  end
52
52
  end
53
53
 
@@ -55,7 +55,7 @@ describe Split::Dashboard do
55
55
  it "should display the names of associated metrics" do
56
56
  metric
57
57
  get '/'
58
- last_response.body.should include('Metrics:testmetric')
58
+ expect(last_response.body).to include('Metrics:testmetric')
59
59
  end
60
60
  end
61
61
 
@@ -63,11 +63,11 @@ describe Split::Dashboard do
63
63
  it "should display a Start button" do
64
64
  experiment_with_goals
65
65
  get '/'
66
- last_response.body.should include('Start')
66
+ expect(last_response.body).to include('Start')
67
67
 
68
68
  post "/start/#{experiment.name}"
69
69
  get '/'
70
- last_response.body.should include('Reset Data')
70
+ expect(last_response.body).to include('Reset Data')
71
71
  end
72
72
  end
73
73
  end
@@ -126,47 +126,48 @@ describe Split::Dashboard do
126
126
 
127
127
  post "/reset/#{experiment.name}"
128
128
 
129
- last_response.should be_redirect
129
+ expect(last_response).to be_redirect
130
130
 
131
131
  new_red_count = red_link.participant_count
132
132
  new_blue_count = blue_link.participant_count
133
133
 
134
- new_blue_count.should eql(0)
135
- new_red_count.should eql(0)
136
- experiment.winner.should be_nil
134
+ expect(new_blue_count).to eq(0)
135
+ expect(new_red_count).to eq(0)
136
+ expect(experiment.winner).to be_nil
137
137
  end
138
138
 
139
139
  it "should delete an experiment" do
140
140
  delete "/#{experiment.name}"
141
- last_response.should be_redirect
142
- Split::Experiment.find(experiment.name).should be_nil
141
+ expect(last_response).to be_redirect
142
+ expect(Split::Experiment.find(experiment.name)).to be_nil
143
143
  end
144
144
 
145
145
  it "should mark an alternative as the winner" do
146
- experiment.winner.should be_nil
146
+ expect(experiment.winner).to be_nil
147
147
  post "/#{experiment.name}", :alternative => 'red'
148
148
 
149
- last_response.should be_redirect
150
- experiment.winner.name.should eql('red')
149
+ expect(last_response).to be_redirect
150
+ expect(experiment.winner.name).to eq('red')
151
151
  end
152
152
 
153
153
  it "should display the start date" do
154
154
  experiment_start_time = Time.parse('2011-07-07')
155
- Time.stub(:now => experiment_start_time)
155
+ expect(Time).to receive(:now).and_return(experiment_start_time)
156
156
  experiment
157
157
 
158
158
  get '/'
159
159
 
160
- last_response.body.should include('<small>2011-07-07</small>')
160
+ expect(last_response.body).to include('<small>2011-07-07</small>')
161
161
  end
162
162
 
163
163
  it "should handle experiments without a start date" do
164
164
  experiment_start_time = Time.parse('2011-07-07')
165
- Time.stub(:now => experiment_start_time)
165
+ expect(Time).to receive(:now).and_return(experiment_start_time)
166
+
166
167
  Split.redis.hdel(:experiment_start_times, experiment.name)
167
168
 
168
169
  get '/'
169
170
 
170
- last_response.body.should include('<small>Unknown</small>')
171
+ expect(last_response.body).to include('<small>Unknown</small>')
171
172
  end
172
173
  end
@@ -23,39 +23,39 @@ describe Split::Experiment do
23
23
  let(:experiment) { Split::Experiment.new('basket_text', :alternatives => ['Basket', "Cart"]) }
24
24
 
25
25
  it "should have a name" do
26
- experiment.name.should eql('basket_text')
26
+ expect(experiment.name).to eq('basket_text')
27
27
  end
28
28
 
29
29
  it "should have alternatives" do
30
- experiment.alternatives.length.should be 2
30
+ expect(experiment.alternatives.length).to be 2
31
31
  end
32
32
 
33
33
  it "should have alternatives with correct names" do
34
- experiment.alternatives.collect{|a| a.name}.should == ['Basket', 'Cart']
34
+ expect(experiment.alternatives.collect{|a| a.name}).to eq(['Basket', 'Cart'])
35
35
  end
36
36
 
37
37
  it "should be resettable by default" do
38
- experiment.resettable.should be_true
38
+ expect(experiment.resettable).to be_truthy
39
39
  end
40
40
 
41
41
  it "should save to redis" do
42
42
  experiment.save
43
- Split.redis.exists('basket_text').should be true
43
+ expect(Split.redis.exists('basket_text')).to be true
44
44
  end
45
45
 
46
46
  it "should save the start time to redis" do
47
47
  experiment_start_time = Time.at(1372167761)
48
- Time.stub(:now => experiment_start_time)
48
+ expect(Time).to receive(:now).and_return(experiment_start_time)
49
49
  experiment.save
50
50
 
51
- Split::Experiment.find('basket_text').start_time.should == experiment_start_time
51
+ expect(Split::Experiment.find('basket_text').start_time).to eq(experiment_start_time)
52
52
  end
53
53
 
54
54
  it "should not save the start time to redis when start_manually is enabled" do
55
- Split.configuration.stub(:start_manually => true)
55
+ expect(Split.configuration).to receive(:start_manually).and_return(true)
56
56
  experiment.save
57
57
 
58
- Split::Experiment.find('basket_text').start_time.should be_nil
58
+ expect(Split::Experiment.find('basket_text').start_time).to be_nil
59
59
  end
60
60
 
61
61
  it "should save the selected algorithm to redis" do
@@ -63,43 +63,43 @@ describe Split::Experiment do
63
63
  experiment.algorithm = experiment_algorithm
64
64
  experiment.save
65
65
 
66
- Split::Experiment.find('basket_text').algorithm.should == experiment_algorithm
66
+ expect(Split::Experiment.find('basket_text').algorithm).to eq(experiment_algorithm)
67
67
  end
68
68
 
69
69
  it "should handle having a start time stored as a string" do
70
70
  experiment_start_time = Time.parse("Sat Mar 03 14:01:03")
71
- Time.stub(:now => experiment_start_time)
71
+ expect(Time).to receive(:now).twice.and_return(experiment_start_time)
72
72
  experiment.save
73
73
  Split.redis.hset(:experiment_start_times, experiment.name, experiment_start_time)
74
74
 
75
- Split::Experiment.find('basket_text').start_time.should == experiment_start_time
75
+ expect(Split::Experiment.find('basket_text').start_time).to eq(experiment_start_time)
76
76
  end
77
77
 
78
78
  it "should handle not having a start time" do
79
79
  experiment_start_time = Time.parse("Sat Mar 03 14:01:03")
80
- Time.stub(:now => experiment_start_time)
80
+ expect(Time).to receive(:now).and_return(experiment_start_time)
81
81
  experiment.save
82
82
 
83
83
  Split.redis.hdel(:experiment_start_times, experiment.name)
84
84
 
85
- Split::Experiment.find('basket_text').start_time.should == nil
85
+ expect(Split::Experiment.find('basket_text').start_time).to be_nil
86
86
  end
87
87
 
88
88
  it "should not create duplicates when saving multiple times" do
89
89
  experiment.save
90
90
  experiment.save
91
- Split.redis.exists('basket_text').should be true
92
- Split.redis.lrange('basket_text', 0, -1).should eql(['Basket', "Cart"])
91
+ expect(Split.redis.exists('basket_text')).to be true
92
+ expect(Split.redis.lrange('basket_text', 0, -1)).to eq(['Basket', "Cart"])
93
93
  end
94
94
 
95
95
  describe 'new record?' do
96
96
  it "should know if it hasn't been saved yet" do
97
- experiment.new_record?.should be_true
97
+ expect(experiment.new_record?).to be_truthy
98
98
  end
99
99
 
100
100
  it "should know if it has been saved yet" do
101
101
  experiment.save
102
- experiment.new_record?.should be_false
102
+ expect(experiment.new_record?).to be_falsey
103
103
  end
104
104
  end
105
105
 
@@ -107,18 +107,18 @@ describe Split::Experiment do
107
107
  it "should return an existing experiment" do
108
108
  experiment.save
109
109
  experiment = Split::Experiment.find('basket_text')
110
- experiment.name.should eql('basket_text')
110
+ expect(experiment.name).to eq('basket_text')
111
111
  end
112
112
 
113
113
  it "should return an existing experiment" do
114
- Split::Experiment.find('non_existent_experiment').should be_nil
114
+ expect(Split::Experiment.find('non_existent_experiment')).to be_nil
115
115
  end
116
116
  end
117
117
 
118
118
  describe 'control' do
119
119
  it 'should be the first alternative' do
120
120
  experiment.save
121
- experiment.control.name.should eql('Basket')
121
+ expect(experiment.control.name).to eq('Basket')
122
122
  end
123
123
  end
124
124
  end
@@ -126,12 +126,12 @@ describe Split::Experiment do
126
126
  describe 'initialization' do
127
127
  it "should set the algorithm when passed as an option to the initializer" do
128
128
  experiment = Split::Experiment.new('basket_text', :alternatives => ['Basket', "Cart"], :algorithm => Split::Algorithms::Whiplash)
129
- experiment.algorithm.should == Split::Algorithms::Whiplash
129
+ expect(experiment.algorithm).to eq(Split::Algorithms::Whiplash)
130
130
  end
131
131
 
132
132
  it "should be possible to make an experiment not resettable" do
133
133
  experiment = Split::Experiment.new('basket_text', :alternatives => ['Basket', "Cart"], :resettable => false)
134
- experiment.resettable.should be_false
134
+ expect(experiment.resettable).to be_falsey
135
135
  end
136
136
  end
137
137
 
@@ -142,8 +142,8 @@ describe Split::Experiment do
142
142
  experiment.save
143
143
 
144
144
  e = Split::Experiment.find('basket_text')
145
- e.should == experiment
146
- e.resettable.should be_false
145
+ expect(e).to eq(experiment)
146
+ expect(e.resettable).to be_falsey
147
147
 
148
148
  end
149
149
 
@@ -152,8 +152,8 @@ describe Split::Experiment do
152
152
  experiment.save
153
153
 
154
154
  e = Split::Experiment.find('basket_text')
155
- e.should == experiment
156
- e.algorithm.should == Split::Algorithms::Whiplash
155
+ expect(e).to eq(experiment)
156
+ expect(e.algorithm).to eq(Split::Algorithms::Whiplash)
157
157
  end
158
158
 
159
159
  it "should persist a new experiment in redis, that does not exist in the configuration file" do
@@ -161,8 +161,8 @@ describe Split::Experiment do
161
161
  experiment.save
162
162
 
163
163
  e = Split::Experiment.find('foobar')
164
- e.should == experiment
165
- e.alternatives.collect{|a| a.name}.should == ['tra', 'la']
164
+ expect(e).to eq(experiment)
165
+ expect(e.alternatives.collect{|a| a.name}).to eq(['tra', 'la'])
166
166
  end
167
167
  end
168
168
 
@@ -172,14 +172,14 @@ describe Split::Experiment do
172
172
  experiment.save
173
173
 
174
174
  experiment.delete
175
- Split.redis.exists('link_color').should be false
176
- Split::Experiment.find('link_color').should be_nil
175
+ expect(Split.redis.exists('link_color')).to be false
176
+ expect(Split::Experiment.find('link_color')).to be_nil
177
177
  end
178
178
 
179
179
  it "should increment the version" do
180
- experiment.version.should eql(0)
180
+ expect(experiment.version).to eq(0)
181
181
  experiment.delete
182
- experiment.version.should eql(1)
182
+ expect(experiment.version).to eq(1)
183
183
  end
184
184
 
185
185
  it "should call the on_experiment_delete hook" do
@@ -191,13 +191,13 @@ describe Split::Experiment do
191
191
 
192
192
  describe 'winner' do
193
193
  it "should have no winner initially" do
194
- experiment.winner.should be_nil
194
+ expect(experiment.winner).to be_nil
195
195
  end
196
196
 
197
197
  it "should allow you to specify a winner" do
198
198
  experiment.save
199
199
  experiment.winner = 'red'
200
- experiment.winner.name.should == 'red'
200
+ expect(experiment.winner.name).to eq('red')
201
201
  end
202
202
  end
203
203
 
@@ -222,30 +222,30 @@ describe Split::Experiment do
222
222
  it 'should reset all alternatives' do
223
223
  experiment.winner = 'green'
224
224
 
225
- experiment.next_alternative.name.should eql('green')
225
+ expect(experiment.next_alternative.name).to eq('green')
226
226
  green.increment_participation
227
227
 
228
228
  experiment.reset
229
229
 
230
- green.participant_count.should eql(0)
231
- green.completed_count.should eql(0)
230
+ expect(green.participant_count).to eq(0)
231
+ expect(green.completed_count).to eq(0)
232
232
  end
233
233
 
234
234
  it 'should reset the winner' do
235
235
  experiment.winner = 'green'
236
236
 
237
- experiment.next_alternative.name.should eql('green')
237
+ expect(experiment.next_alternative.name).to eq('green')
238
238
  green.increment_participation
239
239
 
240
240
  experiment.reset
241
241
 
242
- experiment.winner.should be_nil
242
+ expect(experiment.winner).to be_nil
243
243
  end
244
244
 
245
245
  it "should increment the version" do
246
- experiment.version.should eql(0)
246
+ expect(experiment.version).to eq(0)
247
247
  experiment.reset
248
- experiment.version.should eql(1)
248
+ expect(experiment.version).to eq(1)
249
249
  end
250
250
 
251
251
  it "should call the on_experiment_reset hook" do
@@ -258,12 +258,12 @@ describe Split::Experiment do
258
258
  let(:experiment) { Split::Experiment.find_or_create('link_color', 'blue', 'red', 'green') }
259
259
 
260
260
  it 'should use the default algorithm if none is specified' do
261
- experiment.algorithm.should == Split.configuration.algorithm
261
+ expect(experiment.algorithm).to eq(Split.configuration.algorithm)
262
262
  end
263
263
 
264
264
  it 'should use the user specified algorithm for this experiment if specified' do
265
265
  experiment.algorithm = Split::Algorithms::Whiplash
266
- experiment.algorithm.should == Split::Algorithms::Whiplash
266
+ expect(experiment.algorithm).to eq(Split::Algorithms::Whiplash)
267
267
  end
268
268
  end
269
269
 
@@ -274,16 +274,16 @@ describe Split::Experiment do
274
274
  green = Split::Alternative.new('green', 'link_color')
275
275
  experiment.winner = 'green'
276
276
 
277
- experiment.next_alternative.name.should eql('green')
277
+ expect(experiment.next_alternative.name).to eq('green')
278
278
  green.increment_participation
279
279
 
280
- experiment.next_alternative.name.should eql('green')
280
+ expect(experiment.next_alternative.name).to eq('green')
281
281
  end
282
282
 
283
283
  it "should use the specified algorithm if a winner does not exist" do
284
284
  experiment.algorithm = Split::Algorithms::Whiplash
285
- experiment.algorithm.should_receive(:choose_alternative).and_return(Split::Alternative.new('green', 'link_color'))
286
- experiment.next_alternative.name.should eql('green')
285
+ expect(experiment.algorithm).to receive(:choose_alternative).and_return(Split::Alternative.new('green', 'link_color'))
286
+ expect(experiment.next_alternative.name).to eq('green')
287
287
  end
288
288
  end
289
289
 
@@ -291,7 +291,7 @@ describe Split::Experiment do
291
291
  let(:experiment) { Split::Experiment.find_or_create('link_color', 'blue') }
292
292
 
293
293
  it "should always return the color blue" do
294
- experiment.next_alternative.name.should eql('blue')
294
+ expect(experiment.next_alternative.name).to eq('blue')
295
295
  end
296
296
  end
297
297
 
@@ -304,24 +304,24 @@ describe Split::Experiment do
304
304
  experiment.save
305
305
  blue.participant_count = 5
306
306
  same_experiment = same_but_different_alternative
307
- same_experiment.alternatives.map(&:name).should eql(['blue', 'yellow', 'orange'])
308
- blue.participant_count.should eql(0)
307
+ expect(same_experiment.alternatives.map(&:name)).to eq(['blue', 'yellow', 'orange'])
308
+ expect(blue.participant_count).to eq(0)
309
309
  end
310
310
 
311
311
  it "should only reset once" do
312
312
  experiment.save
313
- experiment.version.should eql(0)
313
+ expect(experiment.version).to eq(0)
314
314
  same_experiment = same_but_different_alternative
315
- same_experiment.version.should eql(1)
315
+ expect(same_experiment.version).to eq(1)
316
316
  same_experiment_again = same_but_different_alternative
317
- same_experiment_again.version.should eql(1)
317
+ expect(same_experiment_again.version).to eq(1)
318
318
  end
319
319
  end
320
320
 
321
321
  describe 'alternatives passed as non-strings' do
322
322
  it "should throw an exception if an alternative is passed that is not a string" do
323
- lambda { Split::Experiment.find_or_create('link_color', :blue, :red) }.should raise_error
324
- lambda { Split::Experiment.find_or_create('link_enabled', true, false) }.should raise_error
323
+ expect(lambda { Split::Experiment.find_or_create('link_color', :blue, :red) }).to raise_error
324
+ expect(lambda { Split::Experiment.find_or_create('link_enabled', true, false) }).to raise_error
325
325
  end
326
326
  end
327
327
 
@@ -331,12 +331,12 @@ describe Split::Experiment do
331
331
  }
332
332
 
333
333
  it "should work for a new experiment" do
334
- experiment_with_weight.alternatives.map(&:weight).should == [1, 2]
334
+ expect(experiment_with_weight.alternatives.map(&:weight)).to eq([1, 2])
335
335
  end
336
336
 
337
337
  it "should work for an existing experiment" do
338
338
  experiment.save
339
- experiment_with_weight.alternatives.map(&:weight).should == [1, 2]
339
+ expect(experiment_with_weight.alternatives.map(&:weight)).to eq([1, 2])
340
340
  end
341
341
  end
342
342
 
@@ -353,26 +353,26 @@ describe Split::Experiment do
353
353
  before { experiment.save }
354
354
 
355
355
  it "can find existing experiment" do
356
- Split::Experiment.find("link_color").name.should eql("link_color")
356
+ expect(Split::Experiment.find("link_color").name).to eq("link_color")
357
357
  end
358
358
 
359
359
  it "should reset an experiment if it is loaded with different goals" do
360
360
  same_experiment = same_but_different_goals
361
- Split::Experiment.find("link_color").goals.should == ["purchase", "refund"]
361
+ expect(Split::Experiment.find("link_color").goals).to eq(["purchase", "refund"])
362
362
  end
363
363
 
364
364
  end
365
365
 
366
366
  it "should have goals" do
367
- experiment.goals.should eql(["purchase"])
367
+ expect(experiment.goals).to eq(["purchase"])
368
368
  end
369
369
 
370
370
  context "find or create experiment" do
371
371
  it "should have correct goals" do
372
372
  experiment = Split::Experiment.find_or_create({'link_color3' => ["purchase", "refund"]}, 'blue', 'red', 'green')
373
- experiment.goals.should == ["purchase", "refund"]
373
+ expect(experiment.goals).to eq(["purchase", "refund"])
374
374
  experiment = Split::Experiment.find_or_create('link_color3', 'blue', 'red', 'green')
375
- experiment.goals.should == []
375
+ expect(experiment.goals).to eq([])
376
376
  end
377
377
  end
378
378
  end