2010-12-01 207 views
0

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

对于非集成测试,模式是它会在相同的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 

回答

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 
+0

年后,但仍然感谢你。 – 2012-04-15 16:41:58

-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 
+0

不是很有帮助。这里的评论容易让人误解,在这种情况下,他只需要返回匹配的文件名。 – szeryf 2012-04-14 14:37:44