No commit activity in last 3 years
No release in over 3 years
This very simple gem generates reports on how FactoryGirl factories are being used in your test runs.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

>= 1.0.0
>= 0

Runtime

 Project Readme

FactoryInspector

This very simple gem reports on how FactoryGirl is being used during your test runs. This is useful in understanding where the time is going during your test runs; while FactoryGirl is useful, overuse can lead to serious slowdowns due to a cascade of database writes when building test objects. The analysis relies on the changes brought in with FactoryGirl 3.2

This gem is a developer utility and makes no effort to sanitize inputs or help you avoid making mistakes, but hopefully it's too simple to need much of that!

Installation

Add this line to your application's Gemfile:

gem 'factory_inspector'

And then execute:

$ bundle

Or install it yourself as:

$ gem install factory_inspector

Usage

FactoryInspector's API is just two methods; start_inspection and generate_report

Assuming you're on a RSpec based project, the changes to your spec/spec_helper.rb file to introduce FactoryInspector would be:

  require 'factory_inspector'

  # From a project relative filename like 'log/filename.txt'
  # generate the full path.
  # TODO There must be simpler way to do this?
  def get_project_path_for(filename)
    "#{File.dirname(__FILE__)}/../#{filename}"
  end

  factory_inspector = FactoryInspector.new
  RSpec.configure do |config|

    config.before :suite do
      factory_inspector.start_inspection
    end

    config.after :suite do
      report_name = 'log/factory_inspector_report.txt'
      report_path = get_project_path_for report_name 
      factory_inspector.generate_report report_path
      puts "Factory Inspector report in '#{report_name}'"
    end
  end

After the tests have run, the nominated log file will have output similar to this:

FACTORY INSPECTOR - 46 FACTORIES USED
  FACTORY NAME                TOTAL  OVERALL   TIME PER  LONGEST   STRATEGIES
                              CALLS  TIME (s)  CALL (s)  CALL (s)            
  school_with_terms             1    0.4783    0.47827  0.4783      [:create]
  school_with_terms_and_cla     5    2.3859    0.47718  0.5184      [:create]
  school_leaver                 1    0.2581    0.25808  0.2581      [:create]
  pre_enrolled_pupil            1    0.2570    0.25704  0.2570      [:create]
  pupil_school_enrolment_fo     1    0.2008    0.20075  0.2008      [:build]
  announcement                  5    0.8973    0.17946  0.2327      [:create]
  sub_class_with_pupils         5    0.7961    0.15921  0.2163      [:create, :build]
  etc

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request