Skip to content

Commit

Permalink
add guard for rails restart, formatting, and specs
Browse files Browse the repository at this point in the history
  • Loading branch information
indirect committed Jan 13, 2022
1 parent 2f685eb commit 73bd254
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ end

group :development do
gem "bundler-audit", "~> 0.9.0"
gem "guard-rspec", "~> 4.7"
gem "guard-shell", "~> 0.7.2"
gem "guard-standardrb", "~> 0.2.2"
gem "hotwire-livereload", "~> 1.0"
gem "standard", "~> 1.6"
gem "web-console", "~> 4.2"
Expand Down
41 changes: 41 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ GEM
bundler-audit (0.9.0.1)
bundler (>= 1.2.0, < 3)
thor (~> 1.0)
coderay (1.1.3)
concurrent-ruby (1.1.9)
crass (1.0.6)
debug (1.4.0)
Expand All @@ -92,11 +93,33 @@ GEM
digest (3.1.0)
erubi (1.10.0)
ffi (1.15.5)
formatador (0.3.0)
globalid (1.0.0)
activesupport (>= 5.0)
griddler (1.5.2)
htmlentities
rails (>= 3.2.0)
guard (2.18.0)
formatador (>= 0.2.4)
listen (>= 2.7, < 4.0)
lumberjack (>= 1.0.12, < 2.0)
nenv (~> 0.1)
notiffany (~> 0.0)
pry (>= 0.13.0)
shellany (~> 0.0)
thor (>= 0.18.1)
guard-compat (1.2.1)
guard-rspec (4.7.3)
guard (~> 2.1)
guard-compat (~> 1.1)
rspec (>= 2.99.0, < 4.0)
guard-shell (0.7.2)
guard (>= 2.0.0)
guard-compat (~> 1.0)
guard-standardrb (0.2.2)
guard (>= 2.0.0)
guard-compat (~> 1.0)
standardrb
honeybadger (4.9.0)
hotwire-livereload (1.0.0)
listen (>= 3.0.0)
Expand Down Expand Up @@ -125,13 +148,15 @@ GEM
loofah (2.13.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
lumberjack (1.2.8)
mail (2.7.1)
mini_mime (>= 0.1.1)
marcel (1.0.2)
method_source (1.0.0)
mini_mime (1.1.2)
minitest (5.15.0)
msgpack (1.4.2)
nenv (0.3.0)
net-imap (0.2.3)
digest
net-protocol
Expand All @@ -155,10 +180,16 @@ GEM
racc (~> 1.4)
nokogiri (1.13.0-x86_64-linux)
racc (~> 1.4)
notiffany (0.1.3)
nenv (~> 0.1)
shellany (~> 0.0)
parallel (1.21.0)
parser (3.1.0.0)
ast (~> 2.4.1)
pg (1.2.3)
pry (0.14.1)
coderay (~> 1.1)
method_source (~> 1.0)
public_suffix (4.0.6)
puma (5.5.2)
nio4r (~> 2.0)
Expand Down Expand Up @@ -207,6 +238,10 @@ GEM
request_store (1.5.0)
rack (>= 1.4)
rexml (3.2.5)
rspec (3.10.0)
rspec-core (~> 3.10.0)
rspec-expectations (~> 3.10.0)
rspec-mocks (~> 3.10.0)
rspec-core (3.10.1)
rspec-support (~> 3.10.0)
rspec-expectations (3.10.1)
Expand Down Expand Up @@ -239,6 +274,7 @@ GEM
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
ruby-progressbar (1.11.0)
shellany (0.0.1)
sprockets (4.0.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
Expand All @@ -249,6 +285,8 @@ GEM
standard (1.6.0)
rubocop (= 1.24.1)
rubocop-performance (= 1.13.1)
standardrb (1.0.0)
standard
stimulus-rails (1.0.2)
railties (>= 6.0.0)
strscan (3.0.1)
Expand Down Expand Up @@ -285,6 +323,9 @@ DEPENDENCIES
bundler-audit (~> 0.9.0)
debug (~> 1.4)
griddler-postmark (~> 1.0)!
guard-rspec (~> 4.7)
guard-shell (~> 0.7.2)
guard-standardrb (~> 0.2.2)
honeybadger (~> 4.9)
hotwire-livereload (~> 1.0)
importmap-rails (~> 1.0)
Expand Down
50 changes: 50 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Restart puma-dev when application things change
guard :shell do
watch("Gemfile.lock") { `touch tmp/restart.txt` }
watch(%r{^config|lib/.*}) { `touch tmp/restart.txt` }
end

# Just make everything standard. Please. I don't want to talk about it.
guard :standardrb, fix: false, all_on_start: false, progress: false do
watch(/.+\.rb$/)
end

# Run tests automatically as related files change
guard :rspec, cmd: "bin/rspec", bundler_env: :inherit do
require "guard/rspec/dsl"
dsl = Guard::RSpec::Dsl.new(self)

# Feel free to open issues for suggestions and improvements

# RSpec files
rspec = dsl.rspec
watch(rspec.spec_helper) { rspec.spec_dir }
watch(rspec.spec_support) { rspec.spec_dir }
watch(rspec.spec_files)

# Ruby files
ruby = dsl.ruby
dsl.watch_spec_files_for(ruby.lib_files)

# Rails files
rails = dsl.rails(view_extensions: %w[erb haml slim])
dsl.watch_spec_files_for(rails.app_files)
dsl.watch_spec_files_for(rails.views)

watch(rails.controllers) do |m|
[
rspec.spec.call("routing/#{m[1]}_routing"),
rspec.spec.call("controllers/#{m[1]}_controller"),
rspec.spec.call("requests/#{m[1]}")
]
end

# Rails config changes
watch(rails.spec_helper) { rspec.spec_dir }
watch(rails.routes) { "#{rspec.spec_dir}/routing" }
watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }

# Capybara features specs
watch(rails.view_dirs) { |m| rspec.spec.call("requests/#{m[1]}") }
watch(rails.layouts) { |m| rspec.spec.call("requests/#{m[1]}") }
end
1 change: 1 addition & 0 deletions Procfile.dev
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
web: bin/rails server -p 3000
css: bin/rails tailwindcss:watch
guard: bin/guard
29 changes: 29 additions & 0 deletions bin/guard
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'guard' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)

bundle_binstub = File.expand_path("../bundle", __FILE__)

if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
load(bundle_binstub)
else
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
end
end

require "rubygems"
require "bundler/setup"

load Gem.bin_path("guard", "guard")

0 comments on commit 73bd254

Please sign in to comment.