Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I get RSpec to only run changed specs?

Tags:

git

rspec

I have a test suite for a very large project (~ 3800 individual examples) that I'm updating from RSpec 2.14 to 3.6.

I have just run a replace-all for s/be_true/be true/, but some of them should be_truthy instead, and these specs are failing.

I can extract the changed lines from git diff - with a little work - but then I need to feed these into RSpec's config.filter_run, and it doesn't seem to like me doing that for the locations filter (the one activated when you specify a rspec path/to/file:line on the command line); it says "All examples were filtered out; ignoring {:locations=>...}".

I can also example.run unless example.location.in? changed_specs in an around filter, but this skips all the others and marks them as pending, rather than ignoring them completely; and it doesn't work in concert with the other filters to run_all_when_everything_filtered. (Probably because example.location refers to the top line of the test, but the changes are a few lines below that.)

And I can't seem to use it to add a tag to the example.metadata and then filter it out, either.

Edit: I also don't want to specify them on the command line, because my tests run under rerun, which keeps running the same command.

Any more ideas?

like image 910
PJSCopeland Avatar asked Aug 04 '17 00:08

PJSCopeland


2 Answers

You can run changed specs with:

rspec $(git ls-files --modified spec)

if you want include new unversioned specs as well use:

rspec $(git ls-files --modified --others spec)

You can make this handier with a shell alias:

alias rch='rspec $(git ls-files --modified --others spec)'
like image 122
weston Avatar answered Nov 15 '22 10:11

weston


git status might be a better bet? Why doesn't something like this work for you:

$ bundle exec rspec $(git status | grep spec | grep "modified:" | cut -b 15-)

source: https://coderwall.com/p/usrhyq/running-modified-specs-with-git

like image 4
PressingOnAlways Avatar answered Nov 15 '22 10:11

PressingOnAlways