govuk_ab_testing 2.2.0 → 2.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +7 -2
- data/.ruby-version +1 -1
- data/CHANGELOG.md +42 -0
- data/Gemfile +1 -1
- data/Jenkinsfile +2 -1
- data/README.md +48 -16
- data/Rakefile +5 -7
- data/govuk_ab_testing.gemspec +9 -11
- data/lib/govuk_ab_testing.rb +12 -12
- data/lib/govuk_ab_testing/ab_test.rb +8 -1
- data/lib/govuk_ab_testing/abstract_helpers.rb +7 -7
- data/lib/govuk_ab_testing/acceptance_tests/active_support.rb +21 -9
- data/lib/govuk_ab_testing/acceptance_tests/capybara.rb +6 -4
- data/lib/govuk_ab_testing/configuration.rb +4 -4
- data/lib/govuk_ab_testing/requested_variant.rb +28 -5
- data/lib/govuk_ab_testing/rspec_assertions.rb +1 -0
- data/lib/govuk_ab_testing/version.rb +1 -1
- metadata +20 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cf9c70a0d36f4d97dec173bfc21738a3266700997a1af70cf3e5fac2b654c313
|
4
|
+
data.tar.gz: 7d63ce7fe82da0f11076b29498a6188691ee765bad005805bfecdea1fc022894
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 59ca9f4101ddea9d142c492052ceedc08af2a29e35601a25afd6e057e976ab4e7745ca9dac4b27156210122314df78da84ee4d42c84fd09fef32ec56a9017ae7
|
7
|
+
data.tar.gz: 9543b01d05c4e12ed4b8c0c029b3c5ff2e313b283541b47cdef0d2135c5273938d5cdcb5304981320e58a99a2399d92749729f2fc76680bbecfca60c6e938fab
|
data/.rubocop.yml
CHANGED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.6.6
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,45 @@
|
|
1
|
+
## 2.4.2
|
2
|
+
|
3
|
+
* Updated gem dependencies and development ruby version to 2.6.6
|
4
|
+
* Fixed new rubocop violations
|
5
|
+
|
6
|
+
## 2.4.1
|
7
|
+
|
8
|
+
* Add extra validation to ActiveSupport assertions to help debug test failures.
|
9
|
+
In order to make assertions about the `meta` tags, the view must be rendered
|
10
|
+
in the test. RSpec Rails tests do not do this by default, so you need to call
|
11
|
+
`render_views` explicitly. Without this check, tests fail with a cryptic error
|
12
|
+
message "undefined method 'document' for nil:NilClass".
|
13
|
+
|
14
|
+
## 2.4.0
|
15
|
+
|
16
|
+
* Add two new optional parameters to `GovukAbTesting::AbTest`:
|
17
|
+
`allowed_variants` and `control_variant`. These allow us to override the
|
18
|
+
traditional naming of the A/B tests and also setup a multivariate test if
|
19
|
+
needed.
|
20
|
+
* Add new method to `RequestedVariant` to query if a user is in a given variant.
|
21
|
+
The method is `variant?(name)`, where `name` is the name of the variant.
|
22
|
+
This new method allows for generic variant names, which are useful when
|
23
|
+
reusing A/B testing cookies/headers. If the cookie name and header name are
|
24
|
+
generic, the variant value should provide details on what test is running.
|
25
|
+
* Add deprecation warnings to `variant_a?` and `variant_b?`, as they will be
|
26
|
+
replaced by the method `variant?(name)`.
|
27
|
+
|
28
|
+
## 2.3.1
|
29
|
+
|
30
|
+
* Fix bug in order to allow us to set multiple headers (i.e. A/B tests) in a
|
31
|
+
test using Capybara. This is important when running multiple A/B tests at
|
32
|
+
once.
|
33
|
+
|
34
|
+
## 2.3.0
|
35
|
+
|
36
|
+
* Fix for Rails 5.0.2 - the Active Support acceptance tests used to memoize
|
37
|
+
the `@request` and `@response` objects. This worked fine in Rails 4, but
|
38
|
+
it looks like Rails 5 now points to a different object at some point during
|
39
|
+
the request/response lifecycle, breaking the memoization. The fix removes
|
40
|
+
this memoization and directly queries the scope for each `@request` or
|
41
|
+
`@response`.
|
42
|
+
|
1
43
|
## 2.2.0
|
2
44
|
|
3
45
|
* Remove string interpolated parameter in error message of
|
data/Gemfile
CHANGED
data/Jenkinsfile
CHANGED
data/README.md
CHANGED
@@ -18,12 +18,9 @@ And then execute:
|
|
18
18
|
|
19
19
|
### Usage
|
20
20
|
|
21
|
-
Before starting this, you'll need to
|
21
|
+
Before starting this, you'll need to:
|
22
22
|
|
23
|
-
-
|
24
|
-
- configure the CDN [like we did for the Education Navigation test](https://github.com/alphagov/govuk-cdn-config/pull/17).
|
25
|
-
The cookie and header name in the CDN config must match the test name parameter
|
26
|
-
that you pass to the Gem. The cookie name is case-sensitive.
|
23
|
+
- [read the documentation](https://docs.publishing.service.gov.uk/manual/ab-testing.html) on how to set up an a/b test. The cookie and header name in [fastly-configure](https://github.com/alphagov/fastly-configure) and [CDN config](https://github.digital.cabinet-office.gov.uk/gds/cdn-configs) must match the test name parameter that you pass to the Gem. The cookie name is case-sensitive.
|
27
24
|
- configure Google Analytics (guidelines to follow)
|
28
25
|
|
29
26
|
To enable testing in the app, your Rails app needs:
|
@@ -53,12 +50,20 @@ Now, let's say you have this controller:
|
|
53
50
|
# app/controllers/party_controller.rb
|
54
51
|
class PartyController < ApplicationController
|
55
52
|
def show
|
56
|
-
ab_test = GovukAbTesting::AbTest.new(
|
53
|
+
ab_test = GovukAbTesting::AbTest.new(
|
54
|
+
"your_ab_test_name",
|
55
|
+
dimension: 300,
|
56
|
+
allowed_variants: ['NoChange', 'LongTitle', 'ShortTitle'],
|
57
|
+
control_variant: 'NoChange'
|
58
|
+
)
|
57
59
|
@requested_variant = ab_test.requested_variant(request.headers)
|
58
60
|
@requested_variant.configure_response(response)
|
59
61
|
|
60
|
-
|
61
|
-
|
62
|
+
case true
|
63
|
+
when @requested_variant.variant?('LongTitle')
|
64
|
+
render "show_template_with_long_title"
|
65
|
+
when @requested_variant.variant?('ShortTitle')
|
66
|
+
render "show_template_with_short_title"
|
62
67
|
else
|
63
68
|
render "show"
|
64
69
|
end
|
@@ -66,7 +71,11 @@ class PartyController < ApplicationController
|
|
66
71
|
end
|
67
72
|
```
|
68
73
|
|
69
|
-
|
74
|
+
In this example, we are running a multivariate test with 3 options being
|
75
|
+
tested: the existing version (control), and two title changes. The minimum
|
76
|
+
number of variants in any test should be two.
|
77
|
+
|
78
|
+
Then, add this to your layouts, so that we have a meta tag that can be picked up
|
70
79
|
by the extension and analytics.
|
71
80
|
|
72
81
|
```html
|
@@ -76,6 +85,9 @@ by the extension and analytics.
|
|
76
85
|
</head>
|
77
86
|
```
|
78
87
|
|
88
|
+
The analytics meta tag will include the allowed variants so the extension knows
|
89
|
+
which variants to suggest the user.
|
90
|
+
|
79
91
|
#### Test helpers
|
80
92
|
|
81
93
|
##### Minitest
|
@@ -160,7 +172,7 @@ end
|
|
160
172
|
##### RSpec
|
161
173
|
|
162
174
|
It is also possible to use `with_variant` and all the individual setup and
|
163
|
-
assertions steps in RSpec tests. Here is an example of a
|
175
|
+
assertions steps in RSpec tests. Here is an example of a Capybara feature file:
|
164
176
|
|
165
177
|
```ruby
|
166
178
|
# spec/features/ab_testing_spec.rb
|
@@ -178,22 +190,42 @@ feature "Viewing a page with an A/B test" do
|
|
178
190
|
end
|
179
191
|
```
|
180
192
|
|
193
|
+
And here is an RSpec controller test:
|
194
|
+
|
195
|
+
```ruby
|
196
|
+
# spec/controllers/some_controller_spec.rb
|
197
|
+
describe SomeController, type :controller do
|
198
|
+
include GovukAbTesting::RspecHelpers
|
199
|
+
|
200
|
+
# RSpec doesn't render views for controller specs by default
|
201
|
+
render_views
|
202
|
+
|
203
|
+
it "should render the B version of the page" do
|
204
|
+
with_variant your_ab_test_name: 'B' do
|
205
|
+
get :index
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
```
|
210
|
+
|
181
211
|
As with the `minitest` version, you can also pass in the following options to
|
182
212
|
`with_variant`:
|
183
213
|
|
184
214
|
- `assert_meta_tag: false`
|
185
215
|
- `dimension: <number>`
|
186
216
|
|
187
|
-
### Current limitations
|
188
|
-
|
189
|
-
This library assumes we are only using one A/B test per page. The acceptance
|
190
|
-
test classes look for only one analytics' meta tag and will fail in the presence
|
191
|
-
of more than one.
|
192
|
-
|
193
217
|
### Running the test suite
|
194
218
|
|
195
219
|
`bundle exec rake`
|
196
220
|
|
221
|
+
### Testing in a browser
|
222
|
+
|
223
|
+
If you want to test this behaviour in a browser then you should use the
|
224
|
+
[GOV.UK Toolkit for Chrome](https://github.com/alphagov/govuk-toolkit-chrome).
|
225
|
+
|
226
|
+
This detects when you have a test running on a page and enables you to choose
|
227
|
+
between variants.
|
228
|
+
|
197
229
|
### Documentation
|
198
230
|
|
199
231
|
See [RubyDoc](http://www.rubydoc.info/gems/govuk_ab_testing) for some limited documentation.
|
data/Rakefile
CHANGED
@@ -1,13 +1,11 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
2
|
require "rspec/core/rake_task"
|
3
|
-
require "
|
3
|
+
require "rubocop/rake_task"
|
4
4
|
|
5
|
+
RuboCop::RakeTask.new
|
5
6
|
RSpec::Core::RakeTask.new(:spec)
|
6
7
|
|
7
|
-
|
8
|
+
desc "Linting for Ruby"
|
9
|
+
task lint: :rubocop
|
8
10
|
|
9
|
-
|
10
|
-
task :publish_gem do |_t|
|
11
|
-
published_gem = GemPublisher.publish_if_updated("govuk_ab_testing.gemspec", :rubygems)
|
12
|
-
puts "Published #{published_gem}" if published_gem
|
13
|
-
end
|
11
|
+
task default: %i[lint spec]
|
data/govuk_ab_testing.gemspec
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
3
|
+
require "govuk_ab_testing/version"
|
5
4
|
|
6
5
|
Gem::Specification.new do |spec|
|
7
6
|
spec.name = "govuk_ab_testing"
|
@@ -9,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
9
8
|
spec.authors = ["GOV.UK Dev"]
|
10
9
|
spec.email = ["govuk-dev@digital.cabinet-office.gov.uk"]
|
11
10
|
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
11
|
+
spec.summary = "Gem to help with A/B testing on the GOV.UK platform"
|
12
|
+
spec.description = "Gem to help with A/B testing on the GOV.UK platform"
|
14
13
|
spec.homepage = "https://github.com/alphagov/govuk_ab_testing"
|
15
14
|
spec.license = "MIT"
|
16
15
|
|
@@ -19,11 +18,10 @@ Gem::Specification.new do |spec|
|
|
19
18
|
end
|
20
19
|
spec.bindir = "exe"
|
21
20
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
-
spec.require_paths = [
|
21
|
+
spec.require_paths = %w[lib]
|
23
22
|
|
24
|
-
spec.add_development_dependency "rake"
|
25
|
-
spec.add_development_dependency "rspec"
|
26
|
-
spec.add_development_dependency "govuk
|
27
|
-
spec.add_development_dependency "yard"
|
28
|
-
spec.add_development_dependency "gem_publisher", "~> 1.5.0"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
spec.add_development_dependency "rspec"
|
25
|
+
spec.add_development_dependency "rubocop-govuk"
|
26
|
+
spec.add_development_dependency "yard"
|
29
27
|
end
|
data/lib/govuk_ab_testing.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
1
|
+
require "govuk_ab_testing/version"
|
2
|
+
require "govuk_ab_testing/configuration"
|
3
|
+
require "govuk_ab_testing/requested_variant"
|
4
|
+
require "govuk_ab_testing/ab_test"
|
5
|
+
require "govuk_ab_testing/minitest_assertions"
|
6
|
+
require "govuk_ab_testing/rspec_assertions"
|
7
|
+
require "govuk_ab_testing/abstract_helpers"
|
8
|
+
require "govuk_ab_testing/minitest_helpers"
|
9
|
+
require "govuk_ab_testing/rspec_helpers"
|
10
|
+
require "govuk_ab_testing/acceptance_tests/meta_tag"
|
11
|
+
require "govuk_ab_testing/acceptance_tests/capybara"
|
12
|
+
require "govuk_ab_testing/acceptance_tests/active_support"
|
13
13
|
|
14
14
|
module GovukAbTesting
|
15
15
|
ANALYTICS_META_TAG_SELECTOR = "meta[name='govuk:ab-test']".freeze
|
@@ -2,15 +2,22 @@ module GovukAbTesting
|
|
2
2
|
class AbTest
|
3
3
|
attr_reader :ab_test_name
|
4
4
|
attr_reader :dimension
|
5
|
+
attr_reader :allowed_variants
|
6
|
+
attr_reader :control_variant
|
5
7
|
|
6
8
|
alias_method :name, :ab_test_name
|
7
9
|
|
8
10
|
# @param request [String] the name of the A/B test
|
9
11
|
# @param dimension [Integer] the dimension registered with Google Analytics
|
10
12
|
# for this specific A/B test
|
11
|
-
|
13
|
+
# @param allowed_variants [Array] an array of Strings representing the
|
14
|
+
# possible variants
|
15
|
+
# @param control_variant [String] the control variant (typically 'A')
|
16
|
+
def initialize(ab_test_name, dimension:, allowed_variants: %w[A B], control_variant: "A")
|
12
17
|
@ab_test_name = ab_test_name
|
13
18
|
@dimension = dimension
|
19
|
+
@allowed_variants = allowed_variants
|
20
|
+
@control_variant = control_variant
|
14
21
|
end
|
15
22
|
|
16
23
|
# @param request [ActionDispatch::Http::Headers] the `request.headers` in
|
@@ -31,7 +31,7 @@ module GovukAbTesting
|
|
31
31
|
assert_contains_substring(
|
32
32
|
string: vary_header_value,
|
33
33
|
substring: ab_test.response_header,
|
34
|
-
error_message: <<-ERROR
|
34
|
+
error_message: <<-ERROR,
|
35
35
|
The 'Vary' header is not being set for the '#{ab_test.name}' A/B test.
|
36
36
|
You will need to use GovukAbTesting::RequestedVariant#configure_response in your controller:
|
37
37
|
|
@@ -46,7 +46,7 @@ module GovukAbTesting
|
|
46
46
|
assert_does_not_contain_substring(
|
47
47
|
string: vary_header,
|
48
48
|
substring: ab_test_name,
|
49
|
-
error_message: <<-ERROR
|
49
|
+
error_message: <<-ERROR,
|
50
50
|
The 'Vary' header is being set by A/B test '#{ab_test_name}' on a page that should not be modified
|
51
51
|
by the A/B test. Check for incorrect usage of GovukAbTesting::RequestedVariant#configure_response
|
52
52
|
in your controller.
|
@@ -63,7 +63,7 @@ module GovukAbTesting
|
|
63
63
|
|
64
64
|
assert_is_empty(
|
65
65
|
enumerable: ab_test_meta_tags,
|
66
|
-
error_message: <<-ERROR
|
66
|
+
error_message: <<-ERROR,
|
67
67
|
Found the '#{ab_test_name}' A/B testing meta tag on a page that should not be modified by
|
68
68
|
the A/B test.
|
69
69
|
|
@@ -81,7 +81,7 @@ module GovukAbTesting
|
|
81
81
|
assert_has_size(
|
82
82
|
enumerable: ab_test_meta_tags,
|
83
83
|
size: 1,
|
84
|
-
error_message: <<-ERROR
|
84
|
+
error_message: <<-ERROR,
|
85
85
|
Incorrect number of analytics meta tags on the page for A/B test '#{ab_test.name}'.
|
86
86
|
You may need to check usage of GovukAbTesting::RequestedVariant#analytics_meta_tag in your template(s):
|
87
87
|
|
@@ -96,7 +96,7 @@ module GovukAbTesting
|
|
96
96
|
assert_is_equal(
|
97
97
|
expected: expected_metatag_content,
|
98
98
|
actual: meta_tag.content,
|
99
|
-
error_message: <<-ERROR
|
99
|
+
error_message: <<-ERROR,
|
100
100
|
The analytics meta tag content for A/B test '#{ab_test.name}' does not match the expected value.
|
101
101
|
You may need to use GovukAbTesting::RequestedVariant#analytics_meta_tag in your template(s):
|
102
102
|
|
@@ -107,7 +107,7 @@ module GovukAbTesting
|
|
107
107
|
|
108
108
|
assert_not_blank(
|
109
109
|
string: meta_tag.dimension,
|
110
|
-
error_message: <<-ERROR
|
110
|
+
error_message: <<-ERROR,
|
111
111
|
The meta tag dimension for the '#{ab_test_name}' A/B test is blank.
|
112
112
|
ERROR
|
113
113
|
)
|
@@ -116,7 +116,7 @@ module GovukAbTesting
|
|
116
116
|
assert_is_equal(
|
117
117
|
expected: ab_test.dimension.to_s,
|
118
118
|
actual: meta_tag.dimension.to_s,
|
119
|
-
error_message: <<-ERROR
|
119
|
+
error_message: <<-ERROR,
|
120
120
|
The analytics meta tag for the '#{ab_test.name}' A/B test does not match the expected value.
|
121
121
|
ERROR
|
122
122
|
)
|
@@ -1,16 +1,23 @@
|
|
1
1
|
module GovukAbTesting
|
2
2
|
module AcceptanceTests
|
3
3
|
class ActiveSupport
|
4
|
-
attr_reader :
|
4
|
+
attr_reader :request_headers, :scope
|
5
5
|
|
6
6
|
def initialize(scope)
|
7
|
-
@request = scope.instance_variable_get(:@request)
|
8
|
-
if @request.nil?
|
9
|
-
raise "Couldn't find '@request' defined, are you using ActiveSupport test cases?"
|
10
|
-
end
|
11
7
|
@scope = scope
|
12
8
|
@request_headers = {}
|
13
|
-
|
9
|
+
|
10
|
+
if request.nil?
|
11
|
+
raise "Couldn't find '@request' defined, are you using ActiveSupport test cases?"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def request
|
16
|
+
@scope.instance_variable_get(:@request)
|
17
|
+
end
|
18
|
+
|
19
|
+
def response
|
20
|
+
@scope.instance_variable_get(:@response)
|
14
21
|
end
|
15
22
|
|
16
23
|
def set_header(name, value)
|
@@ -19,7 +26,7 @@ module GovukAbTesting
|
|
19
26
|
end
|
20
27
|
|
21
28
|
def vary_header
|
22
|
-
|
29
|
+
response.headers["Vary"]
|
23
30
|
end
|
24
31
|
|
25
32
|
def analytics_meta_tags_for_test(ab_test_name)
|
@@ -27,12 +34,17 @@ module GovukAbTesting
|
|
27
34
|
end
|
28
35
|
|
29
36
|
def analytics_meta_tags
|
37
|
+
if scope.response.body.empty?
|
38
|
+
raise "Cannot find response body. If this is an RSpec Rails test, " \
|
39
|
+
"check that 'render_views' is being called."
|
40
|
+
end
|
41
|
+
|
30
42
|
tags = scope.css_select(ANALYTICS_META_TAG_SELECTOR)
|
31
43
|
|
32
44
|
tags.map do |tag|
|
33
45
|
MetaTag.new(
|
34
|
-
content: tag.attributes[
|
35
|
-
dimension: tag.attributes[
|
46
|
+
content: tag.attributes["content"].value,
|
47
|
+
dimension: tag.attributes["data-analytics-dimension"].value,
|
36
48
|
)
|
37
49
|
end
|
38
50
|
end
|
@@ -7,6 +7,7 @@ module GovukAbTesting
|
|
7
7
|
unless scope.respond_to?(:page)
|
8
8
|
raise "Page is not defined, are you using capybara?"
|
9
9
|
end
|
10
|
+
|
10
11
|
@capybara_page = scope.page
|
11
12
|
@request_headers = {}
|
12
13
|
end
|
@@ -16,13 +17,14 @@ module GovukAbTesting
|
|
16
17
|
end
|
17
18
|
|
18
19
|
def set_header(name, value)
|
19
|
-
capybara_page.driver.options[:headers]
|
20
|
+
capybara_page.driver.options[:headers] ||= {}
|
21
|
+
capybara_page.driver.options[:headers][name] = value
|
20
22
|
capybara_page.driver.header(name, value)
|
21
23
|
@request_headers[name] = value
|
22
24
|
end
|
23
25
|
|
24
26
|
def vary_header(*)
|
25
|
-
capybara_page.response_headers[
|
27
|
+
capybara_page.response_headers["Vary"]
|
26
28
|
end
|
27
29
|
|
28
30
|
def analytics_meta_tags_for_test(ab_test_name)
|
@@ -34,8 +36,8 @@ module GovukAbTesting
|
|
34
36
|
|
35
37
|
tags.map do |tag|
|
36
38
|
MetaTag.new(
|
37
|
-
content: tag[
|
38
|
-
dimension: tag[
|
39
|
+
content: tag["content"],
|
40
|
+
dimension: tag["data-analytics-dimension"],
|
39
41
|
)
|
40
42
|
end
|
41
43
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module GovukAbTesting
|
2
2
|
class Configuration
|
3
|
-
VALID_FRAMEWORKS = %i
|
4
|
-
attr_accessor :config
|
3
|
+
VALID_FRAMEWORKS = %i[capybara active_support].freeze
|
4
|
+
attr_accessor :config
|
5
5
|
|
6
6
|
def initialize
|
7
7
|
@config = {}
|
@@ -24,9 +24,9 @@ module GovukAbTesting
|
|
24
24
|
@framework_class ||= begin
|
25
25
|
case config[:acceptance_test_framework]
|
26
26
|
when :capybara
|
27
|
-
|
27
|
+
GovukAbTesting::AcceptanceTests::Capybara
|
28
28
|
when :active_support
|
29
|
-
|
29
|
+
GovukAbTesting::AcceptanceTests::ActiveSupport
|
30
30
|
else
|
31
31
|
raise "Invalid framework #{acceptance_test_framework}"
|
32
32
|
end
|
@@ -17,33 +17,56 @@ module GovukAbTesting
|
|
17
17
|
#
|
18
18
|
# @return [String] the current variant, "A" or "B"
|
19
19
|
def variant_name
|
20
|
-
|
20
|
+
variant = ab_test.allowed_variants.find do |allowed_variant|
|
21
|
+
allowed_variant == request_headers[ab_test.request_header]
|
22
|
+
end
|
23
|
+
|
24
|
+
variant || ab_test.control_variant
|
21
25
|
end
|
22
26
|
|
23
27
|
# @return [Boolean] if the user is to be served variant A
|
24
28
|
def variant_a?
|
29
|
+
warn 'DEPRECATION WARNING: the method `variant_a?` is deprecated. use `variant?("A")` instead'
|
30
|
+
|
25
31
|
variant_name == "A"
|
26
32
|
end
|
27
33
|
|
28
34
|
# @return [Boolean] if the user is to be served variant B
|
29
35
|
def variant_b?
|
36
|
+
warn 'DEPRECATION WARNING: the method `variant_b?` is deprecated. use `variant?("B")` instead'
|
37
|
+
|
30
38
|
variant_name == "B"
|
31
39
|
end
|
32
40
|
|
41
|
+
# Check if the user should be served a specific variant
|
42
|
+
#
|
43
|
+
# @param [String or Symbol] the name of the variant
|
44
|
+
#
|
45
|
+
# @return [Boolean] if the user is to be served variant :name
|
46
|
+
def variant?(name)
|
47
|
+
error_message =
|
48
|
+
"Invalid variant name '#{name}'. Allowed variants are: #{ab_test.allowed_variants}"
|
49
|
+
|
50
|
+
raise error_message unless ab_test.allowed_variants.include?(name.to_s)
|
51
|
+
|
52
|
+
variant_name == name.to_s
|
53
|
+
end
|
54
|
+
|
33
55
|
# Configure the response
|
34
56
|
#
|
35
57
|
# @param [ApplicationController::Response] the `response` in the controller
|
36
58
|
def configure_response(response)
|
37
|
-
response.headers[
|
59
|
+
response.headers["Vary"] = [response.headers["Vary"], ab_test.response_header].compact.join(", ")
|
38
60
|
end
|
39
61
|
|
40
62
|
# HTML meta tag used to track the results of your experiment
|
41
63
|
#
|
42
64
|
# @return [String]
|
43
65
|
def analytics_meta_tag
|
44
|
-
'<meta name="govuk:ab-test" '
|
45
|
-
'content="' + ab_test.meta_tag_name +
|
46
|
-
'data-analytics-dimension="' + @dimension.to_s + '"
|
66
|
+
'<meta name="govuk:ab-test" ' \
|
67
|
+
'content="' + ab_test.meta_tag_name + ":" + variant_name + '" ' \
|
68
|
+
'data-analytics-dimension="' + @dimension.to_s + '" ' \
|
69
|
+
'data-allowed-variants="' + ab_test.allowed_variants.join(",") + '">'
|
47
70
|
end
|
48
71
|
end
|
49
72
|
end
|
metadata
CHANGED
@@ -1,85 +1,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: govuk_ab_testing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2
|
4
|
+
version: 2.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GOV.UK Dev
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-08-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name: govuk
|
42
|
+
name: rubocop-govuk
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: yard
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0
|
61
|
+
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '0
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: gem_publisher
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: 1.5.0
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: 1.5.0
|
68
|
+
version: '0'
|
83
69
|
description: Gem to help with A/B testing on the GOV.UK platform
|
84
70
|
email:
|
85
71
|
- govuk-dev@digital.cabinet-office.gov.uk
|
@@ -132,8 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
132
118
|
- !ruby/object:Gem::Version
|
133
119
|
version: '0'
|
134
120
|
requirements: []
|
135
|
-
|
136
|
-
rubygems_version: 2.6.8
|
121
|
+
rubygems_version: 3.0.3
|
137
122
|
signing_key:
|
138
123
|
specification_version: 4
|
139
124
|
summary: Gem to help with A/B testing on the GOV.UK platform
|