Class: GovukAbTesting::AcceptanceTests::ActiveSupport
- Inherits:
-
Object
- Object
- GovukAbTesting::AcceptanceTests::ActiveSupport
- Defined in:
- lib/govuk_ab_testing/acceptance_tests/active_support.rb
Instance Attribute Summary collapse
-
#request_headers ⇒ Object
readonly
Returns the value of attribute request_headers.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
Instance Method Summary collapse
- #analytics_meta_tags ⇒ Object
- #analytics_meta_tags_for_test(ab_test_name) ⇒ Object
-
#initialize(scope) ⇒ ActiveSupport
constructor
A new instance of ActiveSupport.
- #request ⇒ Object
- #response ⇒ Object
- #set_header(name, value) ⇒ Object
- #vary_header ⇒ Object
Constructor Details
#initialize(scope) ⇒ ActiveSupport
Returns a new instance of ActiveSupport.
6 7 8 9 10 11 12 13 |
# File 'lib/govuk_ab_testing/acceptance_tests/active_support.rb', line 6 def initialize(scope) @scope = scope @request_headers = {} if request.nil? raise "Couldn't find '@request' defined, are you using ActiveSupport test cases?" end end |
Instance Attribute Details
#request_headers ⇒ Object (readonly)
Returns the value of attribute request_headers.
4 5 6 |
# File 'lib/govuk_ab_testing/acceptance_tests/active_support.rb', line 4 def request_headers @request_headers end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
4 5 6 |
# File 'lib/govuk_ab_testing/acceptance_tests/active_support.rb', line 4 def scope @scope end |
Instance Method Details
#analytics_meta_tags ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/govuk_ab_testing/acceptance_tests/active_support.rb', line 36 def if scope.response.body.empty? raise "Cannot find response body. If this is an RSpec Rails test, " \ "check that 'render_views' is being called." end = scope.css_select(ANALYTICS_META_TAG_SELECTOR) .map do |tag| MetaTag.new( content: tag.attributes["content"].value, ) end end |
#analytics_meta_tags_for_test(ab_test_name) ⇒ Object
32 33 34 |
# File 'lib/govuk_ab_testing/acceptance_tests/active_support.rb', line 32 def (ab_test_name) .select { |tag| tag.for_ab_test?(ab_test_name) } end |
#request ⇒ Object
15 16 17 |
# File 'lib/govuk_ab_testing/acceptance_tests/active_support.rb', line 15 def request @scope.instance_variable_get(:@request) end |
#response ⇒ Object
19 20 21 |
# File 'lib/govuk_ab_testing/acceptance_tests/active_support.rb', line 19 def response @scope.instance_variable_get(:@response) end |
#set_header(name, value) ⇒ Object
23 24 25 26 |
# File 'lib/govuk_ab_testing/acceptance_tests/active_support.rb', line 23 def set_header(name, value) request.headers[name] = value @request_headers[name] = value end |
#vary_header ⇒ Object
28 29 30 |
# File 'lib/govuk_ab_testing/acceptance_tests/active_support.rb', line 28 def vary_header response.headers["Vary"] end |