我可以让RSpec只运行更改的规格吗? [英] Can I get RSpec to only run changed specs?
问题描述
我有一个用于大型项目(约3800个单独示例)的测试套件,我将其从RSpec 2.14更新为3.6.
I have a test suite for a very large project (~ 3800 individual examples) that I'm updating from RSpec 2.14 to 3.6.
我刚刚为s/be_true/be true/
运行了全部替换,但是其中一些应该改为be_truthy
,并且这些规格失败了.
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.
我可以通过一些工作从git diff
中提取更改的行,但是随后我需要将这些行输入RSpec的config.filter_run
中,而且似乎不希望我为locations
过滤器做这件事(当您在命令行上指定rspec path/to/file:line
时激活的那个);它说"All examples were filtered out; ignoring {:locations=>...}
".
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=>...}
".
我也可以在around
过滤器中使用example.run unless example.location.in? changed_specs
,但是此skip
将所有其他内容都标记为pending
,而不是完全忽略它们.并且它不能与run_all_when_everything_filtered
的其他过滤器配合使用. (可能是因为example.location
指的是测试的第一行,但更改仅次于该行.)
I can also example.run unless example.location.in? changed_specs
in an around
filter, but this skip
s 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.)
我似乎也不能用它为example.metadata
添加标签,然后将其过滤掉.
And I can't seem to use it to add a tag to the example.metadata
and then filter it out, either.
我也不想在命令行上指定它们,因为我的测试在rerun
下运行,该命令一直运行相同的命令.
I also don't want to specify them on the command line, because my tests run under rerun
, which keeps running the same command.
还有其他想法吗?
推荐答案
您可以使用以下命令运行更改的规范:
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)
您可以使用shell别名来简化此操作:
You can make this handier with a shell alias:
alias rch='rspec $(git ls-files --modified --others spec)'
这篇关于我可以让RSpec只运行更改的规格吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!