Skip to content

Instantly share code, notes, and snippets.

@murbanski
Last active December 15, 2015 17:49
Show Gist options
  • Select an option

  • Save murbanski/5299475 to your computer and use it in GitHub Desktop.

Select an option

Save murbanski/5299475 to your computer and use it in GitHub Desktop.

Revisions

  1. murbanski revised this gist Apr 3, 2013. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions spec_helper.rb
    Original file line number Diff line number Diff line change
    @@ -13,6 +13,8 @@
    RSpec.configure do |config|
    config.after(:suite) do
    STDERR.puts Hash[$factories_speed.sort_by { |k, v| v[:duration] }.reverse]
    total_duration = $factories_speed.sum {|k, v| v[:duration] }
    STDERR.puts "Total FactoryGirl duration: #{total_duration}"
    end
    end

  2. murbanski created this gist Apr 3, 2013.
    18 changes: 18 additions & 0 deletions spec_helper.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    require 'rspec/rails'
    # ...

    $factories_speed = Hash.new {|h, k| h[k] = {calls: 0, duration: 0} }
    ActiveSupport::Notifications.subscribe("factory_girl.run_factory") do |*args|
    event = ActiveSupport::Notifications::Event.new(*args)
    key = "#{event.payload[:strategy]}_#{event.payload[:name]}"
    $factories_speed[key][:calls] += 1
    $factories_speed[key][:duration] += event.duration
    end


    RSpec.configure do |config|
    config.after(:suite) do
    STDERR.puts Hash[$factories_speed.sort_by { |k, v| v[:duration] }.reverse]
    end
    end