Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

factory_inspector

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

factory_inspector

  • 0.0.5
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

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

FAQs

Package last updated on 30 Apr 2012

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc