-
-
Notifications
You must be signed in to change notification settings - Fork 530
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce
suspenders:accessibility
generator
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
1 parent
84e0c95
commit e963ee1
Showing
4 changed files
with
85 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
61
test/generators/suspenders/accessibility_generator_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |