Class: GovukRSpecHelpers::ChooseGovukRadio

Inherits:
Object
  • Object
show all
Defined in:
lib/choose_govuk_radio.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page:, label_text:, hint_text:) ⇒ ChooseGovukRadio

Returns a new instance of ChooseGovukRadio.



6
7
8
9
10
# File 'lib/choose_govuk_radio.rb', line 6

def initialize(page:, label_text:, hint_text:)
  @label_text = label_text
  @hint_text = hint_text
  @page = page
end

Instance Attribute Details

#hint_textObject (readonly)

Returns the value of attribute hint_text.



4
5
6
# File 'lib/choose_govuk_radio.rb', line 4

def hint_text
  @hint_text
end

#label_textObject (readonly)

Returns the value of attribute label_text.



4
5
6
# File 'lib/choose_govuk_radio.rb', line 4

def label_text
  @label_text
end

#pageObject (readonly)

Returns the value of attribute page.



4
5
6
# File 'lib/choose_govuk_radio.rb', line 4

def page
  @page
end

Instance Method Details

#chooseObject



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
# File 'lib/choose_govuk_radio.rb', line 12

def choose
  labels = page.all('label', text: label_text, exact_text: true, normalize_ws: true)

  if labels.size == 0
    check_for_input_id_match

    raise "Unable to find label with the text \"#{label_text}\""
  end

  @label = labels.first

  inputs_matching_label = page.all(id: @label[:for])

  if inputs_matching_label.size == 1
    @input = inputs_matching_label.first
  end

  check_that_fieldset_legend_was_specified

  if hint_text
    check_for_hint
    check_that_hint_is_associated_with_input
  end


  @label.click
end