Class: GovukRSpecHelpers::WithinGovukFieldset

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page:, legend_text:, hint:, block:) ⇒ WithinGovukFieldset

Returns a new instance of WithinGovukFieldset.



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

def initialize(page:, legend_text:, hint:, block:)
  @legend_text = legend_text
  @hint = hint
  @page = page
  @block = block
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



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

def block
  @block
end

#hintObject (readonly)

Returns the value of attribute hint.



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

def hint
  @hint
end

#legend_textObject (readonly)

Returns the value of attribute legend_text.



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

def legend_text
  @legend_text
end

#pageObject (readonly)

Returns the value of attribute page.



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

def page
  @page
end

Instance Method Details

#withinObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/within_govuk_fieldset.rb', line 13

def within

  legends = page.all('legend', text: legend_text, exact_text: true, normalize_ws: true)

  if legends.size == 0
    check_for_fieldset_id_match
    raise "No fieldset found with matching legend"
  end

  legend = legends.first
  @fieldset = legend.ancestor('fieldset')

  check_hint

  @page.within(@fieldset) do
    block.call
  end
end