0

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
John Hinnegan
  • 5,864
  • 2
  • 48
  • 64

2 Answers2

1

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
szeryf
  • 3,197
  • 3
  • 27
  • 28
-1

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
BurmajaM
  • 724
  • 5
  • 10
  • Not very helpful. The comment here is misleading, he just needs to return the matched filename in this case. – szeryf Apr 14 '12 at 14:37