Module: GovukAbTesting::MinitestHelpers
- Defined in:
- lib/govuk_ab_testing/minitest_helpers.rb
Instance Method Summary collapse
- #acceptance_test_framework ⇒ Object
- #assert_response_not_modified_for_ab_test ⇒ Object
- #setup_ab_variant(ab_test_name, variant, dimension = 300) ⇒ Object
- #with_variant(args) ⇒ Object
Instance Method Details
#acceptance_test_framework ⇒ Object
3 4 5 6 |
# File 'lib/govuk_ab_testing/minitest_helpers.rb', line 3 def acceptance_test_framework @acceptance_test_framework ||= GovukAbTesting.configuration.framework_class.new(self) end |
#assert_response_not_modified_for_ab_test ⇒ Object
58 59 60 61 62 63 |
# File 'lib/govuk_ab_testing/minitest_helpers.rb', line 58 def assert_response_not_modified_for_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 = 300) ⇒ Object
52 53 54 55 56 |
# File 'lib/govuk_ab_testing/minitest_helpers.rb', line 52 def setup_ab_variant(ab_test_name, variant, dimension = 300) ab_test = GovukAbTesting::AbTest.new(ab_test_name, dimension: dimension) acceptance_test_framework.set_header(ab_test.request_header, variant) end |
#with_variant(args) ⇒ Object
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 47 48 49 50 |
# File 'lib/govuk_ab_testing/minitest_helpers.rb', line 8 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) acceptance_test_framework.set_header(ab_test.request_header, variant) requested_variant = ab_test.requested_variant(acceptance_test_framework.request_headers) yield vary_header_value = acceptance_test_framework.vary_header(response) assert_match ab_test.response_header, vary_header_value, "You probably forgot to use `configure_response`" unless args[:assert_meta_tag] == false expected_content = ab_test. + ':' + requested_variant.variant_name = "You probably forgot to add the `analytics_meta_tag` to the views" = acceptance_test_framework. assert_equal(1, .count, ) dimension_value = acceptance_test_framework.dimension assert_equal( expected_content, acceptance_test_framework.content, "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 |