Skip to content

Commit

Permalink
dev: added guard for auto selective test running
Browse files Browse the repository at this point in the history
  • Loading branch information
ryantk committed Dec 15, 2023
1 parent feff4a8 commit 4a2628c
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,15 @@ gem "wisper", "2.0.1"
group :development, :test do
gem "byebug", platforms: %i[mri mingw x64_mingw]
gem "dotenv-rails"
gem "guard-rspec", require: false
gem "i18n-tasks"
gem "knapsack"
gem "pry-byebug"
gem "pry-rails"
gem "rubocop-govuk", require: false
gem "rubocop-performance", require: false
gem "terminal-notifier"
gem "terminal-notifier-guard", "~> 1.6.1"
end

group :development do
Expand Down
30 changes: 30 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ GEM
rack-protection (>= 1.5.3, <= 4.0.0)
sanitize (< 7)
foreman (0.87.2)
formatador (1.1.0)
fugit (1.9.0)
et-orbi (~> 1, >= 1.2.7)
raabro (~> 1.4)
Expand All @@ -284,6 +285,20 @@ GEM
activemodel (>= 6.1)
activesupport (>= 6.1)
html-attributes-utils (~> 1)
guard (2.18.1)
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)
hashdiff (1.0.1)
hashie (5.0.0)
highline (2.1.0)
Expand Down Expand Up @@ -355,6 +370,7 @@ GEM
loofah (2.22.0)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
lumberjack (1.2.10)
mail (2.8.1)
mini_mime (>= 0.1.1)
net-imap
Expand All @@ -372,6 +388,7 @@ GEM
multi_json (1.15.0)
multi_xml (0.6.0)
mutex_m (0.2.0)
nenv (0.3.0)
net-http-persistent (4.0.2)
connection_pool (~> 2.2)
net-imap (0.4.7)
Expand All @@ -390,6 +407,9 @@ GEM
racc (~> 1.4)
nokogiri (1.15.5-x86_64-linux)
racc (~> 1.4)
notiffany (0.1.3)
nenv (~> 0.1)
shellany (~> 0.0)
notifications-ruby-client (5.4.0)
jwt (>= 1.5, < 3)
omniauth (2.1.1)
Expand Down Expand Up @@ -534,6 +554,10 @@ GEM
rexml (3.2.6)
rollbar (3.4.2)
rouge (4.2.0)
rspec (3.12.0)
rspec-core (~> 3.12.0)
rspec-expectations (~> 3.12.0)
rspec-mocks (~> 3.12.0)
rspec-core (3.12.2)
rspec-support (~> 3.12.0)
rspec-expectations (3.12.3)
Expand Down Expand Up @@ -600,6 +624,7 @@ GEM
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0)
shellany (0.0.1)
shoulda-matchers (5.3.0)
activesupport (>= 5.2.0)
sidekiq (6.5.12)
Expand Down Expand Up @@ -639,6 +664,8 @@ GEM
attr_required (>= 0.0.5)
faraday (~> 2.0)
faraday-follow_redirects
terminal-notifier (2.0.0)
terminal-notifier-guard (1.6.4)
terminal-table (3.0.2)
unicode-display_width (>= 1.1.1, < 3)
terser (1.1.20)
Expand Down Expand Up @@ -734,6 +761,7 @@ DEPENDENCIES
foreman
govuk-components
govuk_design_system_formbuilder (~> 4.1)
guard-rspec
httparty
httpclient
i18n-tasks
Expand Down Expand Up @@ -781,6 +809,8 @@ DEPENDENCIES
spring-commands-rspec
sprockets-rails
stimulus-rails
terminal-notifier
terminal-notifier-guard (~> 1.6.1)
terser
thor
turbo-rails
Expand Down
63 changes: 63 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# A sample Guardfile
# More info at https://github.com/guard/guard#readme

## Uncomment and set this to only include directories you want to watch
# directories %w(app lib config test spec features) \
# .select{|d| Dir.exist?(d) ? d : UI.warning("Directory #{d} does not exist")}

## Note: if you are using the `directories` clause above and you are not
## watching the project directory ('.'), then you will want to move
## the Guardfile to a watched dir and symlink it back, e.g.
#
# $ mkdir config
# $ mv Guardfile config/
# $ ln -s config/Guardfile .
#
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"

# NOTE: The cmd option is now required due to the increasing number of ways
# rspec may be run, below are examples of the most common uses.
# * bundler: 'bundle exec rspec'
# * bundler binstubs: 'bin/rspec'
# * spring: 'bin/rspec' (This will use spring if running and you have
# installed the spring binstubs per the docs)
# * zeus: 'zeus rspec' (requires the server to be started separately)
# * 'just' rspec: 'rspec'

guard :rspec, cmd: "SKIP_COVERAGE=1 SKIP_KNAPSACK=1 bundle exec rspec --tag ~flaky" 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])
dsl.watch_spec_files_for(rails.app_files)
dsl.watch_spec_files_for(rails.views)

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

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

# Capybara features specs
watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
end

0 comments on commit 4a2628c

Please sign in to comment.