Module: GovukAbTesting::MinitestHelpers

Defined in:
lib/govuk_ab_testing/minitest_helpers.rb

Instance Method Summary collapse

Instance Method Details

#assert_unaffected_by_ab_testObject



31
32
33
34
35
36
# File 'lib/govuk_ab_testing/minitest_helpers.rb', line 31

def assert_unaffected_by_ab_test
  assert_nil response.headers['Vary'],
    "`Vary` header is being added to a page which is outside of the A/B test"

  assert_select "meta[name='govuk:ab-test']", false
end

#setup_ab_variant(ab_test_name, variant, dimension) ⇒ Object



25
26
27
28
29
# File 'lib/govuk_ab_testing/minitest_helpers.rb', line 25

def setup_ab_variant(ab_test_name, variant, dimension)
  ab_test = GovukAbTesting::AbTest.new(ab_test_name, dimension: dimension)

  @request.headers[ab_test.request_header] = variant
end

#with_variant(args) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/govuk_ab_testing/minitest_helpers.rb', line 3

def with_variant(args)
  ab_test_name, variant = args.first

  ab_test = GovukAbTesting::AbTest.new(ab_test_name.to_s, dimension: args[:dimension])

  @request.headers[ab_test.request_header] = variant
  requested_variant = ab_test.requested_variant(@request)

  yield

  assert_equal ab_test.response_header, response.headers['Vary'], "You probably forgot to use `configure_response`"

  unless args[:assert_meta_tag] == false
    raise "Cannot test the A/B meta tag because no expected :dimension parameter was specified by test" unless args[:dimension]

    assert_meta_tag "govuk:ab-test",
      ab_test.meta_tag_name + ':' + requested_variant.variant_name,
      args[:dimension],
      "You probably forgot to add the `analytics_meta_tag`"
  end
end