【问题标题】:Limit Integration tests run by autotest (Rails)限制自动测试运行的集成测试(Rails)
【发布时间】:2012-04-14 22:31:58
【问题描述】:

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

【问题讨论】:

    标签: ruby-on-rails continuous-integration autotest


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      抱歉,我没有时间完全解决您的问题,但我想您可以在阅读 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
      

      【讨论】:

      • 不是很有帮助。这里的注释有误导性,在这种情况下他只需要返回匹配的文件名。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-08-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多