gitlab-experiment 0.4.6 → 0.4.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 51c0f257bd0cea5fa7b970e764ac5cce9f24c5a844673f05579d1c902a46fc39
4
- data.tar.gz: ddd93dc46cdde532f20edd5209651d511105157ee9dd13d58c5a60cb229cd3ca
3
+ metadata.gz: a26425622afb7aa3f341ff403192963e276876b65902237018f852117168a19a
4
+ data.tar.gz: 0a5238c73a4b0217810b4f8161df6452b683b21a6573f1b657517302cef9cef0
5
5
  SHA512:
6
- metadata.gz: 243606b6b55ebe069296c564ad801a6b25075a85d2b2ca38eb47e836b75b655fa9472fbcf0a0cb01c83093b97d529f8b2aec04389d79119064b5021c975b0042
7
- data.tar.gz: 1900d8b44458d2cf1e2086cc48d5e3ccc19160926c1dc9b827b7a93d042edf7354e1eeb35cae12e0c33f133aef39f605dbd5446edf987c1d99a38264d3b97d72
6
+ metadata.gz: 567ca93e3f931c167bc1766490b07e1535db72e3b5da5986715412746354945ed799dab4c075e91c5015aa922bf5d7e5a82bdc940808aa8100c8897d5ee623b7
7
+ data.tar.gz: 3f053ed2ad8bdfc2201aacaef9c723332fba260f4f4cb54c65a92539d74ec100297540c34c97579c99723f0d98e98dc57cbe383a0731128d623b0a58b4786d7c
data/README.md CHANGED
@@ -15,7 +15,7 @@ When we discuss the behavior of this gem, we'll use terms like experiment, conte
15
15
  - `candidate` defines that there's one experimental code path.
16
16
  - `variant(s)` is used when more than one experimental code path exists.
17
17
 
18
- Candidate and variant are the same concept, but simplify how we speak about experimental paths.<br clear="all">
18
+ Candidate and variant are the same concept, but simplify how we speak about experimental paths -- this concept is also widely referred to as the "experiment group".<br clear="all">
19
19
 
20
20
  [[_TOC_]]
21
21
 
@@ -148,12 +148,6 @@ module Gitlab
148
148
  "Experiment;#{id}"
149
149
  end
150
150
 
151
- def key_for(hash)
152
- instance_exec(hash, &Configuration.context_hash_strategy)
153
- end
154
-
155
- protected
156
-
157
151
  def enabled?
158
152
  true
159
153
  end
@@ -167,6 +161,12 @@ module Gitlab
167
161
  enabled? && !excluded?
168
162
  end
169
163
 
164
+ def key_for(hash)
165
+ instance_exec(hash, &Configuration.context_hash_strategy)
166
+ end
167
+
168
+ protected
169
+
170
170
  def run_with_segmenting?
171
171
  !variant_assigned? && enabled? && !excluded?
172
172
  end
@@ -2,7 +2,26 @@
2
2
 
3
3
  module Gitlab
4
4
  class Experiment
5
- module RspecMatchers
5
+ module RSpecHelpers
6
+ def stub_experiments(experiments)
7
+ experiments.each do |name, variant|
8
+ variant = :control if variant == false
9
+ raise ArgumentError, 'variant must be a symbol or false' unless variant.is_a?(Symbol)
10
+
11
+ klass = Gitlab::Experiment.send(:constantize, name) # rubocop:disable GitlabSecurity/PublicSend
12
+ allow(klass).to receive(:new).and_wrap_original do |new, *args, &block|
13
+ new.call(*args).tap do |instance|
14
+ allow(instance).to receive(:enabled?).and_return(true)
15
+ allow(instance).to receive(:resolve_variant_name).and_return(variant.to_s)
16
+
17
+ block.call(instance) if block.present?
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ module RSpecMatchers
6
25
  extend RSpec::Matchers::DSL
7
26
 
8
27
  matcher :exclude do |context|
@@ -83,9 +102,10 @@ module Gitlab
83
102
  end
84
103
 
85
104
  RSpec.configure do |config|
86
- config.define_derived_metadata(file_path: Regexp.new('/spec/experiments/')) do |metadata|
105
+ config.include Gitlab::Experiment::RSpecHelpers
106
+
107
+ config.include Gitlab::Experiment::RSpecMatchers, :experiment
108
+ config.define_derived_metadata(file_path: %r{/spec/experiments/}) do |metadata|
87
109
  metadata[:type] = :experiment
88
110
  end
89
-
90
- config.include Gitlab::Experiment::RspecMatchers, :experiment
91
111
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Gitlab
4
4
  class Experiment
5
- VERSION = '0.4.6'
5
+ VERSION = '0.4.7'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab-experiment
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.6
4
+ version: 0.4.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitLab
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-21 00:00:00.000000000 Z
11
+ date: 2021-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -72,7 +72,7 @@ files:
72
72
  - lib/gitlab/experiment/cookies.rb
73
73
  - lib/gitlab/experiment/dsl.rb
74
74
  - lib/gitlab/experiment/engine.rb
75
- - lib/gitlab/experiment/rspec_matchers.rb
75
+ - lib/gitlab/experiment/rspec.rb
76
76
  - lib/gitlab/experiment/variant.rb
77
77
  - lib/gitlab/experiment/version.rb
78
78
  homepage: https://gitlab.com/gitlab-org/gitlab-experiment