thomasvermaak
thomasvermaak

Reputation: 302

How can I see what FactoryGirl is outputting?

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

Upvotes: 4

Views: 1121

Answers (1)

Wolfgang
Wolfgang

Reputation: 4925

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

Upvotes: 3

Related Questions