Read my latest article: 8 things I look for in a Ruby on Rails app (posted Thu, 06 Jul 2017 16:59:00 GMT)

Rails, Logger, and those pesky Tests

Posted by Wed, 25 Jan 2006 21:06:00 GMT

7 comments Latest by Jacolyte Fri, 05 Feb 2010 22:38:55 GMT

First of all, I would like to thank all of you who took a moment to gather around the campfire with me and share your stuff. That was much appreciated.

So, I started playing with the idea of logging in unit and functional tests and I quickly realized that calling logger.info wasn’t an option. What’s the deal-e-o? Before I gather up my posse and conspire a train hijacking, I decided that I would see how quickly I could solve my problem before I called you all out to the Rio Rails Grande for an old-fashioned shoot out. Ya know, the kind that results in a Bon Jovi song and a little blood.

You’re all in luck because:
  • A) my holster was eaten by my dog and
  • B) I found a quick solution to clean up this logger situation.

Okay… are you ready?

I know… this is totally groundbreaking!!!

Open up test/test_helper.rb and add the method… logger.

# other stuff at the top of the file... just 
# look down below at def logger
class Test::Unit::TestCase
  self.use_transactional_fixtures = true
  self.use_instantiated_fixtures  = false

  # here... look here! right below this
  def logger
    RAILS_DEFAULT_LOGGER
  end
end

Save that and pick up your pistol…

The next step is to call the logger method in your unit and functional tests.

def test_the_obvious
  logger.info( 'asserting that 1 is 1' )
  assert 1, 1
end

I posted this on Rails Weenie as well.

Don't Mock Me said the Dummy Object

Posted by Wed, 18 Jan 2006 14:11:00 GMT

2 comments Latest by J. B. Rainsberger Fri, 02 Jun 2006 20:27:41 GMT

Martin Fowler posted a short entry on his bliki titled, TestDouble where he mentioned Gerard Meszaros’ book which is a collection of patterns for Xunit frameworks. Martin then describes how Gerard has encountered a lot of confusion over similar names for testing objects (stubs, mocks, fakes, dummies,...) in different frameworks and has provided a nice description of each to help you differentiate between them.

Read more…

Older posts: 1 2