diff options
Diffstat (limited to 'spec/lib/gitlab/experimentation_spec.rb')
-rw-r--r-- | spec/lib/gitlab/experimentation_spec.rb | 65 |
1 files changed, 63 insertions, 2 deletions
diff --git a/spec/lib/gitlab/experimentation_spec.rb b/spec/lib/gitlab/experimentation_spec.rb index b503960b8c7..4ef8a75de4f 100644 --- a/spec/lib/gitlab/experimentation_spec.rb +++ b/spec/lib/gitlab/experimentation_spec.rb @@ -15,8 +15,7 @@ RSpec.describe Gitlab::Experimentation::EXPERIMENTS do :invite_members_empty_group_version_a, :contact_sales_btn_in_app, :customize_homepage, - :group_only_trials, - :default_to_issues_board + :group_only_trials ] backwards_compatible_experiment_keys = described_class.filter { |_, v| v[:use_backwards_compatible_subject_index] }.keys @@ -27,6 +26,8 @@ RSpec.describe Gitlab::Experimentation::EXPERIMENTS do end RSpec.describe Gitlab::Experimentation do + using RSpec::Parameterized::TableSyntax + before do stub_const('Gitlab::Experimentation::EXPERIMENTS', { backwards_compatible_test_experiment: { @@ -35,6 +36,10 @@ RSpec.describe Gitlab::Experimentation do }, test_experiment: { tracking_category: 'Team' + }, + tabular_experiment: { + tracking_category: 'Team', + rollout_strategy: rollout_strategy } }) @@ -46,6 +51,7 @@ RSpec.describe Gitlab::Experimentation do end let(:enabled_percentage) { 10 } + let(:rollout_strategy) { nil } describe '.get_experiment' do subject { described_class.get_experiment(:test_experiment) } @@ -175,4 +181,59 @@ RSpec.describe Gitlab::Experimentation do end end end + + describe '.log_invalid_rollout' do + subject { described_class.log_invalid_rollout(:test_experiment, 1) } + + before do + allow(described_class).to receive(:valid_subject_for_rollout_strategy?).and_return(valid) + end + + context 'subject is not valid for experiment' do + let(:valid) { false } + + it 'logs a warning message' do + expect_next_instance_of(Gitlab::ExperimentationLogger) do |logger| + expect(logger) + .to receive(:warn) + .with( + message: 'Subject must conform to the rollout strategy', + experiment_key: :test_experiment, + subject: 'Integer', + rollout_strategy: :cookie + ) + end + + subject + end + end + + context 'subject is valid for experiment' do + let(:valid) { true } + + it 'does not log a warning message' do + expect(Gitlab::ExperimentationLogger).not_to receive(:build) + + subject + end + end + end + + describe '.valid_subject_for_rollout_strategy?' do + subject { described_class.valid_subject_for_rollout_strategy?(:tabular_experiment, experiment_subject) } + + where(:rollout_strategy, :experiment_subject, :result) do + :cookie | nil | true + nil | nil | true + :cookie | 'string' | true + nil | User.new | false + :user | User.new | true + :group | User.new | false + :group | Group.new | true + end + + with_them do + it { is_expected.to be(result) } + end + end end |