Skip to content

Commit

Permalink
Add Guard
Browse files Browse the repository at this point in the history
  • Loading branch information
top4ek committed Dec 5, 2024
1 parent 2df25c8 commit a33bd23
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 20 deletions.
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ group :test do
gem "rack-test", "~> 2.1.0"
gem "shoulda-context", "~> 2.0"

# Run specs with guard
gem "guard"
gem "guard-rspec"

# Test prof provides factories from code
# and other niceties
gem "test-prof", "~> 1.4.0"
Expand Down
34 changes: 26 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,7 @@ GEM
descendants_tracker (~> 0.0.1)
color_conversion (0.1.2)
colored2 (4.0.0)
commonmarker (1.1.5)
rb_sys (~> 0.9)
commonmarker (1.1.5-x86_64-linux)
compare-xml (0.66)
nokogiri (~> 1.8)
concurrent-ruby (1.3.4)
Expand Down Expand Up @@ -565,7 +564,7 @@ GEM
concurrent-ruby (~> 1.1)
webrick (~> 1.7)
websocket-driver (~> 0.7)
ffi (1.17.0)
ffi (1.17.0-x86_64-linux-gnu)
flamegraph (0.9.5)
fog-aws (3.29.0)
base64 (~> 0.2.0)
Expand Down Expand Up @@ -637,6 +636,20 @@ GEM
grape
rack
gravatar_image_tag (1.2.0)
guard (2.19.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)
hana (1.3.7)
hashdiff (1.1.2)
hashery (2.1.2)
Expand Down Expand Up @@ -743,6 +756,7 @@ GEM
view_component (>= 2.0)
yard (~> 0.9)
zeitwerk (~> 2.5)
lumberjack (1.2.10)
mail (2.8.1)
mini_mime (>= 0.1.1)
net-imap
Expand All @@ -761,7 +775,6 @@ GEM
mime-types-data (3.2024.1105)
mini_magick (5.0.1)
mini_mime (1.1.5)
mini_portile2 (2.8.8)
minitest (5.25.2)
msgpack (1.7.5)
multi_json (1.15.0)
Expand All @@ -770,6 +783,7 @@ GEM
mustermann-grape (1.1.0)
mustermann (>= 1.0.0)
mutex_m (0.3.0)
nenv (0.3.0)
net-http (0.6.0)
uri
net-imap (0.5.1)
Expand All @@ -783,9 +797,11 @@ GEM
net-smtp (0.5.0)
net-protocol
nio4r (2.7.4)
nokogiri (1.16.8)
mini_portile2 (~> 2.8.2)
nokogiri (1.16.8-x86_64-linux)
racc (~> 1.4)
notiffany (0.1.3)
nenv (~> 0.1)
shellany (~> 0.0)
oj (3.16.7)
bigdecimal (>= 3.0)
ostruct (>= 0.2)
Expand Down Expand Up @@ -955,7 +971,6 @@ GEM
rb-fsevent (0.11.2)
rb-inotify (0.11.1)
ffi (~> 1.0)
rb_sys (0.9.103)
rbtrace (0.5.1)
ffi (>= 1.0.6)
msgpack (>= 0.4.3)
Expand Down Expand Up @@ -1075,6 +1090,7 @@ GEM
rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0)
semantic (1.6.1)
shellany (0.0.1)
shoulda-context (2.0.0)
shoulda-matchers (6.4.0)
activesupport (>= 5.2.0)
Expand Down Expand Up @@ -1197,7 +1213,7 @@ GEM
zeitwerk (2.7.1)

PLATFORMS
ruby
x86_64-linux

DEPENDENCIES
actionpack-xml_parser (~> 2.0.0)
Expand Down Expand Up @@ -1265,6 +1281,8 @@ DEPENDENCIES
grape (~> 2.2.0)
grape_logging (~> 1.8.4)
grids!
guard
guard-rspec
html-pipeline (~> 2.14.0)
htmldiff
httpx
Expand Down
41 changes: 31 additions & 10 deletions Guardfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,38 @@
# See COPYRIGHT and LICENSE files for more details.
#++

guard :rspec do # , :cli => "--drb" do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { 'spec' }

# Rails example
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) do |m|
["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"]
guard :rspec, cmd: 'spring rspec --format d' do

Check warning on line 29 in Guardfile

View workflow job for this annotation

GitHub Actions / rubocop

[rubocop] reported by reviewdog 🐶 Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. Raw Output: Guardfile:29:20: C: Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
require 'guard/rspec/dsl'

Check warning on line 30 in Guardfile

View workflow job for this annotation

GitHub Actions / rubocop

[rubocop] reported by reviewdog 🐶 Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. Raw Output: Guardfile:30:11: C: Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

dsl = Guard::RSpec::Dsl.new(self)
rspec = dsl.rspec
watch(rspec.spec_helper) { rspec.spec_dir }
watch(rspec.spec_support) { rspec.spec_dir }
watch(rspec.spec_files)

watch(/^modules\/(.+)\/spec\/(.+)_helper\.rb$/) { |m| "modules/#{m[1]}/spec" }
watch(/^modules\/(.+)\/spec\/support\/(.+)\.rb$/) { |m| "modules/#{m[1]}/spec" }
watch(/^modules\/(.*)\/app\/(.+)\.rb$/) { |m| "modules/#{m[1]}/spec/#{m[2]}_spec.rb" }
watch(/^modules\/(.*)\/spec\/(.+)_spec\.rb$/)

ruby = dsl.ruby
dsl.watch_spec_files_for(ruby.lib_files)
rails = dsl.rails(view_extensions: %w[erb slim])
watch(rails.spec_helper) { rspec.spec_dir }
watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }

dsl.watch_spec_files_for(rails.app_files)
dsl.watch_spec_files_for(rails.views)

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

watch(/^lib\/(.+)\.rb$/) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch(%r{^spec/support/(.+)\.rb$}) { 'spec' }
watch('config/routes.rb') { 'spec/routing' }
watch('app/controllers/application_controller.rb') { 'spec/controllers' }
Expand Down
4 changes: 4 additions & 0 deletions docker-compose.override.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ services:
ports:
- "${PORT:-3000}:3000"

# backend-test:
# environment:
# START_GUARD: 1

frontend:
# use these ports to be able to access the stack under http://localhost:4200
ports:
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ services:
build:
<<: *build
target: test
tty: true
stdin_open: true
command: setup-tests
hostname: backend-test
networks:
Expand Down
9 changes: 7 additions & 2 deletions docker/dev/backend/scripts/setup-tests
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,10 @@ echo "to start the full suite, or "
echo " bin/compose exec backend-test bundle exec rspec path/to/some_spec.rb"
echo "to run a subset"

# Keep this container online
while true; do sleep 1000; done;
if [ ${START_GUARD} = "1" ]; then
echo "or use Guard gem events to run a specific tests.\n"
bundle exec guard start --no-bundler-warning
else
# Keep this container online
while true; do sleep 1000; done;
fi

0 comments on commit a33bd23

Please sign in to comment.