Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6913815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:15:56+00:00 2026-05-27T09:15:56+00:00

Rails 3.0.10, Ruby 1.9.2, ActiveSupport::TestCase I would like to print to STDOUT the log

  • 0

Rails 3.0.10, Ruby 1.9.2, ActiveSupport::TestCase

I would like to print to STDOUT the log portion of tests that fail (only). If there is a plugin for that that I didn’t find, please be so kind to tell me. Otherwise, I would like to know:

  • How do I get the result (pass, fail, error) in teardown? In a similar question it is suggested to overwrite all assert methods to rescue exceptions, but I don’t like that approach too much.

My approach would be to have a setup that changes logging to a string and have the string pumped to STDOUT on a fail.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:15:57+00:00Added an answer on May 27, 2026 at 9:15 am

    These methods all work fine in a teardown method:

    self.passed?
    self.class.name
    self.method_name
    

    So in setup, you can save your old logger and create a new one that logs to a string buffer:

    @old_logger = Rails.logger
    @old_ar_logger = ActiveRecord::Base.logger
    @current_buffer = StringIO.new
    Rails.logger = Logger.new(@current_buffer)
    ActiveRecord::Base.logger = Rails.logger
    

    And in teardown, reset loggers, test for passed? and dump buffered log in case it did not:

    Rails.logger = @old_logger
    ActiveRecord::Base.logger = @old_ar_logger
    unless self.passed?
      @current_buffer.close_write
      STDOUT << @current_buffer.string
      @current_buffer.close
    end
    

    It works fine for me. Just beware that if you have an endless loop or something similar, you will not notice that easy.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a non-Rails ruby application (gasp!) and would like to be able to
I assume that ActionController::TestCase is for only testing ActionControllers , but what does ActiveSupport::TestCase
I am using Ruby on Rails 3.0.9 and I would like to know what
Hello Ruby/Rails/Merb developers! Im currently working on a web project that will have a
When running rails generate I get the following error: /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:239:in require': no such file
I have a Ruby on Rails Website that makes HTTP calls to an external
I am trying to run ruby on rails code that I got from github
When I try to do: $ rails generate c2dm_migrations I Get: /usr/lib/ruby/gems/1.8/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:239:in `require': no
We're doing an upgrade to Ruby on Rails 3 (like half the world right
Has anyone used Ruby/Rails with a Sales Logix database?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.