govuk_ab_testing 1.0.4 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/Jenkinsfile +1 -40
- data/README.md +2 -2
- data/lib/govuk_ab_testing/acceptance_tests/active_support.rb +10 -11
- data/lib/govuk_ab_testing/acceptance_tests/capybara.rb +10 -11
- data/lib/govuk_ab_testing/acceptance_tests/meta_tag.rb +16 -0
- data/lib/govuk_ab_testing/minitest_helpers.rb +24 -13
- data/lib/govuk_ab_testing/rspec_helpers.rb +14 -8
- data/lib/govuk_ab_testing/version.rb +1 -1
- data/lib/govuk_ab_testing.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 855c19cb71753681212ec44568952404cda4be1f
|
4
|
+
data.tar.gz: 003b91391e240a88f29321d2f37674895017df3a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: efbeee80a3643a4d3839842841b552cef0e2fe61addfc818cd5649626d2be38f4579369f33359d02ce46f52ad24c2c18447bbb3d756a8848f8951c28bc310926
|
7
|
+
data.tar.gz: 5553b89840a15687c569c3d59c0ccb1877e36664974558e67a0572b7bde005be35459cc9feff64b15eb4cb4922ca75280525b218ddd5e7b1764fe7a997d2d21d
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
## 2.0.0
|
2
|
+
|
3
|
+
* **BREAKING CHANGE** `assert_response_not_modified_for_ab_test` now
|
4
|
+
requires a parameter to indicate what A/B test we are referring to.
|
5
|
+
This allows for multiple A/B tests to exist without letting the test
|
6
|
+
cases fail in case they encounter a different A/B test in the Vary header;
|
7
|
+
* **BREAKING CHANGE** `assert_page_not_tracked_in_ab_test` now also
|
8
|
+
requires a parameter to indicate what A/B test we are referring to.
|
9
|
+
The reason is similar to the one mentioned above;
|
10
|
+
* New class introduced to represent a meta tag. This lets us query if a
|
11
|
+
given meta tag belongs to a given A/B test.
|
12
|
+
|
1
13
|
## 1.0.4
|
2
14
|
|
3
15
|
* Port the individual set-up and assertion steps from Minitest to RSpec
|
data/Jenkinsfile
CHANGED
@@ -1,45 +1,6 @@
|
|
1
1
|
#!/usr/bin/env groovy
|
2
2
|
|
3
|
-
REPOSITORY = 'govuk_ab_testing'
|
4
|
-
|
5
3
|
node {
|
6
4
|
def govuk = load '/var/lib/jenkins/groovy_scripts/govuk_jenkinslib.groovy'
|
7
|
-
|
8
|
-
try {
|
9
|
-
stage('Checkout') {
|
10
|
-
checkout scm
|
11
|
-
}
|
12
|
-
|
13
|
-
stage('Clean') {
|
14
|
-
govuk.cleanupGit()
|
15
|
-
govuk.mergeMasterBranch()
|
16
|
-
}
|
17
|
-
|
18
|
-
stage('Bundle') {
|
19
|
-
echo 'Bundling'
|
20
|
-
sh("bundle install --path ${JENKINS_HOME}/bundles/${JOB_NAME}")
|
21
|
-
}
|
22
|
-
|
23
|
-
stage('Linter') {
|
24
|
-
govuk.rubyLinter()
|
25
|
-
}
|
26
|
-
|
27
|
-
stage('Tests') {
|
28
|
-
govuk.runTests()
|
29
|
-
}
|
30
|
-
|
31
|
-
if(env.BRANCH_NAME == "master") {
|
32
|
-
stage('Publish Gem') {
|
33
|
-
govuk.publishGem(REPOSITORY, env.BRANCH_NAME)
|
34
|
-
}
|
35
|
-
}
|
36
|
-
|
37
|
-
} catch (e) {
|
38
|
-
currentBuild.result = 'FAILED'
|
39
|
-
step([$class: 'Mailer',
|
40
|
-
notifyEveryUnstableBuild: true,
|
41
|
-
recipients: 'govuk-ci-notifications@digital.cabinet-office.gov.uk',
|
42
|
-
sendToIndividuals: true])
|
43
|
-
throw e
|
44
|
-
}
|
5
|
+
govuk.buildProject()
|
45
6
|
}
|
data/README.md
CHANGED
@@ -132,7 +132,7 @@ class PartyControllerTest < ActionController::TestCase
|
|
132
132
|
|
133
133
|
get :show
|
134
134
|
|
135
|
-
assert_response_not_modified_for_ab_test
|
135
|
+
assert_response_not_modified_for_ab_test("your_ab_test_name")
|
136
136
|
end
|
137
137
|
end
|
138
138
|
```
|
@@ -152,7 +152,7 @@ class PartyControllerTest < ActionController::TestCase
|
|
152
152
|
get :show
|
153
153
|
|
154
154
|
assert_response_is_cached_by_variant("your_ab_test_name")
|
155
|
-
assert_page_not_tracked_in_ab_test
|
155
|
+
assert_page_not_tracked_in_ab_test("your_ab_test_name")
|
156
156
|
end
|
157
157
|
end
|
158
158
|
```
|
@@ -21,20 +21,19 @@ module GovukAbTesting
|
|
21
21
|
response.headers['Vary']
|
22
22
|
end
|
23
23
|
|
24
|
-
def
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
def analytics_meta_tag
|
29
|
-
analytics_meta_tags.first
|
24
|
+
def analytics_meta_tags_for_test(ab_test_name)
|
25
|
+
analytics_meta_tags.select { |tag| tag.for_ab_test?(ab_test_name) }
|
30
26
|
end
|
31
27
|
|
32
|
-
def
|
33
|
-
|
34
|
-
end
|
28
|
+
def analytics_meta_tags
|
29
|
+
tags = scope.css_select(ANALYTICS_META_TAG_SELECTOR)
|
35
30
|
|
36
|
-
|
37
|
-
|
31
|
+
tags.map do |tag|
|
32
|
+
MetaTag.new(
|
33
|
+
content: tag.attributes['content'].value,
|
34
|
+
dimension: tag.attributes['data-analytics-dimension'].value
|
35
|
+
)
|
36
|
+
end
|
38
37
|
end
|
39
38
|
end
|
40
39
|
end
|
@@ -25,20 +25,19 @@ module GovukAbTesting
|
|
25
25
|
capybara_page.response_headers['Vary']
|
26
26
|
end
|
27
27
|
|
28
|
-
def
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
def analytics_meta_tag
|
33
|
-
analytics_meta_tags.first
|
28
|
+
def analytics_meta_tags_for_test(ab_test_name)
|
29
|
+
analytics_meta_tags.select { |tag| tag.for_ab_test?(ab_test_name) }
|
34
30
|
end
|
35
31
|
|
36
|
-
def
|
37
|
-
|
38
|
-
end
|
32
|
+
def analytics_meta_tags
|
33
|
+
tags = capybara_page.all(ANALYTICS_META_TAG_SELECTOR, visible: :all)
|
39
34
|
|
40
|
-
|
41
|
-
|
35
|
+
tags.map do |tag|
|
36
|
+
MetaTag.new(
|
37
|
+
content: tag['content'],
|
38
|
+
dimension: tag['data-analytics-dimension']
|
39
|
+
)
|
40
|
+
end
|
42
41
|
end
|
43
42
|
end
|
44
43
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module GovukAbTesting
|
2
|
+
module AcceptanceTests
|
3
|
+
class MetaTag
|
4
|
+
attr_reader :content, :dimension
|
5
|
+
|
6
|
+
def initialize(content:, dimension:)
|
7
|
+
@content = content
|
8
|
+
@dimension = dimension
|
9
|
+
end
|
10
|
+
|
11
|
+
def for_ab_test?(ab_test_name)
|
12
|
+
content.match(/#{ab_test_name}/i)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -25,24 +25,25 @@ module GovukAbTesting
|
|
25
25
|
expected_content =
|
26
26
|
ab_test.meta_tag_name + ':' + requested_variant.variant_name
|
27
27
|
message = "You probably forgot to add the `analytics_meta_tag` to the views"
|
28
|
-
meta_tags =
|
28
|
+
meta_tags =
|
29
|
+
acceptance_test_framework.analytics_meta_tags_for_test(ab_test_name)
|
29
30
|
|
30
31
|
assert_equal(1, meta_tags.count, message)
|
31
32
|
|
32
|
-
|
33
|
+
meta_tag = meta_tags.first
|
33
34
|
|
34
35
|
assert_equal(
|
35
36
|
expected_content,
|
36
|
-
|
37
|
-
"Meta tag's content
|
37
|
+
meta_tag.content,
|
38
|
+
"Meta tag's content doesnt match."
|
38
39
|
)
|
39
40
|
|
40
41
|
if dimension.nil?
|
41
|
-
assert(
|
42
|
+
assert(meta_tag.dimension, "No custom dimension number found")
|
42
43
|
else
|
43
44
|
assert_equal(
|
44
45
|
dimension.to_s,
|
45
|
-
|
46
|
+
meta_tag.dimension,
|
46
47
|
"The custom dimension found in meta tag doesn't match"
|
47
48
|
)
|
48
49
|
end
|
@@ -63,17 +64,27 @@ module GovukAbTesting
|
|
63
64
|
"You probably forgot to use `configure_response`"
|
64
65
|
end
|
65
66
|
|
66
|
-
def assert_response_not_modified_for_ab_test
|
67
|
-
|
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,
|
68
73
|
"`Vary` header is being added to a page which should not be modified by the A/B test"
|
74
|
+
)
|
69
75
|
|
70
|
-
assert_page_not_tracked_in_ab_test
|
76
|
+
assert_page_not_tracked_in_ab_test(ab_test_name)
|
71
77
|
end
|
72
78
|
|
73
|
-
def assert_page_not_tracked_in_ab_test
|
74
|
-
meta_tags =
|
75
|
-
|
76
|
-
|
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
|
+
)
|
77
88
|
end
|
78
89
|
end
|
79
90
|
end
|
@@ -22,12 +22,15 @@ module GovukAbTesting
|
|
22
22
|
|
23
23
|
unless args[:assert_meta_tag] == false
|
24
24
|
content = [ab_test.meta_tag_name, requested_variant.variant_name].join(':')
|
25
|
-
ab_test_metatags =
|
25
|
+
ab_test_metatags =
|
26
|
+
acceptance_test_framework.analytics_meta_tags_for_test(ab_test_name)
|
26
27
|
|
27
28
|
expect(ab_test_metatags.count).to eq(1)
|
28
29
|
|
29
|
-
|
30
|
-
|
30
|
+
meta_tag = ab_test_metatags.first
|
31
|
+
|
32
|
+
expect(meta_tag.content).to eq(content)
|
33
|
+
dimension = meta_tag.dimension
|
31
34
|
|
32
35
|
if dimension.nil?
|
33
36
|
expect(dimension).to_not be_nil
|
@@ -50,15 +53,18 @@ module GovukAbTesting
|
|
50
53
|
expect(vary_header_value).to eq(ab_test.response_header)
|
51
54
|
end
|
52
55
|
|
53
|
-
def assert_response_not_modified_for_ab_test
|
54
|
-
|
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}/),
|
55
60
|
"`Vary` header is being added to a page which should not be modified by the A/B test"
|
56
61
|
|
57
|
-
assert_page_not_tracked_in_ab_test
|
62
|
+
assert_page_not_tracked_in_ab_test(ab_test_name)
|
58
63
|
end
|
59
64
|
|
60
|
-
def assert_page_not_tracked_in_ab_test
|
61
|
-
meta_tags =
|
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)
|
62
68
|
|
63
69
|
expect(meta_tags).to be_empty,
|
64
70
|
"A/B meta tag is being added to a page which should not be modified by the A/B test"
|
data/lib/govuk_ab_testing.rb
CHANGED
@@ -4,6 +4,7 @@ require "govuk_ab_testing/requested_variant"
|
|
4
4
|
require "govuk_ab_testing/ab_test"
|
5
5
|
require "govuk_ab_testing/minitest_helpers"
|
6
6
|
require "govuk_ab_testing/rspec_helpers"
|
7
|
+
require 'govuk_ab_testing/acceptance_tests/meta_tag'
|
7
8
|
require 'govuk_ab_testing/acceptance_tests/capybara'
|
8
9
|
require 'govuk_ab_testing/acceptance_tests/active_support'
|
9
10
|
|
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:
|
4
|
+
version: 2.0.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-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -104,6 +104,7 @@ files:
|
|
104
104
|
- lib/govuk_ab_testing/ab_test.rb
|
105
105
|
- lib/govuk_ab_testing/acceptance_tests/active_support.rb
|
106
106
|
- lib/govuk_ab_testing/acceptance_tests/capybara.rb
|
107
|
+
- lib/govuk_ab_testing/acceptance_tests/meta_tag.rb
|
107
108
|
- lib/govuk_ab_testing/configuration.rb
|
108
109
|
- lib/govuk_ab_testing/minitest_helpers.rb
|
109
110
|
- lib/govuk_ab_testing/requested_variant.rb
|