govuk_ab_testing 0.1.5 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7b853a7e8fbdf08a5b6ee28c3b670e329fe7db86
4
- data.tar.gz: 8fb1463ede612931504805e6623798b473b806f9
3
+ metadata.gz: 3fd5d31f02d60fa9d23dc37c87747ad8ad3dfb4a
4
+ data.tar.gz: 0f3521e417baebb222969d59b3214d4ca094c88c
5
5
  SHA512:
6
- metadata.gz: 35a7f5be723f8941346bab0f6a9c610b6634b342c8bf69f342e8c33282d4225861d8c1cb75e029f531cd305f451b8d6fcee65903c480457441dfdd680de491d3
7
- data.tar.gz: 5f1f4741da3ad9f0f852df037ba7c6b4d59c4fbc3fc0a20af128751a4b03078b14d1acbb4a9698760e60f1e2f53b57b44adfd9a908934d0260ec4abf6d241914
6
+ metadata.gz: 2b11005c795f0f63ec5a4b9443448b4952355a167ef21cb7f3d27671016cdb6cf011a8748bc587b362d1d5553b8abe83adf8f323bfbc80198dbaef51b4f40fed
7
+ data.tar.gz: 65b2c4e8462261800bcb707983853b104b5cf9fa53fbbdc5f85a63d6f4af02e24dfcba7ab20cf5346064b20446bb47383845f48960b198832ec9256d60e3739d
data/CHANGELOG.md CHANGED
@@ -0,0 +1,4 @@
1
+ ## 0.2.0
2
+
3
+ * Include RSpec + Capybara helper class
4
+ * Test custom dimensions on all helper classes
data/Jenkinsfile CHANGED
@@ -1,5 +1,7 @@
1
1
  #!/usr/bin/env groovy
2
2
 
3
+ REPOSITORY = 'govuk_ab_testing'
4
+
3
5
  node {
4
6
  def govuk = load '/var/lib/jenkins/groovy_scripts/govuk_jenkinslib.groovy'
5
7
 
@@ -23,13 +25,12 @@ node {
23
25
  }
24
26
 
25
27
  stage('Tests') {
26
- govuk.setEnvar('RAILS_ENV', 'test')
27
28
  govuk.runTests()
28
29
  }
29
30
 
30
31
  if(env.BRANCH_NAME == "master") {
31
32
  stage('Publish Gem') {
32
- govuk.runRakeTask("publish_gem --trace")
33
+ govuk.publishGem(REPOSITORY, env.BRANCH_NAME)
33
34
  }
34
35
  }
35
36
 
data/README.md CHANGED
@@ -64,6 +64,8 @@ by the extension and analytics.
64
64
 
65
65
  #### Test helpers
66
66
 
67
+ ##### Minitest
68
+
67
69
  The most common usage of an A/B test is to serve two different variants of the
68
70
  same page. In this situation, you can test the controller using `with_variant`.
69
71
  It will configure the request and assert that the response is configured
@@ -121,6 +123,36 @@ class PartyControllerTest < ActionController::TestCase
121
123
  end
122
124
  ```
123
125
 
126
+ ##### RSpec + Capybara
127
+
128
+ It is also possible to use `with_variant` in RSpec tests that use Capybara. Here
129
+ is an example of a spec file:
130
+
131
+ ```ruby
132
+ # spec/features/ab_testing_spec.rb
133
+ feature "Viewing a page with an A/B test" do
134
+ include GovukAbTesting::RspecCapybaraHelpers
135
+
136
+ scenario "viewing the B version of the page" do
137
+ with_variant your_ab_test_name: 'B' do
138
+ visit root_path
139
+
140
+ expect(page).to have_breadcrumbs
141
+ expect(page).to have_beta_label
142
+ end
143
+ end
144
+ end
145
+ ```
146
+
147
+ Please note that `with_variant` in `GovukAbTesting::RspecCapybaraHelpers`
148
+ expects both `page` (Capybara session) and RSpec expectations to be available.
149
+
150
+ As with the `minitest` version, you can also pass in the following options to
151
+ `with_variant`:
152
+
153
+ - `assert_meta_tag: false`
154
+ - `dimension: <number>`
155
+
124
156
  ### Running the test suite
125
157
 
126
158
  `bundle exec rake`
@@ -2,8 +2,10 @@ module GovukAbTesting
2
2
  module MinitestHelpers
3
3
  def with_variant(args)
4
4
  ab_test_name, variant = args.first
5
+ dimension = args[:dimension]
5
6
 
6
- ab_test = GovukAbTesting::AbTest.new(ab_test_name.to_s, dimension: args[:dimension])
7
+ ab_test =
8
+ GovukAbTesting::AbTest.new(ab_test_name.to_s, dimension: dimension)
7
9
 
8
10
  @request.headers[ab_test.request_header] = variant
9
11
  requested_variant = ab_test.requested_variant(@request)
@@ -14,9 +16,32 @@ module GovukAbTesting
14
16
  "You probably forgot to use `configure_response`"
15
17
 
16
18
  unless args[:assert_meta_tag] == false
17
- content = ab_test.meta_tag_name + ':' + requested_variant.variant_name
19
+ expected_content =
20
+ ab_test.meta_tag_name + ':' + requested_variant.variant_name
18
21
  message = "You probably forgot to add the `analytics_meta_tag` to the views"
19
- assert_select "meta[name='govuk:ab-test'][content='#{content}']", 1, message
22
+ meta_tags = css_select("meta[name='govuk:ab-test']")
23
+
24
+ assert_equal(1, meta_tags.count, message)
25
+
26
+ meta_tag = meta_tags.first
27
+ content_value = meta_tag.attributes['content'].value
28
+ dimension_value = meta_tag.attributes['data-analytics-dimension'].value
29
+
30
+ assert_equal(
31
+ expected_content,
32
+ content_value,
33
+ "Meta tag's content doesn't match."
34
+ )
35
+
36
+ if dimension.nil?
37
+ assert(dimension_value, "No custom dimension number found")
38
+ else
39
+ assert_equal(
40
+ dimension.to_s,
41
+ dimension_value,
42
+ "The custom dimension found in meta tag doesn't match"
43
+ )
44
+ end
20
45
  end
21
46
  end
22
47
 
@@ -0,0 +1,33 @@
1
+ module GovukAbTesting
2
+ module RspecCapybaraHelpers
3
+ def with_variant(args)
4
+ unless defined?(page)
5
+ raise "The variable 'page' is not defined, are you using capybara?"
6
+ end
7
+
8
+ ab_test_name, variant = args.first
9
+ dimension = args[:dimension]
10
+ ab_test =
11
+ GovukAbTesting::AbTest.new(ab_test_name.to_s, dimension: dimension)
12
+
13
+ page.driver.header(ab_test.response_header, variant)
14
+
15
+ yield
16
+
17
+ expect(ab_test.response_header).to eq(page.response_headers['Vary'])
18
+
19
+ unless args[:assert_meta_tag] == false
20
+ content = [ab_test.meta_tag_name, variant].join(':')
21
+ ab_test_metatag = page.find("meta[name='govuk:ab-test']", visible: :all)
22
+
23
+ expect(ab_test_metatag['content']).to eq(content)
24
+
25
+ if dimension.nil?
26
+ expect(ab_test_metatag['data-analytics-dimension']).to_not be_nil
27
+ else
28
+ expect(ab_test_metatag['data-analytics-dimension']).to eq(dimension.to_s)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -1,3 +1,3 @@
1
1
  module GovukAbTesting
2
- VERSION = "0.1.5".freeze
2
+ VERSION = "0.2.0".freeze
3
3
  end
@@ -2,6 +2,7 @@ require "govuk_ab_testing/version"
2
2
  require "govuk_ab_testing/requested_variant"
3
3
  require "govuk_ab_testing/ab_test"
4
4
  require "govuk_ab_testing/minitest_helpers"
5
+ require "govuk_ab_testing/rspec_capybara_helpers"
5
6
 
6
7
  module GovukAbTesting
7
8
  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: 0.1.5
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-02-13 00:00:00.000000000 Z
11
+ date: 2017-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -104,6 +104,7 @@ files:
104
104
  - lib/govuk_ab_testing/ab_test.rb
105
105
  - lib/govuk_ab_testing/minitest_helpers.rb
106
106
  - lib/govuk_ab_testing/requested_variant.rb
107
+ - lib/govuk_ab_testing/rspec_capybara_helpers.rb
107
108
  - lib/govuk_ab_testing/version.rb
108
109
  homepage: https://github.com/alphagov/govuk_ab_testing
109
110
  licenses: