|
| 1 | +# frozen_string_literal: true |
| 2 | +require 'spec_helper' |
| 3 | +require 'split/combined_experiments_helper' |
| 4 | + |
| 5 | +describe Split::CombinedExperimentsHelper do |
| 6 | + include Split::CombinedExperimentsHelper |
| 7 | + |
| 8 | + describe 'ab_combined_test' do |
| 9 | + let!(:config_enabled) { true } |
| 10 | + let!(:combined_experiments) { [:exp_1_click, :exp_1_scroll ]} |
| 11 | + let!(:allow_multiple_experiments) { true } |
| 12 | + |
| 13 | + before do |
| 14 | + Split.configuration.experiments = { |
| 15 | + :combined_exp_1 => { |
| 16 | + :alternatives => [ {"control"=> 0.5}, {"test-alt"=> 0.5} ], |
| 17 | + :metric => :my_metric, |
| 18 | + :combined_experiments => combined_experiments |
| 19 | + } |
| 20 | + } |
| 21 | + Split.configuration.enabled = config_enabled |
| 22 | + Split.configuration.allow_multiple_experiments = allow_multiple_experiments |
| 23 | + end |
| 24 | + |
| 25 | + context 'without config enabled' do |
| 26 | + let!(:config_enabled) { false } |
| 27 | + |
| 28 | + it "raises an error" do |
| 29 | + expect(lambda { ab_combined_test :combined_exp_1 }).to raise_error(Split::InvalidExperimentsFormatError ) |
| 30 | + end |
| 31 | + end |
| 32 | + |
| 33 | + context 'multiple experiments disabled' do |
| 34 | + let!(:allow_multiple_experiments) { false } |
| 35 | + |
| 36 | + it "raises an error if multiple experiments is disabled" do |
| 37 | + expect(lambda { ab_combined_test :combined_exp_1 }).to raise_error(Split::InvalidExperimentsFormatError) |
| 38 | + end |
| 39 | + end |
| 40 | + |
| 41 | + context 'without combined experiments' do |
| 42 | + let!(:combined_experiments) { nil } |
| 43 | + |
| 44 | + it "raises an error" do |
| 45 | + expect(lambda { ab_combined_test :combined_exp_1 }).to raise_error(Split::InvalidExperimentsFormatError ) |
| 46 | + end |
| 47 | + end |
| 48 | + |
| 49 | + it "uses same alternatives for all sub experiments " do |
| 50 | + allow(self).to receive(:get_alternative) { "test-alt" } |
| 51 | + expect(self).to receive(:ab_test).with(:exp_1_click, {"control"=>0.5}, {"test-alt"=>0.5}) { "test-alt" } |
| 52 | + expect(self).to receive(:ab_test).with(:exp_1_scroll, [{"test-alt" => 1}] ) |
| 53 | + |
| 54 | + ab_combined_test('combined_exp_1') |
| 55 | + end |
| 56 | + end |
| 57 | +end |
0 commit comments