govuk_ab_testing 2.4.1 → 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 +5 -5
 - data/.github/dependabot.yml +10 -0
 - data/.github/workflows/ci.yml +36 -0
 - data/.rubocop.yml +7 -2
 - data/.ruby-version +1 -1
 - data/CHANGELOG.md +10 -0
 - data/Gemfile +1 -1
 - data/README.md +96 -85
 - data/Rakefile +5 -7
 - data/govuk_ab_testing.gemspec +11 -12
 - data/lib/govuk_ab_testing/ab_test.rb +2 -5
 - data/lib/govuk_ab_testing/abstract_helpers.rb +7 -7
 - data/lib/govuk_ab_testing/acceptance_tests/active_support.rb +4 -4
 - data/lib/govuk_ab_testing/acceptance_tests/capybara.rb +4 -3
 - data/lib/govuk_ab_testing/configuration.rb +10 -12
 - data/lib/govuk_ab_testing/requested_variant.rb +9 -5
 - data/lib/govuk_ab_testing/rspec_assertions.rb +1 -0
 - data/lib/govuk_ab_testing/version.rb +1 -1
 - data/lib/govuk_ab_testing.rb +12 -12
 - metadata +24 -38
 - data/Jenkinsfile +0 -6
 - /data/{LICENSE.txt → LICENCE} +0 -0
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 2 
     | 
    
         
            +
            SHA256:
         
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 6a292ccc01842df0545f9ddfeec92414895271e6127c1cd9905ea30a152f3f58
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 75d28b74e22e0efa9137e7e033daebafd697012fd9f2f17a876fc40c4ef3e66c
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 0d88b6a20a1c3ffae1bc55abb2deba0cfeec443a12c8d0adad615475de3b889c3ec502bb8bdef5d49fff548cef4bc7bf56eaf826d11322d7a4a554dd8b92c9c2
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: e7d98c27fa20cde80ea0ddfbe28be2f9274a6a668257b2cc266387e0db12b1a374b1dbecff1826cceb1bfd9e8aa38386a243c7437bae3eb1d4b31a32b9112525
         
     | 
| 
         @@ -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/.rubocop.yml
    CHANGED
    
    
    
        data/.ruby-version
    CHANGED
    
    | 
         @@ -1 +1 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
             
     | 
| 
      
 1 
     | 
    
         
            +
            3.0.5
         
     | 
    
        data/CHANGELOG.md
    CHANGED
    
    | 
         @@ -1,3 +1,13 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            ## 2.4.3
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            * Updated gem dependencies and development ruby version to 3.0.5
         
     | 
| 
      
 4 
     | 
    
         
            +
            * Fixed new rubocop violations
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            ## 2.4.2
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
            * Updated gem dependencies and development ruby version to 2.6.6
         
     | 
| 
      
 9 
     | 
    
         
            +
            * Fixed new rubocop violations
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
       1 
11 
     | 
    
         
             
            ## 2.4.1
         
     | 
| 
       2 
12 
     | 
    
         | 
| 
       3 
13 
     | 
    
         
             
            * Add extra validation to ActiveSupport assertions to help debug test failures.
         
     | 
    
        data/Gemfile
    CHANGED
    
    
    
        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 
     | 
    
         
            -
            ##  
     | 
| 
       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 
     | 
    
         
            -
             
     | 
| 
      
 17 
     | 
    
         
            +
            ## Pre-requisites
         
     | 
| 
       20 
18 
     | 
    
         | 
| 
       21 
19 
     | 
    
         
             
            Before starting this, you'll need to:
         
     | 
| 
       22 
20 
     | 
    
         | 
| 
       23 
     | 
    
         
            -
            - [ 
     | 
| 
       24 
     | 
    
         
            -
            -  
     | 
| 
      
 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 
     | 
    
         
            -
             
     | 
| 
      
 24 
     | 
    
         
            +
            ## Usage
         
     | 
| 
       27 
25 
     | 
    
         | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       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 
     | 
    
         
            -
             
     | 
| 
       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 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       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 
     | 
    
         
            -
             
     | 
| 
       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 
     | 
    
         
            -
             
     | 
| 
      
 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 
     | 
    
         
            -
             
     | 
| 
       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 
     | 
    
         
            -
             
     | 
| 
      
 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 
     | 
    
         
            -
             
     | 
| 
      
 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 
     | 
    
         
            -
             
     | 
| 
      
 232 
     | 
    
         
            +
            ## API documentation
         
     | 
| 
       173 
233 
     | 
    
         | 
| 
       174 
     | 
    
         
            -
             
     | 
| 
       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 
     | 
    
         
            -
             
     | 
| 
       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 
     | 
    
         
            -
             
     | 
| 
      
 238 
     | 
    
         
            +
                $ bundle exec yard server --reload
         
     | 
| 
       220 
239 
     | 
    
         | 
| 
       221 
     | 
    
         
            -
             
     | 
| 
      
 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  
     | 
| 
      
 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 
     | 
| 
      
 250 
     | 
    
         
            +
            [MIT License](LICENCE)
         
     | 
    
        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,21 +8,21 @@ 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"
         
     | 
| 
      
 15 
     | 
    
         
            +
              spec.required_ruby_version = ">= 3.0"
         
     | 
| 
       16 
16 
     | 
    
         | 
| 
       17 
     | 
    
         
            -
              spec.files 
     | 
| 
      
 17 
     | 
    
         
            +
              spec.files = `git ls-files -z`.split("\x0").reject do |f|
         
     | 
| 
       18 
18 
     | 
    
         
             
                f.match(%r{^(test|spec|features)/})
         
     | 
| 
       19 
19 
     | 
    
         
             
              end
         
     | 
| 
       20 
20 
     | 
    
         
             
              spec.bindir        = "exe"
         
     | 
| 
       21 
21 
     | 
    
         
             
              spec.executables   = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
         
     | 
| 
       22 
     | 
    
         
            -
              spec.require_paths = [ 
     | 
| 
      
 22 
     | 
    
         
            +
              spec.require_paths = %w[lib]
         
     | 
| 
       23 
23 
     | 
    
         | 
| 
       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"
         
     | 
| 
      
 24 
     | 
    
         
            +
              spec.add_development_dependency "rake"
         
     | 
| 
      
 25 
     | 
    
         
            +
              spec.add_development_dependency "rspec"
         
     | 
| 
      
 26 
     | 
    
         
            +
              spec.add_development_dependency "rubocop-govuk", "4.10.0"
         
     | 
| 
      
 27 
     | 
    
         
            +
              spec.add_development_dependency "yard"
         
     | 
| 
       29 
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 
     | 
    
         | 
| 
         @@ -13,7 +10,7 @@ module GovukAbTesting 
     | 
|
| 
       13 
10 
     | 
    
         
             
                # @param allowed_variants [Array] an array of Strings representing the
         
     | 
| 
       14 
11 
     | 
    
         
             
                # possible variants
         
     | 
| 
       15 
12 
     | 
    
         
             
                # @param control_variant [String] the control variant (typically 'A')
         
     | 
| 
       16 
     | 
    
         
            -
                def initialize(ab_test_name, dimension:, allowed_variants: %w 
     | 
| 
      
 13 
     | 
    
         
            +
                def initialize(ab_test_name, dimension:, allowed_variants: %w[A B], control_variant: "A")
         
     | 
| 
       17 
14 
     | 
    
         
             
                  @ab_test_name = ab_test_name
         
     | 
| 
       18 
15 
     | 
    
         
             
                  @dimension = dimension
         
     | 
| 
       19 
16 
     | 
    
         
             
                  @allowed_variants = allowed_variants
         
     | 
| 
         @@ -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 
     | 
    
         
             
                    )
         
     | 
| 
         @@ -26,7 +26,7 @@ module GovukAbTesting 
     | 
|
| 
       26 
26 
     | 
    
         
             
                  end
         
     | 
| 
       27 
27 
     | 
    
         | 
| 
       28 
28 
     | 
    
         
             
                  def vary_header
         
     | 
| 
       29 
     | 
    
         
            -
                    response.headers[ 
     | 
| 
      
 29 
     | 
    
         
            +
                    response.headers["Vary"]
         
     | 
| 
       30 
30 
     | 
    
         
             
                  end
         
     | 
| 
       31 
31 
     | 
    
         | 
| 
       32 
32 
     | 
    
         
             
                  def analytics_meta_tags_for_test(ab_test_name)
         
     | 
| 
         @@ -35,7 +35,7 @@ module GovukAbTesting 
     | 
|
| 
       35 
35 
     | 
    
         | 
| 
       36 
36 
     | 
    
         
             
                  def analytics_meta_tags
         
     | 
| 
       37 
37 
     | 
    
         
             
                    if scope.response.body.empty?
         
     | 
| 
       38 
     | 
    
         
            -
                      raise "Cannot find response body. If this is an RSpec Rails test, "  
     | 
| 
      
 38 
     | 
    
         
            +
                      raise "Cannot find response body. If this is an RSpec Rails test, " \
         
     | 
| 
       39 
39 
     | 
    
         
             
                        "check that 'render_views' is being called."
         
     | 
| 
       40 
40 
     | 
    
         
             
                    end
         
     | 
| 
       41 
41 
     | 
    
         | 
| 
         @@ -43,8 +43,8 @@ module GovukAbTesting 
     | 
|
| 
       43 
43 
     | 
    
         | 
| 
       44 
44 
     | 
    
         
             
                    tags.map do |tag|
         
     | 
| 
       45 
45 
     | 
    
         
             
                      MetaTag.new(
         
     | 
| 
       46 
     | 
    
         
            -
                        content: tag.attributes[ 
     | 
| 
       47 
     | 
    
         
            -
                        dimension: tag.attributes[ 
     | 
| 
      
 46 
     | 
    
         
            +
                        content: tag.attributes["content"].value,
         
     | 
| 
      
 47 
     | 
    
         
            +
                        dimension: tag.attributes["data-analytics-dimension"].value,
         
     | 
| 
       48 
48 
     | 
    
         
             
                      )
         
     | 
| 
       49 
49 
     | 
    
         
             
                    end
         
     | 
| 
       50 
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
         
     | 
| 
         @@ -23,7 +24,7 @@ module GovukAbTesting 
     | 
|
| 
       23 
24 
     | 
    
         
             
                  end
         
     | 
| 
       24 
25 
     | 
    
         | 
| 
       25 
26 
     | 
    
         
             
                  def vary_header(*)
         
     | 
| 
       26 
     | 
    
         
            -
                    capybara_page.response_headers[ 
     | 
| 
      
 27 
     | 
    
         
            +
                    capybara_page.response_headers["Vary"]
         
     | 
| 
       27 
28 
     | 
    
         
             
                  end
         
     | 
| 
       28 
29 
     | 
    
         | 
| 
       29 
30 
     | 
    
         
             
                  def analytics_meta_tags_for_test(ab_test_name)
         
     | 
| 
         @@ -35,8 +36,8 @@ module GovukAbTesting 
     | 
|
| 
       35 
36 
     | 
    
         | 
| 
       36 
37 
     | 
    
         
             
                    tags.map do |tag|
         
     | 
| 
       37 
38 
     | 
    
         
             
                      MetaTag.new(
         
     | 
| 
       38 
     | 
    
         
            -
                        content: tag[ 
     | 
| 
       39 
     | 
    
         
            -
                        dimension: tag[ 
     | 
| 
      
 39 
     | 
    
         
            +
                        content: tag["content"],
         
     | 
| 
      
 40 
     | 
    
         
            +
                        dimension: tag["data-analytics-dimension"],
         
     | 
| 
       40 
41 
     | 
    
         
             
                      )
         
     | 
| 
       41 
42 
     | 
    
         
             
                    end
         
     | 
| 
       42 
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 = {}
         
     | 
| 
         @@ -21,16 +21,14 @@ module GovukAbTesting 
     | 
|
| 
       21 
21 
     | 
    
         
             
                end
         
     | 
| 
       22 
22 
     | 
    
         | 
| 
       23 
23 
     | 
    
         
             
                def framework_class
         
     | 
| 
       24 
     | 
    
         
            -
                  @framework_class ||=  
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       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
         
     | 
| 
         @@ -56,17 +56,21 @@ module GovukAbTesting 
     | 
|
| 
       56 
56 
     | 
    
         
             
                #
         
     | 
| 
       57 
57 
     | 
    
         
             
                # @param [ApplicationController::Response] the `response` in the controller
         
     | 
| 
       58 
58 
     | 
    
         
             
                def configure_response(response)
         
     | 
| 
       59 
     | 
    
         
            -
                  response.headers[ 
     | 
| 
      
 59 
     | 
    
         
            +
                  response.headers["Vary"] = [response.headers["Vary"], ab_test.response_header].compact.join(", ")
         
     | 
| 
       60 
60 
     | 
    
         
             
                end
         
     | 
| 
       61 
61 
     | 
    
         | 
| 
       62 
62 
     | 
    
         
             
                # HTML meta tag used to track the results of your experiment
         
     | 
| 
       63 
63 
     | 
    
         
             
                #
         
     | 
| 
       64 
64 
     | 
    
         
             
                # @return [String]
         
     | 
| 
       65 
65 
     | 
    
         
             
                def analytics_meta_tag
         
     | 
| 
       66 
     | 
    
         
            -
                   
     | 
| 
       67 
     | 
    
         
            -
                     
     | 
| 
       68 
     | 
    
         
            -
             
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
      
 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
         
     | 
    
        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
         
     | 
    
        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.4. 
     | 
| 
      
 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:  
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2023-03-21 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: 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:  
     | 
| 
      
 54 
     | 
    
         
            +
                    version: 4.10.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
         
     | 
| 
         @@ -87,14 +73,15 @@ executables: [] 
     | 
|
| 
       87 
73 
     | 
    
         
             
            extensions: []
         
     | 
| 
       88 
74 
     | 
    
         
             
            extra_rdoc_files: []
         
     | 
| 
       89 
75 
     | 
    
         
             
            files:
         
     | 
| 
      
 76 
     | 
    
         
            +
            - ".github/dependabot.yml"
         
     | 
| 
      
 77 
     | 
    
         
            +
            - ".github/workflows/ci.yml"
         
     | 
| 
       90 
78 
     | 
    
         
             
            - ".gitignore"
         
     | 
| 
       91 
79 
     | 
    
         
             
            - ".rspec"
         
     | 
| 
       92 
80 
     | 
    
         
             
            - ".rubocop.yml"
         
     | 
| 
       93 
81 
     | 
    
         
             
            - ".ruby-version"
         
     | 
| 
       94 
82 
     | 
    
         
             
            - CHANGELOG.md
         
     | 
| 
       95 
83 
     | 
    
         
             
            - Gemfile
         
     | 
| 
       96 
     | 
    
         
            -
            -  
     | 
| 
       97 
     | 
    
         
            -
            - LICENSE.txt
         
     | 
| 
      
 84 
     | 
    
         
            +
            - LICENCE
         
     | 
| 
       98 
85 
     | 
    
         
             
            - README.md
         
     | 
| 
       99 
86 
     | 
    
         
             
            - Rakefile
         
     | 
| 
       100 
87 
     | 
    
         
             
            - bin/console
         
     | 
| 
         @@ -125,15 +112,14 @@ required_ruby_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       125 
112 
     | 
    
         
             
              requirements:
         
     | 
| 
       126 
113 
     | 
    
         
             
              - - ">="
         
     | 
| 
       127 
114 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       128 
     | 
    
         
            -
                  version: '0'
         
     | 
| 
      
 115 
     | 
    
         
            +
                  version: '3.0'
         
     | 
| 
       129 
116 
     | 
    
         
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
       130 
117 
     | 
    
         
             
              requirements:
         
     | 
| 
       131 
118 
     | 
    
         
             
              - - ">="
         
     | 
| 
       132 
119 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       133 
120 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       134 
121 
     | 
    
         
             
            requirements: []
         
     | 
| 
       135 
     | 
    
         
            -
             
     | 
| 
       136 
     | 
    
         
            -
            rubygems_version: 2.6.13
         
     | 
| 
      
 122 
     | 
    
         
            +
            rubygems_version: 3.4.9
         
     | 
| 
       137 
123 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       138 
124 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       139 
125 
     | 
    
         
             
            summary: Gem to help with A/B testing on the GOV.UK platform
         
     | 
    
        data/Jenkinsfile
    DELETED
    
    
    
        /data/{LICENSE.txt → LICENCE}
    RENAMED
    
    | 
         
            File without changes
         
     |