4

I am using FactoryGirl in my rspec2 test with rails 3.2.1 and I would like to see the FactoryGirl output especially when the test fails.

Is there a way with $stderror puts to get to view what FactoryGirl has created?

Thanks

1 Answer 1

3

You could use the Rails logger to write directly to your log/test.log file.

I usually add the following to spec_helper.rb

def logger
  Rails::logger
end

now you can log anywhere in your spec like so:

describe Customer do

  it "logs factory girl generated objects" do
    customer = Factory( :customer )
    logger.warn( customer.pretty_inspect )
  end

end

This will print the generated customer object with all properties

2
  • Thanks @Wolfgang ... is there a specific place in spec_helper where I need to add 'def logger'? Feb 23, 2012 at 17:30
  • Simply add the def logger at the end of spec_helper
    – Wolfgang
    Feb 23, 2012 at 18:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.