首页 文章

由autotest(Rails)运行的限制集成测试

提问于
浏览
0

我正在使用自动测试,并添加了钩子来运行我的集成测试 . 在工作时,每当我做出影响任何集成测试的更改时,所有集成测试都会重新运行 . 如果可能的话,这是我想要改变的行为 . (我正在使用rspec和webrat进行测试,没有黄瓜)

对于非集成测试,模式是如果您更改测试或其描述,它会在同一个spec文件(或描述块?)中重新运行测试 . 所以,比方说我们有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

2 回答

  • -1

    您的 .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
    
  • 1

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

相关问题