Class: GovukAbTesting::AcceptanceTests::Capybara

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scope) ⇒ Capybara

Returns a new instance of Capybara.



6
7
8
9
10
11
12
13
# File 'lib/govuk_ab_testing/acceptance_tests/capybara.rb', line 6

def initialize(scope)
  unless scope.respond_to?(:page)
    raise "Page is not defined, are you using capybara?"
  end

  @capybara_page = scope.page
  @request_headers = {}
end

Instance Attribute Details

#capybara_pageObject (readonly)

Returns the value of attribute capybara_page.



4
5
6
# File 'lib/govuk_ab_testing/acceptance_tests/capybara.rb', line 4

def capybara_page
  @capybara_page
end

#request_headersObject (readonly)

Returns the value of attribute request_headers.



4
5
6
# File 'lib/govuk_ab_testing/acceptance_tests/capybara.rb', line 4

def request_headers
  @request_headers
end

Instance Method Details

#analytics_meta_tagsObject



34
35
36
37
38
39
40
41
42
# File 'lib/govuk_ab_testing/acceptance_tests/capybara.rb', line 34

def analytics_meta_tags
  tags = capybara_page.all(ANALYTICS_META_TAG_SELECTOR, visible: :all)

  tags.map do |tag|
    MetaTag.new(
      content: tag["content"],
    )
  end
end

#analytics_meta_tags_for_test(ab_test_name) ⇒ Object



30
31
32
# File 'lib/govuk_ab_testing/acceptance_tests/capybara.rb', line 30

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/capybara.rb', line 15

def request
  @capybara_page
end

#set_header(name, value) ⇒ Object



19
20
21
22
23
24
# File 'lib/govuk_ab_testing/acceptance_tests/capybara.rb', line 19

def set_header(name, value)
  capybara_page.driver.options[:headers] ||= {}
  capybara_page.driver.options[:headers][name] = value
  capybara_page.driver.header(name, value)
  @request_headers[name] = value
end

#vary_headerObject



26
27
28
# File 'lib/govuk_ab_testing/acceptance_tests/capybara.rb', line 26

def vary_header(*)
  capybara_page.response_headers["Vary"]
end