Module: CapybaraAccessibilityAudit::AuditSystemTestExtensions

Extended by:
ActiveSupport::Concern
Defined in:
lib/capybara_accessibility_audit/audit_system_test_extensions.rb

Constant Summary collapse

if defined?(Capybara::Session::MODAL_METHODS)
  Capybara::Session::MODAL_METHODS
else
  %i[accept_alert accept_confirm accept_prompt dismiss_confirm dismiss_prompt]
end

Instance Method Summary collapse

Instance Method Details

#assert_no_accessibility_violations(**options) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/capybara_accessibility_audit/audit_system_test_extensions.rb', line 92

def assert_no_accessibility_violations(**options)
  options.assert_valid_keys(
    :according_to,
    :checking,
    :checking_only,
    :excluding,
    :skipping,
    :within
  )
  options.compact_blank!

  axe_matcher = Axe::Matchers::BeAxeClean.new
  axe_matcher = options.inject(axe_matcher) { |matcher, option| matcher.public_send(*option) }

  assert axe_matcher.matches?(page), axe_matcher.failure_message
end

#skip_accessibility_audits(&block) ⇒ Object



74
75
76
77
78
79
80
81
# File 'lib/capybara_accessibility_audit/audit_system_test_extensions.rb', line 74

def skip_accessibility_audits(&block)
  accessibility_audit_enabled = self.accessibility_audit_enabled
  self.accessibility_audit_enabled = false

  block.call
ensure
  self.accessibility_audit_enabled = accessibility_audit_enabled
end

#skip_accessibility_violations(value, &block) ⇒ Object



83
84
85
86
87
88
89
90
# File 'lib/capybara_accessibility_audit/audit_system_test_extensions.rb', line 83

def skip_accessibility_violations(value, &block)
  skipping = accessibility_audit_options.skipping
  accessibility_audit_options.skipping = Array(value)

  block.call
ensure
  accessibility_audit_options.skipping = skipping
end

#with_accessibility_audit_options(**options, &block) ⇒ Object



65
66
67
68
69
70
71
72
# File 'lib/capybara_accessibility_audit/audit_system_test_extensions.rb', line 65

def with_accessibility_audit_options(**options, &block)
  accessibility_audit_options = self.accessibility_audit_options
  self.accessibility_audit_options = accessibility_audit_options.merge(options)

  block.call
ensure
  self.accessibility_audit_options = accessibility_audit_options
end

#with_accessibility_audits(**options, &block) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/capybara_accessibility_audit/audit_system_test_extensions.rb', line 52

def with_accessibility_audits(**options, &block)
  accessibility_audit_enabled = self.accessibility_audit_enabled
  self.accessibility_audit_enabled = true

  if options.present?
    with_accessibility_audit_options(**options, &block)
  else
    block.call
  end
ensure
  self.accessibility_audit_enabled = accessibility_audit_enabled
end