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

WIP Introduce suspenders:lint generator #1143

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ GEM

PLATFORMS
arm64-darwin-21
arm64-darwin-22
x86_64-linux

DEPENDENCIES
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Unreleased
* Remove `suspenders` system executable
* Introduce `suspenders:accessibility` generator
* Introduce `Suspenders::Generators::APIAppUnsupported` module and concern
* Introduce `suspenders:lint` generator

20230113.0 (January, 13, 2023)

Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ Installs [capybara_accessibility_audit] and [capybara_accessible_selectors]
[capybara_accessibility_audit]: https://github.com/thoughtbot/capybara_accessibility_audit
[capybara_accessible_selectors]: https://github.com/citizensadvice/capybara_accessible_selectors

### Lint

Installs [standard].

[standard]: https://github.com/standardrb/standard

## Contributing

See the [CONTRIBUTING] document.
Expand Down
14 changes: 14 additions & 0 deletions lib/generators/suspenders/lint_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Suspenders
module Generators
class LintGenerator < Rails::Generators::Base
desc "Sets up standard"

def setup_standard
gem "standard", group: [:development, :test]
Bundler.with_unbundled_env { run "bundle install" }
prepend_to_file("Rakefile", 'require "standard/rake"')
end
end
end
end

6 changes: 0 additions & 6 deletions test/dummy/Rakefile

This file was deleted.

66 changes: 66 additions & 0 deletions test/generators/suspenders/lint_generator_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
require "test_helper"
require "generators/suspenders/lint_generator"

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

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

test "adds gem to Gemfile" do
expected_output = <<~RUBY
gem "standard", group: [:development, :test]
RUBY

run_generator

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

test "adds require to Rakefile" do
expected_output = <<~RUBY
require "standard/rake"
RUBY

run_generator

assert_file app_root("Rakefile") do |file|
assert_match(expected_output.strip, file.strip)
end
end

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

capture(:stdout) do
generator.setup_standard
end
end

test "generator has a description" do
description = "Sets up standard"

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

private

def prepare_destination
touch "Gemfile"
touch "Rakefile"
end

def restore_destination
remove_file_if_exists "Gemfile"
remove_file_if_exists "Rakefile"
end
end
end
end
Loading