govuk_ab_testing 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/lib/govuk_ab_testing/ab_test.rb +3 -0
- data/lib/govuk_ab_testing/abstract_helpers.rb +128 -0
- data/lib/govuk_ab_testing/acceptance_tests/active_support.rb +3 -2
- data/lib/govuk_ab_testing/minitest_assertions.rb +28 -0
- data/lib/govuk_ab_testing/minitest_helpers.rb +2 -86
- data/lib/govuk_ab_testing/rspec_assertions.rb +29 -0
- data/lib/govuk_ab_testing/rspec_helpers.rb +2 -69
- data/lib/govuk_ab_testing/version.rb +1 -1
- data/lib/govuk_ab_testing.rb +8 -5
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 84d90e7b73cb4f14c3ddc5670921e7077a85ecca
|
4
|
+
data.tar.gz: 6e933bd3bc167d9995097901654893c26c4300dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a929e3cf5b0a044a1dc2b2cde0d8e6b7541bd110a5569c0e38c466aa5b908750658ab7749ff251774dfd89542f2457b8781c1304430f011c550f13b41315e7a
|
7
|
+
data.tar.gz: ab6bee9421a644a0e906f1073b3a751917c60b41306f42f4c51e7ccd84aae6f453f8c8c17e819df5868c550df0db1201b6ef34dbfa628649f2f8bc576fb04414
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## 2.1.0
|
2
|
+
|
3
|
+
* Refactor both RSpec and Minitest helpers to use the same Abstract helper
|
4
|
+
* Allow assertions on the Vary header for multiple concurrent A/B tests
|
5
|
+
* Fix a broken RSpec assertion
|
6
|
+
* Fix meta tag dimension checking
|
7
|
+
|
1
8
|
## 2.0.0
|
2
9
|
|
3
10
|
* **BREAKING CHANGE** `assert_response_not_modified_for_ab_test` now
|
@@ -0,0 +1,128 @@
|
|
1
|
+
module GovukAbTesting
|
2
|
+
module AbstractHelpers
|
3
|
+
def acceptance_test_framework
|
4
|
+
@acceptance_test_framework ||= GovukAbTesting.configuration.framework_class.new(self)
|
5
|
+
end
|
6
|
+
|
7
|
+
def with_variant(args)
|
8
|
+
ab_test_name, variant = args.first
|
9
|
+
dimension = args[:dimension]
|
10
|
+
|
11
|
+
setup_ab_variant(ab_test_name, variant, dimension)
|
12
|
+
|
13
|
+
yield
|
14
|
+
|
15
|
+
assert_response_is_cached_by_variant(ab_test_name)
|
16
|
+
|
17
|
+
unless args[:assert_meta_tag] == false
|
18
|
+
assert_page_tracked_in_ab_test(ab_test_name, variant, dimension)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def setup_ab_variant(ab_test_name, variant, dimension = 300)
|
23
|
+
ab_test = AbTest.new(ab_test_name, dimension: dimension)
|
24
|
+
acceptance_test_framework.set_header(ab_test.request_header, variant)
|
25
|
+
end
|
26
|
+
|
27
|
+
def assert_response_is_cached_by_variant(ab_test_name)
|
28
|
+
ab_test = AbTest.new(ab_test_name, dimension: 300)
|
29
|
+
vary_header_value = acceptance_test_framework.vary_header
|
30
|
+
|
31
|
+
assert_contains_substring(
|
32
|
+
string: vary_header_value,
|
33
|
+
substring: ab_test.response_header,
|
34
|
+
error_message: <<-ERROR
|
35
|
+
The 'Vary' header is not being set for the '#{ab_test.name}' A/B test.
|
36
|
+
You will need to use GovukAbTesting::RequestedVariant#configure_response in your controller:
|
37
|
+
|
38
|
+
requested_variant.configure_response(response)
|
39
|
+
|
40
|
+
ERROR
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
def assert_response_not_modified_for_ab_test(ab_test_name)
|
45
|
+
vary_header = acceptance_test_framework.vary_header
|
46
|
+
assert_does_not_contain_substring(
|
47
|
+
string: vary_header,
|
48
|
+
substring: ab_test_name,
|
49
|
+
error_message: <<-ERROR
|
50
|
+
The 'Vary' header is being set by A/B test '#{ab_test_name}' on a page that should not be modified
|
51
|
+
by the A/B test. Check for incorrect usage of GovukAbTesting::RequestedVariant#configure_response
|
52
|
+
in your controller.
|
53
|
+
|
54
|
+
'Vary': #{vary_header}
|
55
|
+
|
56
|
+
ERROR
|
57
|
+
)
|
58
|
+
end
|
59
|
+
|
60
|
+
def assert_page_not_tracked_in_ab_test(ab_test_name)
|
61
|
+
ab_test_meta_tags =
|
62
|
+
acceptance_test_framework.analytics_meta_tags_for_test(ab_test_name)
|
63
|
+
|
64
|
+
assert_is_empty(
|
65
|
+
enumerable: ab_test_meta_tags,
|
66
|
+
error_message: <<-ERROR
|
67
|
+
Found the following '#{ab_test_name}' A/B testing meta tag on a page that should not be modified by
|
68
|
+
the A/B test:
|
69
|
+
|
70
|
+
#{ab_test_meta_tags.first.content}
|
71
|
+
|
72
|
+
Check for incorrect usage of GovukAbTesting::RequestedVariant#analytics_meta_tag
|
73
|
+
ERROR
|
74
|
+
)
|
75
|
+
end
|
76
|
+
|
77
|
+
def assert_page_tracked_in_ab_test(ab_test_name, variant, dimension)
|
78
|
+
ab_test = AbTest.new(ab_test_name, dimension: dimension)
|
79
|
+
|
80
|
+
ab_test_meta_tags =
|
81
|
+
acceptance_test_framework.analytics_meta_tags_for_test(ab_test.name)
|
82
|
+
|
83
|
+
assert_has_size(
|
84
|
+
enumerable: ab_test_meta_tags,
|
85
|
+
size: 1,
|
86
|
+
error_message: <<-ERROR
|
87
|
+
Incorrect number of analytics meta tags on the page for A/B test '#{ab_test.name}'.
|
88
|
+
You may need to check usage of GovukAbTesting::RequestedVariant#analytics_meta_tag in your template(s):
|
89
|
+
|
90
|
+
<%= requested_variant.analytics_meta_tag %>
|
91
|
+
|
92
|
+
ERROR
|
93
|
+
)
|
94
|
+
|
95
|
+
meta_tag = ab_test_meta_tags.first
|
96
|
+
expected_metatag_content = "#{ab_test.meta_tag_name}:#{variant}"
|
97
|
+
|
98
|
+
assert_is_equal(
|
99
|
+
expected: expected_metatag_content,
|
100
|
+
actual: meta_tag.content,
|
101
|
+
error_message: <<-ERROR
|
102
|
+
The analytics meta tag content for A/B test '#{ab_test.name}' does not match the expected value.
|
103
|
+
You may need to use GovukAbTesting::RequestedVariant#analytics_meta_tag in your template(s):
|
104
|
+
|
105
|
+
<%= requested_variant.analytics_meta_tag %>
|
106
|
+
|
107
|
+
ERROR
|
108
|
+
)
|
109
|
+
|
110
|
+
assert_not_blank(
|
111
|
+
string: meta_tag.dimension,
|
112
|
+
error_message: <<-ERROR
|
113
|
+
The meta tag dimension for the '#{ab_test_name}' A/B test is blank.
|
114
|
+
ERROR
|
115
|
+
)
|
116
|
+
|
117
|
+
unless ab_test.dimension.nil?
|
118
|
+
assert_is_equal(
|
119
|
+
expected: ab_test.dimension.to_s,
|
120
|
+
actual: meta_tag.dimension.to_s,
|
121
|
+
error_message: <<-ERROR
|
122
|
+
The analytics meta tag for the '#{ab_test.name}' A/B test does not match the expected value.
|
123
|
+
ERROR
|
124
|
+
)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
@@ -10,6 +10,7 @@ module GovukAbTesting
|
|
10
10
|
end
|
11
11
|
@scope = scope
|
12
12
|
@request_headers = {}
|
13
|
+
@response = scope.instance_variable_get(:@response)
|
13
14
|
end
|
14
15
|
|
15
16
|
def set_header(name, value)
|
@@ -17,8 +18,8 @@ module GovukAbTesting
|
|
17
18
|
@request_headers[name] = value
|
18
19
|
end
|
19
20
|
|
20
|
-
def vary_header
|
21
|
-
response.headers['Vary']
|
21
|
+
def vary_header
|
22
|
+
@response.headers['Vary']
|
22
23
|
end
|
23
24
|
|
24
25
|
def analytics_meta_tags_for_test(ab_test_name)
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module GovukAbTesting
|
2
|
+
module MinitestAssertions
|
3
|
+
def assert_is_equal(expected:, actual:, error_message:)
|
4
|
+
assert_equal(expected, actual, error_message)
|
5
|
+
end
|
6
|
+
|
7
|
+
def assert_contains_substring(string:, substring:, error_message:)
|
8
|
+
assert_match(/#{substring}/, string, error_message)
|
9
|
+
end
|
10
|
+
|
11
|
+
def assert_does_not_contain_substring(string:, substring:, error_message:)
|
12
|
+
refute_match(/#{substring}/, string, error_message)
|
13
|
+
end
|
14
|
+
|
15
|
+
def assert_has_size(enumerable:, size:, error_message:)
|
16
|
+
assert_equal(size, enumerable.count, error_message)
|
17
|
+
end
|
18
|
+
|
19
|
+
def assert_is_empty(enumerable:, error_message:)
|
20
|
+
assert_has_size(enumerable, 0, error_message)
|
21
|
+
end
|
22
|
+
|
23
|
+
def assert_not_blank(string:, error_message:)
|
24
|
+
refute_nil(string, error_message)
|
25
|
+
refute_equal(string.length, 0, error_message)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -1,90 +1,6 @@
|
|
1
1
|
module GovukAbTesting
|
2
2
|
module MinitestHelpers
|
3
|
-
|
4
|
-
|
5
|
-
GovukAbTesting.configuration.framework_class.new(self)
|
6
|
-
end
|
7
|
-
|
8
|
-
def with_variant(args)
|
9
|
-
ab_test_name, variant = args.first
|
10
|
-
dimension = args[:dimension]
|
11
|
-
|
12
|
-
ab_test =
|
13
|
-
GovukAbTesting::AbTest.new(ab_test_name.to_s, dimension: dimension)
|
14
|
-
|
15
|
-
acceptance_test_framework.set_header(ab_test.request_header, variant)
|
16
|
-
requested_variant = ab_test.requested_variant(acceptance_test_framework.request_headers)
|
17
|
-
|
18
|
-
yield
|
19
|
-
|
20
|
-
vary_header_value = acceptance_test_framework.vary_header(response)
|
21
|
-
assert_match ab_test.response_header, vary_header_value,
|
22
|
-
"You probably forgot to use `configure_response`"
|
23
|
-
|
24
|
-
unless args[:assert_meta_tag] == false
|
25
|
-
expected_content =
|
26
|
-
ab_test.meta_tag_name + ':' + requested_variant.variant_name
|
27
|
-
message = "You probably forgot to add the `analytics_meta_tag` to the views"
|
28
|
-
meta_tags =
|
29
|
-
acceptance_test_framework.analytics_meta_tags_for_test(ab_test_name)
|
30
|
-
|
31
|
-
assert_equal(1, meta_tags.count, message)
|
32
|
-
|
33
|
-
meta_tag = meta_tags.first
|
34
|
-
|
35
|
-
assert_equal(
|
36
|
-
expected_content,
|
37
|
-
meta_tag.content,
|
38
|
-
"Meta tag's content doesnt match."
|
39
|
-
)
|
40
|
-
|
41
|
-
if dimension.nil?
|
42
|
-
assert(meta_tag.dimension, "No custom dimension number found")
|
43
|
-
else
|
44
|
-
assert_equal(
|
45
|
-
dimension.to_s,
|
46
|
-
meta_tag.dimension,
|
47
|
-
"The custom dimension found in meta tag doesn't match"
|
48
|
-
)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def setup_ab_variant(ab_test_name, variant, dimension = 300)
|
54
|
-
ab_test = GovukAbTesting::AbTest.new(ab_test_name, dimension: dimension)
|
55
|
-
|
56
|
-
acceptance_test_framework.set_header(ab_test.request_header, variant)
|
57
|
-
end
|
58
|
-
|
59
|
-
def assert_response_is_cached_by_variant(ab_test_name)
|
60
|
-
ab_test = GovukAbTesting::AbTest.new(ab_test_name, dimension: 123)
|
61
|
-
|
62
|
-
vary_header_value = acceptance_test_framework.vary_header(response)
|
63
|
-
assert_match ab_test.response_header, vary_header_value,
|
64
|
-
"You probably forgot to use `configure_response`"
|
65
|
-
end
|
66
|
-
|
67
|
-
def assert_response_not_modified_for_ab_test(ab_test_name)
|
68
|
-
vary_header = acceptance_test_framework.vary_header(response)
|
69
|
-
|
70
|
-
assert_no_match(
|
71
|
-
/#{ab_test_name}/,
|
72
|
-
vary_header,
|
73
|
-
"`Vary` header is being added to a page which should not be modified by the A/B test"
|
74
|
-
)
|
75
|
-
|
76
|
-
assert_page_not_tracked_in_ab_test(ab_test_name)
|
77
|
-
end
|
78
|
-
|
79
|
-
def assert_page_not_tracked_in_ab_test(ab_test_name)
|
80
|
-
meta_tags =
|
81
|
-
acceptance_test_framework.analytics_meta_tags_for_test(ab_test_name)
|
82
|
-
|
83
|
-
assert_equal(
|
84
|
-
0,
|
85
|
-
meta_tags.count,
|
86
|
-
"A/B meta tag is being added to a page which should not be modified by the A/B test"
|
87
|
-
)
|
88
|
-
end
|
3
|
+
include AbstractHelpers
|
4
|
+
include MinitestAssertions
|
89
5
|
end
|
90
6
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module GovukAbTesting
|
2
|
+
module RspecAssertions
|
3
|
+
def assert_is_equal(expected:, actual:, error_message:)
|
4
|
+
expect(actual).to eq(expected), error_message
|
5
|
+
end
|
6
|
+
|
7
|
+
def assert_contains_substring(string:, substring:, error_message:)
|
8
|
+
expect(string).to include(substring), error_message
|
9
|
+
end
|
10
|
+
|
11
|
+
def assert_does_not_contain_substring(string:, substring:, error_message:)
|
12
|
+
return if string.nil?
|
13
|
+
expect(string).not_to include(substring), error_message
|
14
|
+
end
|
15
|
+
|
16
|
+
def assert_has_size(enumerable:, size:, error_message:)
|
17
|
+
expect(enumerable.count).to eq(size), error_message
|
18
|
+
end
|
19
|
+
|
20
|
+
def assert_is_empty(enumerable:, error_message:)
|
21
|
+
assert_has_size(enumerable, 0, error_message)
|
22
|
+
end
|
23
|
+
|
24
|
+
def assert_not_blank(string:, error_message:)
|
25
|
+
expect(string).not_to be_nil, error_message
|
26
|
+
expect(string.length).not_to eq(0), error_message
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -1,73 +1,6 @@
|
|
1
1
|
module GovukAbTesting
|
2
2
|
module RspecHelpers
|
3
|
-
|
4
|
-
|
5
|
-
GovukAbTesting.configuration.framework_class.new(self)
|
6
|
-
end
|
7
|
-
|
8
|
-
def with_variant(args)
|
9
|
-
ab_test_name, variant = args.first
|
10
|
-
dimension = args[:dimension]
|
11
|
-
|
12
|
-
ab_test =
|
13
|
-
GovukAbTesting::AbTest.new(ab_test_name.to_s, dimension: dimension)
|
14
|
-
|
15
|
-
acceptance_test_framework.set_header(ab_test.request_header, variant)
|
16
|
-
requested_variant = ab_test.requested_variant(acceptance_test_framework.request_headers)
|
17
|
-
|
18
|
-
yield
|
19
|
-
|
20
|
-
vary_header_value = acceptance_test_framework.vary_header
|
21
|
-
expect(ab_test.response_header).to eq(vary_header_value)
|
22
|
-
|
23
|
-
unless args[:assert_meta_tag] == false
|
24
|
-
content = [ab_test.meta_tag_name, requested_variant.variant_name].join(':')
|
25
|
-
ab_test_metatags =
|
26
|
-
acceptance_test_framework.analytics_meta_tags_for_test(ab_test_name)
|
27
|
-
|
28
|
-
expect(ab_test_metatags.count).to eq(1)
|
29
|
-
|
30
|
-
meta_tag = ab_test_metatags.first
|
31
|
-
|
32
|
-
expect(meta_tag.content).to eq(content)
|
33
|
-
dimension = meta_tag.dimension
|
34
|
-
|
35
|
-
if dimension.nil?
|
36
|
-
expect(dimension).to_not be_nil
|
37
|
-
else
|
38
|
-
expect(dimension).to eq(dimension.to_s)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def setup_ab_variant(ab_test_name, variant, dimension = 300)
|
44
|
-
ab_test = GovukAbTesting::AbTest.new(ab_test_name, dimension: dimension)
|
45
|
-
|
46
|
-
acceptance_test_framework.set_header(ab_test.request_header, variant)
|
47
|
-
end
|
48
|
-
|
49
|
-
def assert_response_is_cached_by_variant(ab_test_name)
|
50
|
-
ab_test = GovukAbTesting::AbTest.new(ab_test_name, dimension: 123)
|
51
|
-
|
52
|
-
vary_header_value = acceptance_test_framework.vary_header
|
53
|
-
expect(vary_header_value).to eq(ab_test.response_header)
|
54
|
-
end
|
55
|
-
|
56
|
-
def assert_response_not_modified_for_ab_test(ab_test_name)
|
57
|
-
vary_header = acceptance_test_framework.vary_header
|
58
|
-
|
59
|
-
expect(vary_header).to_not match?(/#{ab_test_name}/),
|
60
|
-
"`Vary` header is being added to a page which should not be modified by the A/B test"
|
61
|
-
|
62
|
-
assert_page_not_tracked_in_ab_test(ab_test_name)
|
63
|
-
end
|
64
|
-
|
65
|
-
def assert_page_not_tracked_in_ab_test(ab_test_name)
|
66
|
-
meta_tags =
|
67
|
-
acceptance_test_framework.analytics_meta_tags_for_test(ab_test_name)
|
68
|
-
|
69
|
-
expect(meta_tags).to be_empty,
|
70
|
-
"A/B meta tag is being added to a page which should not be modified by the A/B test"
|
71
|
-
end
|
3
|
+
include AbstractHelpers
|
4
|
+
include RspecAssertions
|
72
5
|
end
|
73
6
|
end
|
data/lib/govuk_ab_testing.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
|
-
require
|
1
|
+
require 'govuk_ab_testing/version'
|
2
2
|
require 'govuk_ab_testing/configuration'
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
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'
|
7
10
|
require 'govuk_ab_testing/acceptance_tests/meta_tag'
|
8
11
|
require 'govuk_ab_testing/acceptance_tests/capybara'
|
9
12
|
require 'govuk_ab_testing/acceptance_tests/active_support'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: govuk_ab_testing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
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: 2017-03-
|
11
|
+
date: 2017-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -102,12 +102,15 @@ files:
|
|
102
102
|
- govuk_ab_testing.gemspec
|
103
103
|
- lib/govuk_ab_testing.rb
|
104
104
|
- lib/govuk_ab_testing/ab_test.rb
|
105
|
+
- lib/govuk_ab_testing/abstract_helpers.rb
|
105
106
|
- lib/govuk_ab_testing/acceptance_tests/active_support.rb
|
106
107
|
- lib/govuk_ab_testing/acceptance_tests/capybara.rb
|
107
108
|
- lib/govuk_ab_testing/acceptance_tests/meta_tag.rb
|
108
109
|
- lib/govuk_ab_testing/configuration.rb
|
110
|
+
- lib/govuk_ab_testing/minitest_assertions.rb
|
109
111
|
- lib/govuk_ab_testing/minitest_helpers.rb
|
110
112
|
- lib/govuk_ab_testing/requested_variant.rb
|
113
|
+
- lib/govuk_ab_testing/rspec_assertions.rb
|
111
114
|
- lib/govuk_ab_testing/rspec_helpers.rb
|
112
115
|
- lib/govuk_ab_testing/version.rb
|
113
116
|
homepage: https://github.com/alphagov/govuk_ab_testing
|