我有一个用于大型项目(约3800个单独示例)的测试套件,我将其从RSpec 2.14更新为3.6。
我刚刚为运行了全部替换s/be_true/be true/,但是其中一些应该be_truthy代替,并且这些规格都失败了。
我可以git diff通过一些工作从其中提取更改的行,但是随后我需要将其输入RSpec的行中config.filter_run,这似乎不像我为locations过滤器那样做(当您rspec path/to/file:line在命令行上指定a时激活了该行) ; 它说“ All examples were filtered out; ignoring {:locations=>...}”。
我也可以example.run unless example.location.in? changed_specs在around过滤器中,但这skip是所有其他过滤器,并将它们标记为pending,而不是完全忽略它们。并且它与的其他过滤器不兼容run_all_when_everything_filtered。(可能是因为它example.location指的是测试的第一行,但是更改仅次于该行的几行。)
而且,我似乎也无法使用它在上添加标签example.metadata,然后将其过滤掉。
编辑:我也不想在命令行上指定它们,因为我的测试是在下rerun运行的,它始终运行相同的命令。
还有其他想法吗?
您可以使用以下命令运行更改后的规范:
rspec $(git ls-files --modified spec)
Run Code Online (Sandbox Code Playgroud)
如果您还想包含新的未版本化规范,请使用:
rspec $(git ls-files --modified --others spec)
Run Code Online (Sandbox Code Playgroud)
您可以使用 shell 别名使这更方便:
alias rch='rspec $(git ls-files --modified --others spec)'
Run Code Online (Sandbox Code Playgroud)
git status 可能是更好的选择?为什么这样的东西对你不起作用:
$ bundle exec rspec $(git status | grep spec | grep "modified:" | cut -b 15-)
Run Code Online (Sandbox Code Playgroud)
来源:https ://coderwall.com/p/usrhyq/running-modified-specs-with-git