[rspec-users] Global setup method goes where?

Ben Mabey ben at benmabey.com
Fri Jul 4 02:19:34 EDT 2008

Gregg Pollack wrote:
> You know how sometimes you look in /log/test.log for debug information
> like which test caused a certain render or query?
> I found this post which shows how to get test information printed out in
> your test.log with test:unit and shoulda, but I'm not sure there's a way
> to do it with RSpec.
> http://bmorearty.wordpress.com/2008/06/18/find-tests-more-easily-in-your-testlog/
> test:unit allows you to put "setup :blah" in your test_helper.rb, and
> then the blah method gets called before each test.  This can be used to
> print out a log statement saying 'we're runnig test ___".  How would we
> do the same in rspec with the spec_helper.rb so that we can print this
> data out in our logs too?
> Any takers?  I'm sure I could probably figure this out if I dove deep
> into the code base, but I get the feeling someone must have done this
> before.
> I'm going to cover this on the next Rails Envy podcast, so you'll get
> some credit for a good answer, and a link if you post the answer to your
> blog (assuming you want the publicity).  ;-)
> Gregg Pollack
> RailsEnvy.com

In your spec_helper.rb just put:

Spec::Runner.configure do |config|
  config.before(:each) do
      full_example_description = "#{self.class.description} #{@method_name}"
#{full_example_description}\n\n#{'-' * (9 + 


Note that the constant RAILS_DEFAULT_LOGGER is being used since 
Rails::logger is only available in 2.1.

I'll write up a quick post on on this and show how to do something 
similar with the story runner.


More information about the rspec-users mailing list