blob: 7b1d1763010ed27b273afb6c9892f07a6ad367e8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Experimentation::Experiment do
using RSpec::Parameterized::TableSyntax
let(:percentage) { 50 }
let(:params) do
{
tracking_category: 'Category1',
use_backwards_compatible_subject_index: true
}
end
before do
feature = double('FeatureFlag', percentage_of_time_value: percentage )
expect(Feature).to receive(:get).with(:experiment_key_experiment_percentage).and_return(feature)
end
subject(:experiment) { described_class.new(:experiment_key, **params) }
describe '#active?' do
before do
allow(Gitlab).to receive(:dev_env_or_com?).and_return(on_gitlab_com)
end
subject { experiment.active? }
where(:on_gitlab_com, :percentage, :is_active) do
true | 0 | false
true | 10 | true
false | 0 | false
false | 10 | false
end
with_them do
it { is_expected.to eq(is_active) }
end
end
describe '#enabled_for_index?' do
subject { experiment.enabled_for_index?(index) }
where(:index, :percentage, :is_enabled) do
50 | 40 | false
40 | 50 | true
nil | 50 | false
end
with_them do
it { is_expected.to eq(is_enabled) }
end
end
end
|