0
votes

After learning about "guard" (I'm using Gem version 2.14.2), and reading this, https://www.chrisblunt.com/ruby-on-rails-running-tests-with-guard-and-docker/, I'm curious if I'm using guard correctly with my rspec tests. After I launch the guard console using

bundle exec guard

I'm searching for a way so that my entire suite of rspec tests will not be run when I only edit a single file. Is it possible to configure guard such that guard will only run tests for a particular spec? For example, if I edit the file

lib/folder1/myclass.rb

and spec file

spec/lib/folder1/myclass_spec.rb

Changes to lib/folder1/myclass.rb will not cause the entire suite of tests to run but rather only the spec/lib/folder1/myclass_spec.rb or at least only specs dependent on the altered class?

1

1 Answers

0
votes

Given I have the proper gems in my Gemfile,

gem 'guard', '~> 2.16.2'
gem 'guard-rspec', '~> 4.7.3'

And I have a Guardfile in place,

Then lets say I want to run only spec/policies/user_policy_spec.rb file whenever app/policies/user_policy.rb file changes, then I add the following guard to my Guardfile.

guard :rspec, cmd: "bundle exec rspec" do
  watch(%r{^app/policies/(.+)\.rb$})     { |m| "spec/policies/#{m[1]}_spec.rb" }
end