Skip to content

Commit a663a33

Browse files
authored
Merge pull request #677 from splitrb/fix-spec-deprecations
Remove usage of deprecated implicit block expectation from specs
2 parents c4a3e22 + 49bf6c2 commit a663a33

File tree

5 files changed

+33
-32
lines changed

5 files changed

+33
-32
lines changed

spec/combined_experiments_helper_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,23 @@
2626
let!(:config_enabled) { false }
2727

2828
it "raises an error" do
29-
expect(lambda { ab_combined_test :combined_exp_1 }).to raise_error(Split::InvalidExperimentsFormatError )
29+
expect { ab_combined_test :combined_exp_1 }.to raise_error(Split::InvalidExperimentsFormatError )
3030
end
3131
end
3232

3333
context 'multiple experiments disabled' do
3434
let!(:allow_multiple_experiments) { false }
3535

3636
it "raises an error if multiple experiments is disabled" do
37-
expect(lambda { ab_combined_test :combined_exp_1 }).to raise_error(Split::InvalidExperimentsFormatError)
37+
expect { ab_combined_test :combined_exp_1 }.to raise_error(Split::InvalidExperimentsFormatError)
3838
end
3939
end
4040

4141
context 'without combined experiments' do
4242
let!(:combined_experiments) { nil }
4343

4444
it "raises an error" do
45-
expect(lambda { ab_combined_test :combined_exp_1 }).to raise_error(Split::InvalidExperimentsFormatError )
45+
expect { ab_combined_test :combined_exp_1 }.to raise_error(Split::InvalidExperimentsFormatError )
4646
end
4747
end
4848

spec/encapsulated_helper_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def params
1717

1818
it "should not raise an error when params raises an error" do
1919
expect{ params }.to raise_error(NoMethodError)
20-
expect(lambda { ab_test('link_color', 'blue', 'red') }).not_to raise_error
20+
expect { ab_test('link_color', 'blue', 'red') }.not_to raise_error
2121
end
2222

2323
it "calls the block with selected alternative" do

spec/experiment_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,8 +494,8 @@ def same_but_different_alternative
494494

495495
describe 'alternatives passed as non-strings' do
496496
it "should throw an exception if an alternative is passed that is not a string" do
497-
expect(lambda { Split::ExperimentCatalog.find_or_create('link_color', :blue, :red) }).to raise_error(ArgumentError)
498-
expect(lambda { Split::ExperimentCatalog.find_or_create('link_enabled', true, false) }).to raise_error(ArgumentError)
497+
expect { Split::ExperimentCatalog.find_or_create('link_color', :blue, :red) }.to raise_error(ArgumentError)
498+
expect { Split::ExperimentCatalog.find_or_create('link_enabled', true, false) }.to raise_error(ArgumentError)
499499
end
500500
end
501501

spec/helper_spec.rb

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,27 @@
1212

1313
describe "ab_test" do
1414
it "should not raise an error when passed strings for alternatives" do
15-
expect(lambda { ab_test('xyz', '1', '2', '3') }).not_to raise_error
15+
expect { ab_test('xyz', '1', '2', '3') }.not_to raise_error
1616
end
1717

1818
it "should not raise an error when passed an array for alternatives" do
19-
expect(lambda { ab_test('xyz', ['1', '2', '3']) }).not_to raise_error
19+
expect { ab_test('xyz', ['1', '2', '3']) }.not_to raise_error
2020
end
2121

2222
it "should raise the appropriate error when passed integers for alternatives" do
23-
expect(lambda { ab_test('xyz', 1, 2, 3) }).to raise_error(ArgumentError)
23+
expect { ab_test('xyz', 1, 2, 3) }.to raise_error(ArgumentError)
2424
end
2525

2626
it "should raise the appropriate error when passed symbols for alternatives" do
27-
expect(lambda { ab_test('xyz', :a, :b, :c) }).to raise_error(ArgumentError)
27+
expect { ab_test('xyz', :a, :b, :c) }.to raise_error(ArgumentError)
2828
end
2929

3030
it "should not raise error when passed an array for goals" do
31-
expect(lambda { ab_test({'link_color' => ["purchase", "refund"]}, 'blue', 'red') }).not_to raise_error
31+
expect { ab_test({'link_color' => ["purchase", "refund"]}, 'blue', 'red') }.not_to raise_error
3232
end
3333

3434
it "should not raise error when passed just one goal" do
35-
expect(lambda { ab_test({'link_color' => "purchase"}, 'blue', 'red') }).not_to raise_error
35+
expect { ab_test({'link_color' => "purchase"}, 'blue', 'red') }.not_to raise_error
3636
end
3737

3838
it "raises an appropriate error when processing combined expirements" do
@@ -44,7 +44,7 @@
4444
}
4545
}
4646
Split::ExperimentCatalog.find_or_create('combined_exp_1')
47-
expect(lambda { ab_test('combined_exp_1')}).to raise_error(Split::InvalidExperimentsFormatError )
47+
expect { ab_test('combined_exp_1') }.to raise_error(Split::InvalidExperimentsFormatError )
4848
end
4949

5050
it "should assign a random alternative to a new user when there are an equal number of alternatives assigned" do
@@ -67,28 +67,28 @@
6767
it 'should not increment the counter for an experiment that the user is not participating in' do
6868
ab_test('link_color', 'blue', 'red')
6969
e = Split::ExperimentCatalog.find_or_create('button_size', 'small', 'big')
70-
expect(lambda {
70+
expect {
7171
# User shouldn't participate in this second experiment
7272
ab_test('button_size', 'small', 'big')
73-
}).not_to change { e.participant_count }
73+
}.not_to change { e.participant_count }
7474
end
7575

7676
it 'should not increment the counter for an ended experiment' do
7777
e = Split::ExperimentCatalog.find_or_create('button_size', 'small', 'big')
7878
e.winner = 'small'
79-
expect(lambda {
79+
expect {
8080
a = ab_test('button_size', 'small', 'big')
8181
expect(a).to eq('small')
82-
}).not_to change { e.participant_count }
82+
}.not_to change { e.participant_count }
8383
end
8484

8585
it 'should not increment the counter for an not started experiment' do
8686
expect(Split.configuration).to receive(:start_manually).and_return(true)
8787
e = Split::ExperimentCatalog.find_or_create('button_size', 'small', 'big')
88-
expect(lambda {
88+
expect {
8989
a = ab_test('button_size', 'small', 'big')
9090
expect(a).to eq('small')
91-
}).not_to change { e.participant_count }
91+
}.not_to change { e.participant_count }
9292
end
9393

9494
it "should return the given alternative for an existing user" do
@@ -370,9 +370,9 @@
370370
e.winner = 'small'
371371
a = ab_test('button_size', 'small', 'big')
372372
expect(a).to eq('small')
373-
expect(lambda {
373+
expect {
374374
ab_finished('button_size')
375-
}).not_to change { Split::Alternative.new(a, 'button_size').completed_count }
375+
}.not_to change { Split::Alternative.new(a, 'button_size').completed_count }
376376
end
377377

378378
it "should clear out the user's participation from their session" do
@@ -431,9 +431,9 @@
431431
# receive the control for button_size. As the user is not participating in
432432
# the button size experiment, finishing it should not increase the
433433
# completion count for that alternative.
434-
expect(lambda {
434+
expect {
435435
ab_finished('button_size')
436-
}).not_to change { Split::Alternative.new('small', 'button_size').completed_count }
436+
}.not_to change { Split::Alternative.new('small', 'button_size').completed_count }
437437
end
438438
end
439439

@@ -875,13 +875,13 @@ def should_finish_experiment(experiment_name, should_finish=true)
875875

876876
describe 'ab_test' do
877877
it 'should raise an exception' do
878-
expect(lambda { ab_test('link_color', 'blue', 'red') }).to raise_error(Errno::ECONNREFUSED)
878+
expect { ab_test('link_color', 'blue', 'red') }.to raise_error(Errno::ECONNREFUSED)
879879
end
880880
end
881881

882882
describe 'finished' do
883883
it 'should raise an exception' do
884-
expect(lambda { ab_finished('link_color') }).to raise_error(Errno::ECONNREFUSED)
884+
expect { ab_finished('link_color') }.to raise_error(Errno::ECONNREFUSED)
885885
end
886886
end
887887

@@ -893,12 +893,12 @@ def should_finish_experiment(experiment_name, should_finish=true)
893893
end
894894

895895
it "should not attempt to connect to redis" do
896-
expect(lambda { ab_test('link_color', 'blue', 'red') }).not_to raise_error
896+
expect { ab_test('link_color', 'blue', 'red') }.not_to raise_error
897897
end
898898

899899
it "should return control variable" do
900900
expect(ab_test('link_color', 'blue', 'red')).to eq('blue')
901-
expect(lambda { ab_finished('link_color') }).not_to raise_error
901+
expect { ab_finished('link_color') }.not_to raise_error
902902
end
903903
end
904904
end
@@ -912,7 +912,7 @@ def should_finish_experiment(experiment_name, should_finish=true)
912912

913913
describe 'ab_test' do
914914
it 'should not raise an exception' do
915-
expect(lambda { ab_test('link_color', 'blue', 'red') }).not_to raise_error
915+
expect { ab_test('link_color', 'blue', 'red') }.not_to raise_error
916916
end
917917

918918
it 'should call db_failover_on_db_error proc with error as parameter' do
@@ -971,7 +971,7 @@ def should_finish_experiment(experiment_name, should_finish=true)
971971

972972
describe 'finished' do
973973
it 'should not raise an exception' do
974-
expect(lambda { ab_finished('link_color') }).not_to raise_error
974+
expect { ab_finished('link_color') }.not_to raise_error
975975
end
976976

977977
it 'should call db_failover_on_db_error proc with error as parameter' do
@@ -1086,16 +1086,16 @@ def should_finish_experiment(experiment_name, should_finish=true)
10861086

10871087
it "fails gracefully if config is missing experiment" do
10881088
Split.configuration.experiments = { :other_experiment => { :foo => "Bar" } }
1089-
expect(lambda { ab_test :my_experiment }).to raise_error(Split::ExperimentNotFound)
1089+
expect { ab_test :my_experiment }.to raise_error(Split::ExperimentNotFound)
10901090
end
10911091

10921092
it "fails gracefully if config is missing" do
1093-
expect(lambda { Split.configuration.experiments = nil }).to raise_error(Split::InvalidExperimentsFormatError)
1093+
expect { Split.configuration.experiments = nil }.to raise_error(Split::InvalidExperimentsFormatError)
10941094
end
10951095

10961096
it "fails gracefully if config is missing alternatives" do
10971097
Split.configuration.experiments[:my_experiment] = { :foo => "Bar" }
1098-
expect(lambda { ab_test :my_experiment }).to raise_error(NoMethodError)
1098+
expect { ab_test :my_experiment }.to raise_error(NoMethodError)
10991099
end
11001100
end
11011101

spec/spec_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ module GlobalSharedContext
3131
RSpec.configure do |config|
3232
config.order = 'random'
3333
config.include GlobalSharedContext
34+
config.raise_errors_for_deprecations!
3435
end
3536

3637
def session

0 commit comments

Comments
 (0)