diff --git a/Gemfile b/Gemfile index 0e6b318ffe35..18739a491f1e 100644 --- a/Gemfile +++ b/Gemfile @@ -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" diff --git a/Gemfile.lock b/Gemfile.lock index ffce7edab9c9..071692c3499c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -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) @@ -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) @@ -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 @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -1197,7 +1213,7 @@ GEM zeitwerk (2.7.1) PLATFORMS - ruby + x86_64-linux DEPENDENCIES actionpack-xml_parser (~> 2.0.0) @@ -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 diff --git a/Guardfile b/Guardfile index 4d787422605f..4dd7a422bc7e 100644 --- a/Guardfile +++ b/Guardfile @@ -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 + require "guard/rspec/dsl" + + 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' } diff --git a/docker-compose.override.example.yml b/docker-compose.override.example.yml index 96095d1b6e44..81ae453a4d9d 100644 --- a/docker-compose.override.example.yml +++ b/docker-compose.override.example.yml @@ -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: diff --git a/docker-compose.yml b/docker-compose.yml index 67af270b8c7c..906311b283f1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -140,6 +140,8 @@ services: build: <<: *build target: test + tty: true + stdin_open: true command: setup-tests hostname: backend-test networks: diff --git a/docker/dev/backend/scripts/setup-tests b/docker/dev/backend/scripts/setup-tests index ddcdd7e5755b..eb74db7b75af 100755 --- a/docker/dev/backend/scripts/setup-tests +++ b/docker/dev/backend/scripts/setup-tests @@ -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