限制自动测试运行的集成测试 (Rails)

发布于 2024-10-05 15:44:59 字数 640 浏览 2 评论 0原文

我正在使用自动测试,并添加了挂钩来运行我的集成测试。在工作时,每当我做出影响任何集成测试的更改时,所有集成测试都会重新运行。如果可能的话,这是我想改变的行为。 (我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

倦话 2024-10-12 15:44:59

您的 .autotest 是问题的根源:)它基本上表示,对于 /spec/integration 目录中的 any 文件,all 其中应该运行。您应该仅返回匹配的文件名,如下所示:

require "autotest/growl"
require "autotest/fsevent"

Autotest.add_hook :initialize do |autotest|
  autotest.add_mapping(/^spec\/integration\/.*_spec\.rb$/) do |filename|
    filename
  end  
end

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:

require "autotest/growl"
require "autotest/fsevent"

Autotest.add_hook :initialize do |autotest|
  autotest.add_mapping(/^spec\/integration\/.*_spec\.rb$/) do |filename|
    filename
  end  
end
潇烟暮雨 2024-10-12 15:44:59

抱歉,我没有时间完全解决您的问题,但我想当您阅读 Autotest#add_mapping 方法的注释时,您可以自己完成。你必须稍微玩一下正则表达式。注意“+proc+ 传递了匹配的文件名和 Regexp.last_match”。这是完整的评论:

  # Adds a file mapping, optionally prepending the mapping to the
  # front of the list if +prepend+ is true. +regexp+ should match a
  # file path in the codebase. +proc+ is passed a matched filename and
  # Regexp.last_match. +proc+ should return an array of tests to run.
  #
  # For example, if test_helper.rb is modified, rerun all tests:
  #
  #   at.add_mapping(/test_helper.rb/) do |f, _|
  #     at.files_matching(/^test.*rb$/)
  #   end

  def add_mapping regexp, prepend = false, &proc

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:

  # Adds a file mapping, optionally prepending the mapping to the
  # front of the list if +prepend+ is true. +regexp+ should match a
  # file path in the codebase. +proc+ is passed a matched filename and
  # Regexp.last_match. +proc+ should return an array of tests to run.
  #
  # For example, if test_helper.rb is modified, rerun all tests:
  #
  #   at.add_mapping(/test_helper.rb/) do |f, _|
  #     at.files_matching(/^test.*rb$/)
  #   end

  def add_mapping regexp, prepend = false, &proc
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文