3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/govuk_ab_testing/minitest_helpers.rb', line 3
def with_variant(args)
ab_test_name, variant = args.first
dimension = args[:dimension]
ab_test =
GovukAbTesting::AbTest.new(ab_test_name.to_s, dimension: dimension)
@request.[ab_test.] = variant
requested_variant = ab_test.requested_variant(@request)
yield
assert_match ab_test., response.['Vary'],
"You probably forgot to use `configure_response`"
unless args[:assert_meta_tag] == false
expected_content =
ab_test.meta_tag_name + ':' + requested_variant.variant_name
message = "You probably forgot to add the `analytics_meta_tag` to the views"
meta_tags = css_select("meta[name='govuk:ab-test']")
assert_equal(1, meta_tags.count, message)
meta_tag = meta_tags.first
content_value = meta_tag.attributes['content'].value
dimension_value = meta_tag.attributes['data-analytics-dimension'].value
assert_equal(
expected_content,
content_value,
"Meta tag's content doesn't match."
)
if dimension.nil?
assert(dimension_value, "No custom dimension number found")
else
assert_equal(
dimension.to_s,
dimension_value,
"The custom dimension found in meta tag doesn't match"
)
end
end
end
|