Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow marking tests Pending when they fail audits #22

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,17 @@ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
end
```

How can I make all of the failing tests just be pending instead of failures?
---

You can allow automated auditing, but mark tests that fail the auditing be marked as `pending` instead of `failed`:

```ruby
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
self.accessibility_audit_skip_on_error = true
end
```

How can I turn off auditing for a block of code?
---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module AuditSystemTestExtensions
included do
class_attribute :accessibility_audit_after_methods, default: Set.new
class_attribute :accessibility_audit_enabled, default: true
class_attribute :accessibility_audit_skip_on_error, default: false
class_attribute :accessibility_audit_options, default: ActiveSupport::OrderedOptions.new

MODAL_METHODS.each do |method|
Expand Down Expand Up @@ -51,6 +52,7 @@ def skip_accessibility_audit_after(*methods)

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

if options.present?
Expand Down Expand Up @@ -103,7 +105,12 @@ def assert_no_accessibility_violations(**options)
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
page_axe_match = axe_matcher.matches?(page)
if !page_axe_match && self.accessibility_audit_skip_on_error
skip(axe_matcher.failure_message)
else
assert page_axe_match, axe_matcher.failure_message
end
end
end
end
14 changes: 14 additions & 0 deletions spec/system/audit_assertions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,20 @@
end
end

describe "Make failing tests Pending" do
before do
self.accessibility_audit_skip_on_error = true
end

it "marks violation test as pending" do
allow_any_instance_of(RSpec::Core::Pending).to receive(:skip)
visit violations_path
click_on "Violate rule: label"
go_back
click_on "Violate rule: image-alt"
end
end

describe "Disabling" do
before do
self.accessibility_audit_enabled = false
Expand Down