172172 it "should only let a user participate in one experiment at a time" do
173173 link_color = ab_test ( 'link_color' , 'blue' , 'red' )
174174 ab_test ( 'button_size' , 'small' , 'big' )
175- expect ( ab_user ) . to eq ( { ' link_color' => link_color } )
175+ expect ( ab_user [ 'link_color' ] ) . to eq ( link_color )
176176 big = Split ::Alternative . new ( 'big' , 'button_size' )
177177 expect ( big . participant_count ) . to eq ( 0 )
178178 small = Split ::Alternative . new ( 'small' , 'button_size' )
185185 end
186186 link_color = ab_test ( 'link_color' , 'blue' , 'red' )
187187 button_size = ab_test ( 'button_size' , 'small' , 'big' )
188- expect ( ab_user ) . to eq ( { 'link_color' => link_color , 'button_size' => button_size } )
188+ expect ( ab_user [ 'link_color' ] ) . to eq ( link_color )
189+ expect ( ab_user [ 'button_size' ] ) . to eq ( button_size )
189190 button_size_alt = Split ::Alternative . new ( button_size , 'button_size' )
190191 expect ( button_size_alt . participant_count ) . to eq ( 1 )
191192 end
192193
193194 it "should not over-write a finished key when an experiment is on a later version" do
194195 experiment . increment_version
195196 ab_user = { experiment . key => 'blue' , experiment . finished_key => true }
196- finshed_session = ab_user . dup
197+ finished_session = ab_user . dup
197198 ab_test ( 'link_color' , 'blue' , 'red' )
198- expect ( ab_user ) . to eq ( finshed_session )
199+ expect ( ab_user ) . to eq ( finished_session )
199200 end
200201 end
201202
247248
248249 it "should set experiment's finished key if reset is false" do
249250 finished ( @experiment_name , { :reset => false } )
250- expect ( ab_user ) . to eq ( @experiment . key => @alternative_name , @experiment . finished_key => true )
251+ expect ( ab_user [ @experiment . key ] ) . to eq ( @alternative_name )
252+ expect ( ab_user [ @experiment . finished_key ] ) . to eq ( true )
251253 end
252254
253255 it 'should not increment the counter if reset is false and the experiment has been already finished' do
279281 end
280282
281283 it "should clear out the user's participation from their session" do
282- expect ( ab_user ) . to eq ( @experiment . key => @alternative_name )
284+ expect ( ab_user [ @experiment . key ] ) . to eq ( @alternative_name )
283285 finished ( @experiment_name )
284- expect ( ab_user ) . to eq ( { } )
286+ expect ( ab_user . keys ) . to be_empty
285287 end
286288
287289 it "should not clear out the users session if reset is false" do
288- expect ( ab_user ) . to eq ( @experiment . key => @alternative_name )
290+ expect ( ab_user [ @experiment . key ] ) . to eq ( @alternative_name )
289291 finished ( @experiment_name , { :reset => false } )
290- expect ( ab_user ) . to eq ( @experiment . key => @alternative_name , @experiment . finished_key => true )
292+ expect ( ab_user [ @experiment . key ] ) . to eq ( @alternative_name )
293+ expect ( ab_user [ @experiment . finished_key ] ) . to eq ( true )
291294 end
292295
293296 it "should reset the users session when experiment is not versioned" do
294- expect ( ab_user ) . to eq ( @experiment . key => @alternative_name )
297+ expect ( ab_user [ @experiment . key ] ) . to eq ( @alternative_name )
295298 finished ( @experiment_name )
296- expect ( ab_user ) . to eq ( { } )
299+ expect ( ab_user . keys ) . to be_empty
297300 end
298301
299302 it "should reset the users session when experiment is versioned" do
300303 @experiment . increment_version
301304 @alternative_name = ab_test ( @experiment_name , *@alternatives )
302305
303- expect ( ab_user ) . to eq ( @experiment . key => @alternative_name )
306+ expect ( ab_user [ @experiment . key ] ) . to eq ( @alternative_name )
304307 finished ( @experiment_name )
305- expect ( ab_user ) . to eq ( { } )
308+ expect ( ab_user . keys ) . to be_empty
306309 end
307310
308311 it "should do nothing where the experiment was not started by this user" do
337340 experiment = Split ::ExperimentCatalog . find :my_experiment
338341
339342 finished :my_experiment
340- expect ( ab_user ) . to eq ( experiment . key => alternative , experiment . finished_key => true )
343+ expect ( ab_user [ experiment . key ] ) . to eq ( alternative )
344+ expect ( ab_user [ experiment . finished_key ] ) . to eq ( true )
341345 end
342346 end
343347
@@ -618,28 +622,28 @@ def should_finish_experiment(experiment_name, should_finish=true)
618622 it "should use version zero if no version is present" do
619623 alternative_name = ab_test ( 'link_color' , 'blue' , 'red' )
620624 expect ( experiment . version ) . to eq ( 0 )
621- expect ( ab_user ) . to eq ( { 'link_color' => alternative_name } )
625+ expect ( ab_user [ 'link_color' ] ) . to eq ( alternative_name )
622626 end
623627
624628 it "should save the version of the experiment to the session" do
625629 experiment . reset
626630 expect ( experiment . version ) . to eq ( 1 )
627631 alternative_name = ab_test ( 'link_color' , 'blue' , 'red' )
628- expect ( ab_user ) . to eq ( { 'link_color:1' => alternative_name } )
632+ expect ( ab_user [ 'link_color:1' ] ) . to eq ( alternative_name )
629633 end
630634
631635 it "should load the experiment even if the version is not 0" do
632636 experiment . reset
633637 expect ( experiment . version ) . to eq ( 1 )
634638 alternative_name = ab_test ( 'link_color' , 'blue' , 'red' )
635- expect ( ab_user ) . to eq ( { 'link_color:1' => alternative_name } )
639+ expect ( ab_user [ 'link_color:1' ] ) . to eq ( alternative_name )
636640 return_alternative_name = ab_test ( 'link_color' , 'blue' , 'red' )
637641 expect ( return_alternative_name ) . to eq ( alternative_name )
638642 end
639643
640644 it "should reset the session of a user on an older version of the experiment" do
641645 alternative_name = ab_test ( 'link_color' , 'blue' , 'red' )
642- expect ( ab_user ) . to eq ( { 'link_color' => alternative_name } )
646+ expect ( ab_user [ 'link_color' ] ) . to eq ( alternative_name )
643647 alternative = Split ::Alternative . new ( alternative_name , 'link_color' )
644648 expect ( alternative . participant_count ) . to eq ( 1 )
645649
@@ -656,7 +660,7 @@ def should_finish_experiment(experiment_name, should_finish=true)
656660
657661 it "should cleanup old versions of experiments from the session" do
658662 alternative_name = ab_test ( 'link_color' , 'blue' , 'red' )
659- expect ( ab_user ) . to eq ( { 'link_color' => alternative_name } )
663+ expect ( ab_user [ 'link_color' ] ) . to eq ( alternative_name )
660664 alternative = Split ::Alternative . new ( alternative_name , 'link_color' )
661665 expect ( alternative . participant_count ) . to eq ( 1 )
662666
@@ -666,12 +670,12 @@ def should_finish_experiment(experiment_name, should_finish=true)
666670 expect ( alternative . participant_count ) . to eq ( 0 )
667671
668672 new_alternative_name = ab_test ( 'link_color' , 'blue' , 'red' )
669- expect ( ab_user ) . to eq ( { 'link_color:1' => new_alternative_name } )
673+ expect ( ab_user [ 'link_color:1' ] ) . to eq ( new_alternative_name )
670674 end
671675
672676 it "should only count completion of users on the current version" do
673677 alternative_name = ab_test ( 'link_color' , 'blue' , 'red' )
674- expect ( ab_user ) . to eq ( { 'link_color' => alternative_name } )
678+ expect ( ab_user [ 'link_color' ] ) . to eq ( alternative_name )
675679 alternative = Split ::Alternative . new ( alternative_name , 'link_color' )
676680
677681 experiment . reset
0 commit comments