Can I get RSpec to only run changed specs?

会有一股神秘感。 提交于 2020-07-18 18:00:30

问题


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?


回答1:


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)'



回答2:


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




回答3:


I couldn't find a straight forward way of doing it, but you can do it combining the ruby gem 'guard' and the 'watch' command like mentioned in the below link.

Automatically run RSPec when plain-old Ruby (not Rails) files change

It worked for me but you may need to find out further tweaks to enhance what you want.

Additional suggestion, https://github.com/guard/guard-rspec is having good support if you want to try out the above with 'guard-rspec' gem.



来源:https://stackoverflow.com/questions/45496443/can-i-get-rspec-to-only-run-changed-specs

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!