Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails test hanging - how can I print the test name before execution?

I'm having a test hang in our rails app can't figure out which one (since it hangs and doesn't get to the failure report). I found this blog post http://bmorearty.wordpress.com/2008/06/18/find-tests-more-easily-in-your-testlog/ which adds a setup hook to print the test name but when I try to do the same thing it gives me an error saying wrong number of arguments for setup (1 for 0). Any help at all would be appreciated.

like image 866
John Duff Avatar asked Oct 01 '08 14:10

John Duff


3 Answers

If you run test using rake it will work:

rake test:units TESTOPTS="-v" 
like image 87
allenwei Avatar answered Oct 13 '22 02:10

allenwei


The printing of the test name is the responsibility of the TestRunner. If you are running your tests from the command line you can specify the -v option, to print out the test case names.

example:

ruby test_Foo.rb -v
Loaded suite test_Foo
Started
test_blah(TestFoo): .
test_blee(TestFoo): .

Finished in 0.007 seconds.

2 tests, 15 assertions, 0 failures, 0 errors
like image 24
Aaron Hinni Avatar answered Oct 13 '22 02:10

Aaron Hinni


This is what I use, in test_helper.rb

class Test::Unit::TestCase
  # ...

  def setup_with_naming 
    unless @@named[self.class.name]
      puts "\n#{self.class.name} "
      @@named[self.class.name] = true
    end
    setup_without_naming
  end
  alias_method_chain :setup, :naming unless defined? @@aliased
  @@aliased = true  
end

The @@aliased variable keeps it from being re-aliased when you run it on multiple files at once; @@named keeps the name from being displayed before every test (just before the first to run).

like image 4
Ben Scofield Avatar answered Oct 13 '22 02:10

Ben Scofield