Tips – Print test name and file name when testing (Final Solution)

RubyOnRails,Tips 13 五月 2010 | View Comments


As previous solution doesn’t works, after read source code of ActiveSupport::TestCase I find a final solution.

class ActiveSupport::TestCase
  setup :log_test
  private
  def log_test
    unless @already_logged_this_test  
      puts "\n\nStarting #{@method_name} in class:#{self.class.name}\n#{'-' * (20 + @method_name.length + self.class.name.length)}\n"  
    end  
    @already_logged_this_test = true

  end

setup is a callback of ActiveSupport::TestCase. So we doesn’t hack anything. It works fine.

And what’s more rake test already support verbose model

  rake test:units TESTOPTS="-v"

if you using run test directly like this, TESTOPTS="-v" doesn’t work

ruby -Itest test/units/some_test.rb



Tagged in , ,

  • http://www.napoliristorante.com cooking top round

    Hi buddy, your blog’s design is simple and clean and i like it. Your blog posts are superb. Please keep them coming. Greets!!!

blog comments powered by Disqus

Ads Plugin created by Jake Ruston's Wordpress Plugins - Powered by and football database.