Class: GovukAbTesting::AcceptanceTests::ActiveSupport

Inherits:
Object
  • Object
show all
Defined in:
lib/govuk_ab_testing/acceptance_tests/active_support.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_headersObject (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

#scopeObject (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_tagsObject



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 analytics_meta_tags
  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

  tags = scope.css_select(ANALYTICS_META_TAG_SELECTOR)

  tags.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 analytics_meta_tags_for_test(ab_test_name)
  analytics_meta_tags.select { |tag| tag.for_ab_test?(ab_test_name) }
end

#requestObject



15
16
17
# File 'lib/govuk_ab_testing/acceptance_tests/active_support.rb', line 15

def request
  @scope.instance_variable_get(:@request)
end

#responseObject



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_headerObject



28
29
30
# File 'lib/govuk_ab_testing/acceptance_tests/active_support.rb', line 28

def vary_header
  response.headers["Vary"]
end