How can I find out what FactoryGirl displays?

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

Is there a way with $ stderror puts to see what FactoryGirl created?

thanks

+4
source share
1 answer

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

I usually add the following to spec_helper.rb

 def logger Rails::logger end 

Now you can write anywhere in your specification like this:

 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

+3
source

Source: https://habr.com/ru/post/1398080/


All Articles