0

I'm working with Rails 5 and rspec (gem version 4). I was wondering if RSpec can be configured to only run tests that have been modified within a single file when only running that file, i.e.

bundle exec rspec spec/my_spec.rb

. If my file is like this

RSpec.describe MyClass do

  context "context 1" do
    it "tests condition 1" do
    end

    it "tests condition 2" do
    end

    ...
  end

  context "context 2" do
    ...
  end

  ...
end

and I only update tests in "context 1," is it possible to test the single file and have only modified tests from within that file run? With respect to this answer -- Can I get RSpec to only run changed specs?, it appears that only relates to actual files that have changed when running the complete suite of rspec tests.

satish
  • 703
  • 5
  • 23
  • 52

2 Answers2

1

I think you are looking for guard.

Checkout nicely written article https://collectiveidea.com/blog/archives/2017/02/09/guard-is-your-friend

Amit Patel
  • 15,609
  • 18
  • 68
  • 106
0

There is a Ruby Gem called retest designed to do exactly that. Just run retest, and it will watch for changes in the code or the specs themselves, and rerun just the respective spec file.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
DannyB
  • 12,810
  • 5
  • 55
  • 65
  • It'll run the entire file? I normally use `guard-rspec` for this. But OP was ideally looking for something to run just the changed specs within the file. – Sergio Tulentsev Jul 22 '22 at 13:59