Class: AxeMatchers::ResultFormatter

Inherits:
Object
  • Object
show all
Defined in:
decidim-dev/lib/decidim/dev/test/rspec_support/accessibility_examples.rb

Instance Method Summary collapse

Constructor Details

#initialize(result) ⇒ ResultFormatter

Returns a new instance of ResultFormatter.



16
17
18
19
# File 'decidim-dev/lib/decidim/dev/test/rspec_support/accessibility_examples.rb', line 16

def initialize(result)
  @result = result
  @violations = result["violations"]
end

Instance Method Details

#formatObject



21
22
23
24
25
26
27
28
# File 'decidim-dev/lib/decidim/dev/test/rspec_support/accessibility_examples.rb', line 21

def format
  <<~MESSAGE

    Found #{violations.count} accessibility #{violations.count == 1 ? "violation" : "violations"}:

    #{violation_messages.join("\n")}
  MESSAGE
end

#violation_messagesObject



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'decidim-dev/lib/decidim/dev/test/rspec_support/accessibility_examples.rb', line 30

def violation_messages
  violations.each_with_index.map do |violation, index|
    nodes = violation["nodes"]
    [
      "#{index + 1}) #{violation["id"]}: #{violation["help"]} (#{violation["impact"]})",
      indent_lines(violation["helpUrl"], 1),
      indent_lines("The following #{nodes.length} #{nodes.length == 1 ? "node" : "nodes"} violate this rule:", 1),
      "",
      indent_lines(node_messages_for(nodes), 2),
      ""
    ]
  end.flatten
end