govuk_ab_testing 2.4.2 → 2.4.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cf9c70a0d36f4d97dec173bfc21738a3266700997a1af70cf3e5fac2b654c313
4
- data.tar.gz: 7d63ce7fe82da0f11076b29498a6188691ee765bad005805bfecdea1fc022894
3
+ metadata.gz: 6a292ccc01842df0545f9ddfeec92414895271e6127c1cd9905ea30a152f3f58
4
+ data.tar.gz: 75d28b74e22e0efa9137e7e033daebafd697012fd9f2f17a876fc40c4ef3e66c
5
5
  SHA512:
6
- metadata.gz: 59ca9f4101ddea9d142c492052ceedc08af2a29e35601a25afd6e057e976ab4e7745ca9dac4b27156210122314df78da84ee4d42c84fd09fef32ec56a9017ae7
7
- data.tar.gz: 9543b01d05c4e12ed4b8c0c029b3c5ff2e313b283541b47cdef0d2135c5273938d5cdcb5304981320e58a99a2399d92749729f2fc76680bbecfca60c6e938fab
6
+ metadata.gz: 0d88b6a20a1c3ffae1bc55abb2deba0cfeec443a12c8d0adad615475de3b889c3ec502bb8bdef5d49fff548cef4bc7bf56eaf826d11322d7a4a554dd8b92c9c2
7
+ data.tar.gz: e7d98c27fa20cde80ea0ddfbe28be2f9274a6a668257b2cc266387e0db12b1a374b1dbecff1826cceb1bfd9e8aa38386a243c7437bae3eb1d4b31a32b9112525
@@ -0,0 +1,10 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: bundler
4
+ directory: /
5
+ schedule:
6
+ interval: daily
7
+ - package-ecosystem: "github-actions"
8
+ directory: /
9
+ schedule:
10
+ interval: daily
@@ -0,0 +1,36 @@
1
+ on: [push, pull_request]
2
+
3
+ jobs:
4
+ # This matrix job runs the test suite against multiple Ruby versions
5
+ test_matrix:
6
+ strategy:
7
+ fail-fast: false
8
+ matrix:
9
+ # Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0'
10
+ ruby: ['3.0', 3.1, 3.2]
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - uses: actions/checkout@v3
14
+ - uses: ruby/setup-ruby@v1
15
+ with:
16
+ ruby-version: ${{ matrix.ruby }}
17
+ bundler-cache: true
18
+ - run: bundle exec rake
19
+
20
+ # Branch protection rules cannot directly depend on status checks from matrix jobs.
21
+ # So instead we define `test` as a dummy job which only runs after the preceding `test_matrix` checks have passed.
22
+ # Solution inspired by: https://github.community/t/status-check-for-a-matrix-jobs/127354/3
23
+ test:
24
+ needs: test_matrix
25
+ runs-on: ubuntu-latest
26
+ steps:
27
+ - run: echo "All matrix tests have passed 🚀"
28
+
29
+ publish:
30
+ needs: test
31
+ if: ${{ github.ref == 'refs/heads/main' }}
32
+ permissions:
33
+ contents: write
34
+ uses: alphagov/govuk-infrastructure/.github/workflows/publish-rubygem.yml@main
35
+ secrets:
36
+ GEM_HOST_API_KEY: ${{ secrets.ALPHAGOV_RUBYGEMS_API_KEY }}
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.6.6
1
+ 3.0.5
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 2.4.3
2
+
3
+ * Updated gem dependencies and development ruby version to 3.0.5
4
+ * Fixed new rubocop violations
5
+
1
6
  ## 2.4.2
2
7
 
3
8
  * Updated gem dependencies and development ruby version to 2.6.6
data/README.md CHANGED
@@ -2,9 +2,7 @@
2
2
 
3
3
  Gem to help with A/B testing on the GOV.UK platform.
4
4
 
5
- ## Technical documentation
6
-
7
- ### Installation
5
+ ## Installation
8
6
 
9
7
  Add this line to your application's Gemfile:
10
8
 
@@ -16,35 +14,27 @@ And then execute:
16
14
 
17
15
  $ bundle
18
16
 
19
- ### Usage
17
+ ## Pre-requisites
20
18
 
21
19
  Before starting this, you'll need to:
22
20
 
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.
24
- - configure Google Analytics (guidelines to follow)
21
+ - [Read the documentation](https://docs.publishing.service.gov.uk/manual/ab-testing.html) for an overview on how a/b testing works on GOV.UK.
22
+ - The cookie and header name in [govuk-cdn-config](https://github.com/alphagov/govuk-cdn-config/blob/master/ab_tests/ab_tests.yaml) must match the test name parameter that you pass to the Gem. The cookie name is case-sensitive.
25
23
 
26
- To enable testing in the app, your Rails app needs:
24
+ ## Usage
27
25
 
28
- 1. Some piece of logic to be A/B tested
29
- 2. A HTML meta tag that will be used to measure the results, and which specifies
30
- the dimension to use in Google Analytics
31
- 3. A response HTTP header that tells Fastly you're doing an A/B test
26
+ ### Outline
32
27
 
33
- Start by defining which acceptance testing framework you will use. This gem
34
- supports both Capybara and ActiveSupport. In order to configure it, add this to
35
- your test helper file:
28
+ To enable testing in the app, your Rails app needs:
36
29
 
37
- ```
38
- GovukAbTesting.configure do |config|
39
- config.acceptance_test_framework = :capybara # or :active_support
40
- end
41
- ```
30
+ 1. [Some piece of logic to be A/B tested](#1-example-ab-test-logic)
31
+ 2. [A response HTTP header that tells Fastly you're doing an A/B test](#2-http-response-header-to-fastly)
32
+ 3. [A HTML meta tag that will be used to measure the results, and which specifies
33
+ the dimension to use in Google Analytics](#3-add-html-metatag-tags-to-your-layouts)
42
34
 
43
- If we use capybara, the gem expects `page` to be defined in the scope of the
44
- test cases. If we use ActiveSupport, the gem expects `@request` to be defined in
45
- the scope of the test cases.
35
+ ### 1. Example A/B test logic
46
36
 
47
- Now, let's say you have this controller:
37
+ Let's say you have this controller:
48
38
 
49
39
  ```ruby
50
40
  # app/controllers/party_controller.rb
@@ -73,10 +63,15 @@ end
73
63
 
74
64
  In this example, we are running a multivariate test with 3 options being
75
65
  tested: the existing version (control), and two title changes. The minimum
76
- number of variants in any test should be two.
66
+ number of variants in any test should be two.
67
+
68
+ ### 2. HTTP response header to Fastly
69
+
70
+ The `configure_response` method used in the example in `step 1` sends the response header. The header helps Fastly to understand which variant was returned to the user and cache appropriately.
71
+
72
+ ### 3. Add HTML metatag tags to your layouts
77
73
 
78
- Then, add this to your layouts, so that we have a meta tag that can be picked up
79
- by the extension and analytics.
74
+ This is for the extension and analytics.
80
75
 
81
76
  ```html
82
77
  <!-- application.html.erb -->
@@ -86,11 +81,76 @@ by the extension and analytics.
86
81
  ```
87
82
 
88
83
  The analytics meta tag will include the allowed variants so the extension knows
89
- which variants to suggest the user.
84
+ which variants to suggest to the user.
85
+
86
+ ## Running the test suite for the gem
87
+
88
+ `bundle exec rake`
89
+
90
+ ## Acceptance testing
91
+
92
+ Start by defining which acceptance testing framework you will use. This gem
93
+ supports both Capybara and ActiveSupport. In order to configure it, add this to
94
+ your test helper file:
95
+
96
+ ```
97
+ GovukAbTesting.configure do |config|
98
+ config.acceptance_test_framework = :capybara # or :active_support
99
+ end
100
+ ```
101
+
102
+ If we use capybara, the gem expects `page` to be defined in the scope of the
103
+ test cases. If we use ActiveSupport, the gem expects `@request` to be defined in
104
+ the scope of the test cases.
105
+
106
+ ### Test helpers
107
+
108
+ #### RSpec
109
+
110
+ It is also possible to use `with_variant` and all the individual setup and
111
+ assertions steps in RSpec tests. Here is an example of a Capybara feature file:
112
+
113
+ ```ruby
114
+ # spec/features/ab_testing_spec.rb
115
+ feature "Viewing a page with an A/B test" do
116
+ include GovukAbTesting::RspecHelpers
117
+
118
+ scenario "viewing the B version of the page" do
119
+ with_variant your_ab_test_name: 'B' do
120
+ visit root_path
121
+
122
+ expect(page).to have_breadcrumbs
123
+ expect(page).to have_beta_label
124
+ end
125
+ end
126
+ end
127
+ ```
128
+
129
+ And here is an RSpec controller test:
130
+
131
+ ```ruby
132
+ # spec/controllers/some_controller_spec.rb
133
+ describe SomeController, type :controller do
134
+ include GovukAbTesting::RspecHelpers
135
+
136
+ # RSpec doesn't render views for controller specs by default
137
+ render_views
90
138
 
91
- #### Test helpers
139
+ it "should render the B version of the page" do
140
+ with_variant your_ab_test_name: 'B' do
141
+ get :index
142
+ end
143
+ end
144
+ end
145
+ ```
92
146
 
93
- ##### Minitest
147
+ As with the `minitest` version, you can also pass in the following options to
148
+ `with_variant`:
149
+
150
+ - `assert_meta_tag: false`
151
+ - `dimension: <number>`
152
+
153
+ #### Minitest
94
154
 
95
155
  The most common usage of an A/B test is to serve two different variants of the
96
156
  same page. In this situation, you can test the controller using `with_variant`.
@@ -169,71 +229,22 @@ class PartyControllerTest < ActionController::TestCase
169
229
  end
170
230
  ```
171
231
 
172
- ##### RSpec
232
+ ## API documentation
173
233
 
174
- It is also possible to use `with_variant` and all the individual setup and
175
- assertions steps in RSpec tests. Here is an example of a Capybara feature file:
234
+ See [RubyDoc](http://www.rubydoc.info/gems/govuk_ab_testing) for documentation including all of the assertions for tests.
176
235
 
177
- ```ruby
178
- # spec/features/ab_testing_spec.rb
179
- feature "Viewing a page with an A/B test" do
180
- include GovukAbTesting::RspecHelpers
181
-
182
- scenario "viewing the B version of the page" do
183
- with_variant your_ab_test_name: 'B' do
184
- visit root_path
185
-
186
- expect(page).to have_breadcrumbs
187
- expect(page).to have_beta_label
188
- end
189
- end
190
- end
191
- ```
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
-
211
- As with the `minitest` version, you can also pass in the following options to
212
- `with_variant`:
213
-
214
- - `assert_meta_tag: false`
215
- - `dimension: <number>`
216
-
217
- ### Running the test suite
236
+ To run a Yard server locally to preview documentation, run:
218
237
 
219
- `bundle exec rake`
238
+ $ bundle exec yard server --reload
220
239
 
221
- ### Testing in a browser
240
+ ## Checking your A/B test in a browser
222
241
 
223
242
  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).
243
+ [GOV.UK Toolkit browser extension](https://github.com/alphagov/govuk-browser-extension).
225
244
 
226
245
  This detects when you have a test running on a page and enables you to choose
227
246
  between variants.
228
247
 
229
- ### Documentation
230
-
231
- See [RubyDoc](http://www.rubydoc.info/gems/govuk_ab_testing) for some limited documentation.
232
-
233
- To run a Yard server locally to preview documentation, run:
234
-
235
- $ bundle exec yard server --reload
236
-
237
248
  ## Licence
238
249
 
239
- [MIT License](LICENCE.txt)
250
+ [MIT License](LICENCE)
@@ -12,8 +12,9 @@ Gem::Specification.new do |spec|
12
12
  spec.description = "Gem to help with A/B testing on the GOV.UK platform"
13
13
  spec.homepage = "https://github.com/alphagov/govuk_ab_testing"
14
14
  spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 3.0"
15
16
 
16
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
18
  f.match(%r{^(test|spec|features)/})
18
19
  end
19
20
  spec.bindir = "exe"
@@ -22,6 +23,6 @@ Gem::Specification.new do |spec|
22
23
 
23
24
  spec.add_development_dependency "rake"
24
25
  spec.add_development_dependency "rspec"
25
- spec.add_development_dependency "rubocop-govuk"
26
+ spec.add_development_dependency "rubocop-govuk", "4.10.0"
26
27
  spec.add_development_dependency "yard"
27
28
  end
@@ -1,9 +1,6 @@
1
1
  module GovukAbTesting
2
2
  class AbTest
3
- attr_reader :ab_test_name
4
- attr_reader :dimension
5
- attr_reader :allowed_variants
6
- attr_reader :control_variant
3
+ attr_reader :ab_test_name, :dimension, :allowed_variants, :control_variant
7
4
 
8
5
  alias_method :name, :ab_test_name
9
6
 
@@ -21,16 +21,14 @@ module GovukAbTesting
21
21
  end
22
22
 
23
23
  def framework_class
24
- @framework_class ||= begin
25
- case config[:acceptance_test_framework]
26
- when :capybara
27
- GovukAbTesting::AcceptanceTests::Capybara
28
- when :active_support
29
- GovukAbTesting::AcceptanceTests::ActiveSupport
30
- else
31
- raise "Invalid framework #{acceptance_test_framework}"
32
- end
33
- end
24
+ @framework_class ||= case config[:acceptance_test_framework]
25
+ when :capybara
26
+ GovukAbTesting::AcceptanceTests::Capybara
27
+ when :active_support
28
+ GovukAbTesting::AcceptanceTests::ActiveSupport
29
+ else
30
+ raise "Invalid framework #{acceptance_test_framework}"
31
+ end
34
32
  end
35
33
  end
36
34
  end
@@ -63,10 +63,14 @@ module GovukAbTesting
63
63
  #
64
64
  # @return [String]
65
65
  def analytics_meta_tag
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(",") + '">'
66
+ tag = <<~HTML
67
+ <meta name="govuk:ab-test"
68
+ content="#{ab_test.meta_tag_name}:#{variant_name}"
69
+ data-analytics-dimension="#{@dimension}"
70
+ data-allowed-variants="#{ab_test.allowed_variants.join(',')}">
71
+ HTML
72
+
73
+ tag.gsub(/\n/, "")
70
74
  end
71
75
  end
72
76
  end
@@ -1,3 +1,3 @@
1
1
  module GovukAbTesting
2
- VERSION = "2.4.2".freeze
2
+ VERSION = "2.4.3".freeze
3
3
  end
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.2
4
+ version: 2.4.3
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: 2020-08-04 00:00:00.000000000 Z
11
+ date: 2023-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -42,16 +42,16 @@ dependencies:
42
42
  name: rubocop-govuk
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - '='
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: 4.10.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: '0'
54
+ version: 4.10.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: yard
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -73,14 +73,15 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
+ - ".github/dependabot.yml"
77
+ - ".github/workflows/ci.yml"
76
78
  - ".gitignore"
77
79
  - ".rspec"
78
80
  - ".rubocop.yml"
79
81
  - ".ruby-version"
80
82
  - CHANGELOG.md
81
83
  - Gemfile
82
- - Jenkinsfile
83
- - LICENSE.txt
84
+ - LICENCE
84
85
  - README.md
85
86
  - Rakefile
86
87
  - bin/console
@@ -111,14 +112,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
111
112
  requirements:
112
113
  - - ">="
113
114
  - !ruby/object:Gem::Version
114
- version: '0'
115
+ version: '3.0'
115
116
  required_rubygems_version: !ruby/object:Gem::Requirement
116
117
  requirements:
117
118
  - - ">="
118
119
  - !ruby/object:Gem::Version
119
120
  version: '0'
120
121
  requirements: []
121
- rubygems_version: 3.0.3
122
+ rubygems_version: 3.4.9
122
123
  signing_key:
123
124
  specification_version: 4
124
125
  summary: Gem to help with A/B testing on the GOV.UK platform
data/Jenkinsfile DELETED
@@ -1,7 +0,0 @@
1
- #!/usr/bin/env groovy
2
-
3
- library("govuk")
4
-
5
- node {
6
- govuk.buildProject()
7
- }
File without changes