#279 √ resolved
Coda Hale

Autotest never calls the :red hook

Reported by Coda Hale | February 7th, 2008 @ 06:31 AM | in 1.1.4

My autotest growl notifications stopped worked recently (independently of the growlnotify Leopard problems), and in the process of debugging this I replaced my ~/.autotest file with the following tracer code:

module Autotest::CanaryInCoalMine

  Autotest.add_hook :run_command do  |at|
    puts "============ RUNNING"
  end

  Autotest.add_hook :green do  |at|
    puts "============ GREEN"
  end

  Autotest.add_hook :all_good do  |at|
    puts "============ ALL GOOD"
  end

  Autotest.add_hook :red do  |at|
    puts "============ RED"
  end

  Autotest.add_hook :quit do  |at|
    puts "============ BYE NOW"
  end
end

I found that at no point does RSpec's autotest code ever call the :red hook.

An abbreviated example of the behavior:

$ autotest
loading autotest/rspec
============ ALL GOOD
============ RUNNING
/opt/local/bin/ruby -S /opt/local/lib/ruby/gems/1.8/gems/rspec-1.1.3/bin/spec -O spec/spec.opts  [a whole bunch of files]
...............................................................................................................................................................................................................................................................................................................................................................................................................................

Finished in 2.516881 seconds

415 examples, 0 failures
============ GOOD
============ ALL GOOD
<I manually induce a failure.>
============ RUNNING
/opt/local/bin/ruby -S /opt/local/lib/ruby/gems/1.8/gems/rspec-1.1.3/bin/spec -O spec/spec.opts  spec/happy_class_spec.rb
........F........

1)
'HappyClass should be awesome' FAILED
expected: 2,
     got: 1 (using ==)
Diff:
@@ -1,2 +1,2 @@
-1
+2

./spec/happy_class_spec.rb:94:

Finished in 0.078181 seconds

17 examples, 1 failure
============ GOOD
============ ALL GOOD
============ ALL GOOD
^CInterrupt a second time to quit
^C============ BYE NOW

This appears to be a bug in Autotest::Rspec#consolidate_failures, which does not actually parse out the failed specs and their containing files.

Replacing consolidate_failures with the following code fixes this:

  def consolidate_failures(failed)
    filters = Hash.new { |h,k| h[k] = [] }
    failed.each do |spec, trace|
      if trace =~ /\n(.*):[\d]+:\Z/
        filters[$1] << spec
      end
    end
    return filters
  end

I'm using RSpec 1.1.3 and ZenTest 3.9.1.

Comments and changes to this ticket

  • David Chelimsky

    David Chelimsky February 8th, 2008 @ 03:19 AM

    • → Milestone changed from “” to “1.1.4”
    • → State changed from “new” to “resolved”
    • → Assigned user changed from “” to “David Chelimsky”

    Applied to r3286

  • David Chelimsky

    David Chelimsky February 15th, 2008 @ 07:18 AM

    • → State changed from “resolved” to “open”

    This was done but it I have to undo it because it caused problems. Somehow script/spec was showing up in the list of files to run after failures.

  • David Chelimsky

    David Chelimsky February 15th, 2008 @ 02:53 PM

    Coda - the problem that this patch introduced was that 'script/spec' ended up in the list of files to test when there were failures. So you'd end up with a command like this:

    ruby -S script/spec -O spec/spec.opts script/spec spec/models/foo_spec.rb
    

    This would result in autotest hanging and cpu spiking up to 100%.

    It would be great if you'd submit a new patch that doesn't do that :)

  • Coda Hale

    Coda Hale February 15th, 2008 @ 07:10 PM

    How's this?

      def consolidate_failures(failed)
        filters = Hash.new { |h,k| h[k] = [] }
        failed.each do |spec, trace|
          if trace =~ /\n(.*_spec.rb):[\d]+:\Z/
            filters[$1] << spec
          end
        end
        return filters
      end
    

    It makes the assumption that all specs end with _spec.rb -- that's correct, right?

  • David Chelimsky

    David Chelimsky February 15th, 2008 @ 08:48 PM

    That still doesn't always call the red hook. I modified the regexp to this:

    /\n(.*_spec.rb):[\d]+:\Z?/m
    

    And that caused red to get run, but now autotest just runs continuously. Getting close though. I'm working on this - hope to have a solution soon.

  • David Chelimsky

    David Chelimsky February 16th, 2008 @ 07:28 AM

    • → State changed from “open” to “resolved”

    The thing that was causing things to keep running was an incorrect exceptions list set by rspec_on_rails.

    Applied to r3312.

Please Login or create a free account to add a new comment.

You can update this ticket by sending an email to from your email client. (help)

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Behaviour Driven Development for Ruby.

Shared Ticket Bins

People watching this ticket