我可以让RSpec只运行更改的规格吗?

时间:2017-08-04 00:18:44

标签: git rspec

我有一个非常大的项目测试套件(大约3800个个体示例),我正在从RSpec 2.14更新到3.6。

我刚刚为s/be_true/be true/运行了替换全部,但其中一些应该be_truthy,而这些规格都失败了。

我可以从git diff中提取更改的行 - 只需要做一点工作 - 但是我需要将这些行提供给RSpec的config.filter_run,而且它似乎不喜欢我为locations做这些{1}}过滤器(在命令行中指定rspec path/to/file:line时激活的过滤器);它说“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下运行,它继续运行相同的命令。

还有什么想法?

3 个答案:

答案 0 :(得分:3)

git status可能是更好的选择?为什么这样的事情不适合你:

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

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

答案 1 :(得分:2)

您可以使用以下命令运行更改的规范:

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

如果您想要包含新的无版本规格,请使用:

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

你可以使用shell别名来实现这一点:

alias rch='rspec $(git ls-files --modified --others spec)'

答案 2 :(得分:0)

我无法找到一种直接的方法,但你可以将ruby gem'guard'和'watch'命令结合起来,如下面的链接所示。

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

它对我有用,但您可能需要进一步调整以增强您的需求。

如果你想用'guard-rspec'宝石试试上面的内容,https://github.com/guard/guard-rspec得到了很好的支持。

相关问题