限制自动测试运行的集成测试 (Rails)
我正在使用自动测试,并添加了挂钩来运行我的集成测试。在工作时,每当我做出影响任何集成测试的更改时,所有集成测试都会重新运行。如果可能的话,这是我想改变的行为。 (我使用 rspec 和 webrat 进行测试,没有黄瓜)
对于非集成测试,模式是如果您更改测试或其描述内容,它会在同一规范文件(或描述块?)中重新运行测试。因此,假设我们有 page_controller.rb 和 page_controller_spec.rb。 autotest 知道,如果您更改这些文件之一,它只会运行 page_controller_spec 中的测试,然后,如果它通过,它会运行所有测试。我想要类似的集成测试 - 只需首先运行文件中失败的测试,然后运行所有测试(如果它们通过)。
我的 .autotest 文件看起来像这样
require "autotest/growl"
require "autotest/fsevent"
Autotest.add_hook :initialize do |autotest|
autotest.add_mapping(/^spec\/integration\/.*_spec\.rb$/) do
autotest.files_matching(/^spec\/integration\/.*_spec\.rb$/)
end
end
I'm using autotest, and have added hooks to run my integration tests. While working, any time I make a change that impacts any of the integration tests, all the integration tests rerun. This is the behavior I'd like to change, if possible. (I'm using rspec with webrat for my tests, no cucumber)
With non-integration tests, the pattern is that it reruns the tests in the same spec file (or describe block?) if you change the test or what its describing. So, say we have page_controller.rb and page_controller_spec.rb. autotest knows that if you change one of those files, it runs just the tests in the page_controller_spec, then, if it passes, it runs all the tests. I'd like something similar for my integration tests -- just run the tests in the file with the failing test first, then run all tests if they pass.
my .autotest file looks like this
require "autotest/growl"
require "autotest/fsevent"
Autotest.add_hook :initialize do |autotest|
autotest.add_mapping(/^spec\/integration\/.*_spec\.rb$/) do
autotest.files_matching(/^spec\/integration\/.*_spec\.rb$/)
end
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的
.autotest
是问题的根源:)它基本上表示,对于/spec/integration
目录中的 any 文件,all 其中应该运行。您应该仅返回匹配的文件名,如下所示:Your
.autotest
is the source of the problem :) It basically says that for any file in/spec/integration
directory, all of them should be run. You should return only the matched filename, like this:抱歉,我没有时间完全解决您的问题,但我想当您阅读 Autotest#add_mapping 方法的注释时,您可以自己完成。你必须稍微玩一下正则表达式。注意“+proc+ 传递了匹配的文件名和 Regexp.last_match”。这是完整的评论:
Sorry, I don't have time to fix your problem totally but I guess you can do it on your own when you read the comment of Autotest#add_mapping method. You have to play a little bit with regex. Pay attention at "+proc+ is passed a matched filename and Regexp.last_match". Here's full comment: