Skip to content

Commit

Permalink
Introduce suspenders:accessibility generator
Browse files Browse the repository at this point in the history
Ported over from #1105

Installs [capybara_accessibility_audit] and
[capybara_accessible_selectors].

`./bin/rails g suspenders:accessibility`

[capybara_accessibility_audit]: https://github.com/thoughtbot/capybara_accessibility_audit
[capybara_accessible_selectors]: https://github.com/citizensadvice/capybara_accessible_selectors
  • Loading branch information
stevepolitodesign committed Oct 31, 2023
1 parent 84e0c95 commit e963ee1
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 1 deletion.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Unreleased

* Remove `suspenders` system executable
* Introduce `suspenders:accessibility` generator

20230113.0 (January, 13, 2023)

Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@ end

## Generators

TODO
### Accessibility

Installs [capybara_accessibility_audit] and [capybara_accessible_selectors]

`./bin/rails g suspenders:accessibility`

[capybara_accessibility_audit]: https://github.com/thoughtbot/capybara_accessibility_audit
[capybara_accessible_selectors]: https://github.com/citizensadvice/capybara_accessible_selectors

## Contributing

Expand Down
15 changes: 15 additions & 0 deletions lib/generators/suspenders/accessibility_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Suspenders
module Generators
class AccessibilityGenerator < Rails::Generators::Base
desc "Installs capybara_accessibility_audit and capybara_accessible_selectors"

def add_capybara_gems
gem_group :test do
gem "capybara_accessibility_audit"
gem "capybara_accessible_selectors", github: "citizensadvice/capybara_accessible_selectors"
end
Bundler.with_unbundled_env { run "bundle install" }
end
end
end
end
61 changes: 61 additions & 0 deletions test/generators/suspenders/accessibility_generator_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
require "test_helper"
require "generators/suspenders/accessibility_generator"

module Suspenders
module Generators
class AccessibilityGeneratorTest < Rails::Generators::TestCase
include Suspenders::TestHelpers

tests Suspenders::Generators::AccessibilityGenerator
destination Rails.root
setup :prepare_destination
teardown :restore_destination

test "generator runs without errors" do
assert_nothing_raised do
run_generator
end
end

test "adds gems to Gemfile" do
expected_output = <<~RUBY
group :test do
gem "capybara_accessibility_audit"
gem "capybara_accessible_selectors", github: "citizensadvice/capybara_accessible_selectors"
end
RUBY

run_generator

assert_file app_root("Gemfile") do |file|
assert_match(expected_output, file)
end
end

test "installs gems with Bundler" do
Bundler.stubs(:with_unbundled_env).yields
generator.expects(:run).with("bundle install").once

capture(:stdout) do
generator.add_capybara_gems
end
end

test "generator has a description" do
description = "Installs capybara_accessibility_audit and capybara_accessible_selectors"

assert_equal description, Suspenders::Generators::AccessibilityGenerator.desc
end

private

def prepare_destination
touch "Gemfile"
end

def restore_destination
remove_file_if_exists "Gemfile"
end
end
end
end

0 comments on commit e963ee1

Please sign in to comment.