factory_girl_profiling 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/.gitignore +20 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +52 -0
- data/Rakefile +1 -0
- data/factory_girl_profiling.gemspec +24 -0
- data/lib/factory_girl_profiling/initializer.rb +20 -0
- data/lib/factory_girl_profiling/profiler.rb +88 -0
- data/lib/factory_girl_profiling/version.rb +3 -0
- data/lib/factory_girl_profiling.rb +8 -0
- data/spec/integration/profiler_spec.rb +10 -0
- data/spec/lib/factory_girl_profiling/initializer_spec.rb +11 -0
- data/spec/lib/factory_girl_profiling/profiler_spec.rb +44 -0
- data/spec/spec_helper.rb +20 -0
- metadata +106 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NzFiOWZkYzBjZTY5MzJjMmYxNWM5MWYwMTdkNzkwYTQ0MTdiNzRjNA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MjljN2UyZjM0NDdlZGZlMGFmNTQyMGU3YTQ1NmIwMWNkODhmMDA1Zg==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ODA0Zjc4Njg5YTE0NjhmMDU4ZTFmZmYzZDFjNjljNGZlMGViOTdiMDYyYmJj
|
10
|
+
OTk5Y2M2NDI3NzQyYmE4OGRiZWRkMzVmNjk5YWIyZjU5Y2YwN2VhYTkyOTNl
|
11
|
+
YjBjMDI0MTMxOTgxNDIwYmY0YTg0NmY5MTI3Mjg2MWZiOTk0MjE=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZDkyYTNlMDFmYjNhYjUwMWZmN2Q5NDRmMWJlOTI4NWFhMjZhNGY0ODY4NWJj
|
14
|
+
M2UzMjEzZjQ3ZDRlOTUwN2Y1OTJjYjU5MjA5MDBmYzMzMzY5OTRiYTdiZDcw
|
15
|
+
M2NiMTk4YTZmYjI3YmUyZjZkNDI0NzdiNDUyNTExMDQ0YmNmODg=
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Andrey Rozhkovsky
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# FactoryGirlProfiling
|
2
|
+
|
3
|
+
Prints number of times when factory was build or create and time (avg, min, max) that it took after test suite
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'factory_girl_profiling'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install factory_girl_profiling
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Add env var when running test to collect and
|
22
|
+
print statistic after test suite
|
23
|
+
|
24
|
+
PROFILE_FACTORY_GIRL=1
|
25
|
+
|
26
|
+
|
27
|
+
What's happennig is:
|
28
|
+
|
29
|
+
|
30
|
+
RSpec.configure do |config|
|
31
|
+
config.before(:suite) do
|
32
|
+
ActiveSupport::Notifications.subscribe("factory_girl.run_factory") do |name, start, finish, id, payload|
|
33
|
+
FactoryGirlProfiling::Profiler.add(name, start, finish, id, payload)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
config.after(:suite) do
|
38
|
+
FactoryGirlProfiling::Profiler.print_results
|
39
|
+
FactoryGirlProfiling::Profiler.reset
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
For more info about FactoryGirl read
|
44
|
+
https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md#activesupport-instrumentation
|
45
|
+
|
46
|
+
## Contributing
|
47
|
+
|
48
|
+
1. Fork it
|
49
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
50
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
51
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
52
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'factory_girl_profiling/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "factory_girl_profiling"
|
8
|
+
spec.version = FactoryGirlProfiling::VERSION
|
9
|
+
spec.authors = ["Andrey Rozhkovsky"]
|
10
|
+
spec.email = ["andrey.rozhkovsky@gmail.com"]
|
11
|
+
spec.description = %q{Prints number of times when factory was build or create and time (avg, min, max) that it took after test suite}
|
12
|
+
spec.summary = %q{Prints some statistic for FactoryGirl usage after test suite}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module FactoryGirlProfiling
|
2
|
+
class Initializer
|
3
|
+
def self.initialize_rspec
|
4
|
+
RSpec.configure do |config|
|
5
|
+
if ENV['PROFILE_FACTORY_GIRL']
|
6
|
+
config.before(:suite) do
|
7
|
+
ActiveSupport::Notifications.subscribe("factory_girl.run_factory") do |name, start, finish, id, payload|
|
8
|
+
FactoryGirlProfiling::Profiler.add(name, start, finish, id, payload)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
config.after(:suite) do
|
13
|
+
FactoryGirlProfiling::Profiler.print_results
|
14
|
+
FactoryGirlProfiling::Profiler.reset
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module FactoryGirlProfiling
|
2
|
+
class Profiler
|
3
|
+
private :initialize
|
4
|
+
def self.instance
|
5
|
+
@instance ||= new
|
6
|
+
end
|
7
|
+
|
8
|
+
class << self
|
9
|
+
[:add, :reset, :print_results].each do |method|
|
10
|
+
define_method method do |*args|
|
11
|
+
instance.send(method, *args)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
reset
|
18
|
+
end
|
19
|
+
|
20
|
+
def reset
|
21
|
+
@factory_girl_results = {}
|
22
|
+
@factory_girl_timing_results = {}
|
23
|
+
end
|
24
|
+
|
25
|
+
def add(name, start, finish, id, payload)
|
26
|
+
add_counting(payload[:name], payload[:strategy])
|
27
|
+
add_timing(payload[:name], payload[:strategy], finish - start)
|
28
|
+
end
|
29
|
+
|
30
|
+
def add_timing(name, strategy, timing)
|
31
|
+
@factory_girl_timing_results[name] ||= {}
|
32
|
+
@factory_girl_timing_results[name][strategy] ||= []
|
33
|
+
@factory_girl_timing_results[name][strategy] << timing
|
34
|
+
|
35
|
+
|
36
|
+
#if timing >= 0.5
|
37
|
+
#output_string "Slow factory: #{name} using strategy #{strategy}"
|
38
|
+
#end
|
39
|
+
end
|
40
|
+
|
41
|
+
def add_counting(name, strategy)
|
42
|
+
@factory_girl_results[name] ||= {}
|
43
|
+
@factory_girl_results[name][strategy] ||= 0
|
44
|
+
@factory_girl_results[name][strategy] += 1
|
45
|
+
end
|
46
|
+
|
47
|
+
def print_results
|
48
|
+
print_counting_results
|
49
|
+
print_timing_results
|
50
|
+
end
|
51
|
+
|
52
|
+
def print_counting_results
|
53
|
+
output_string 'FactoryGirl counting:'
|
54
|
+
sort_data_hash(@factory_girl_results).each do |factory, values|
|
55
|
+
counts_for_strategies = values.inject([]){|s, (strategy, count)| s << "#{strategy} = #{count}"}
|
56
|
+
output_string "#{"#{factory}:".ljust(30)} #{"%15s \t" * counts_for_strategies.size}" % counts_for_strategies
|
57
|
+
end
|
58
|
+
output_string "\n"
|
59
|
+
end
|
60
|
+
|
61
|
+
def print_timing_results
|
62
|
+
output_string 'FactoryGirl timing:'
|
63
|
+
sort_value_proc = ->(val) { val.values.map{|e| e.reduce(0, &:+)}.reduce(0, &:+) / val.values.map(&:size).reduce(0, &:+) }
|
64
|
+
sort_data_hash(@factory_girl_timing_results, sort_value_proc).each do |factory, data|
|
65
|
+
output_string factory
|
66
|
+
data.each do |strategy, times|
|
67
|
+
output_string "#{"#{strategy}:".ljust(10)} avg=#{(times.reduce(0, &:+) / times.size).round(2)} \t(min=#{times.min.round(2)},\tmax=#{times.max.round(2)})"
|
68
|
+
end
|
69
|
+
output_string ""
|
70
|
+
end
|
71
|
+
output_string "\n"
|
72
|
+
end
|
73
|
+
|
74
|
+
def sort_data_hash(hash, sort_value_proc = nil)
|
75
|
+
sort_value_proc ||= Proc.new {|val| val.values.reduce(0, &:+) }
|
76
|
+
hash.to_a.sort {|(_, v1), (_, v2)| sort_value_proc.call(v2) <=> sort_value_proc.call(v1)}
|
77
|
+
end
|
78
|
+
|
79
|
+
def output_string(str)
|
80
|
+
output_buffer.puts str
|
81
|
+
end
|
82
|
+
|
83
|
+
attr_writer :output_buffer
|
84
|
+
def output_buffer
|
85
|
+
@output_buffer ||= $stdout
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe 'Integration: Profiler' do
|
4
|
+
it "works" do
|
5
|
+
profiler = FactoryGirlProfiling::Profiler.instance
|
6
|
+
profiler.add_timing('some factory', 'some strategy', 123)
|
7
|
+
profiler.add_counting('some factory', 'some strategy')
|
8
|
+
profiler.print_results
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe FactoryGirlProfiling::Initializer do
|
4
|
+
context '.initialize_rspec' do
|
5
|
+
it "calls RSpec.configure" do
|
6
|
+
FactoryGirlProfiling::Initializer::RSpec = rspec_double = double('rspec')
|
7
|
+
rspec_double.should_receive(:configure)
|
8
|
+
FactoryGirlProfiling::Initializer.initialize_rspec
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe FactoryGirlProfiling::Profiler do
|
4
|
+
subject { FactoryGirlProfiling::Profiler.instance }
|
5
|
+
let(:output) { StringIO.new }
|
6
|
+
before do
|
7
|
+
subject.reset
|
8
|
+
subject.output_buffer = output
|
9
|
+
end
|
10
|
+
context 'timing' do
|
11
|
+
it "saves and prints given data" do
|
12
|
+
subject.add_timing('some name', 'some strategy', 42)
|
13
|
+
subject.print_timing_results
|
14
|
+
expect(output.string).to include('some name')
|
15
|
+
expect(output.string).to include('some strategy')
|
16
|
+
expect(output.string).to include('42')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'counting' do
|
21
|
+
it "saves and prints given data" do
|
22
|
+
subject.add_counting('some name', 'some strategy')
|
23
|
+
subject.add_counting('some name', 'some strategy')
|
24
|
+
subject.print_counting_results
|
25
|
+
expect(output.string).to include('some name')
|
26
|
+
expect(output.string).to include('some strategy')
|
27
|
+
expect(output.string).to include('2')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context '#reset' do
|
32
|
+
it "resets saved data" do
|
33
|
+
subject.print_results
|
34
|
+
blank_result = output.string
|
35
|
+
output.reopen
|
36
|
+
subject.add_counting('some name', 'some strategy')
|
37
|
+
subject.add_timing('some name', 'some strategy', 42)
|
38
|
+
subject.reset
|
39
|
+
subject.print_results
|
40
|
+
expect(output.string).to eq(blank_result)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
config.filter_run :focus
|
11
|
+
|
12
|
+
# Run specs in random order to surface order dependencies. If you find an
|
13
|
+
# order dependency and want to debug it, you can fix the order by providing
|
14
|
+
# the seed, which is printed after each run.
|
15
|
+
# --seed 1234
|
16
|
+
config.order = 'random'
|
17
|
+
end
|
18
|
+
|
19
|
+
require "factory_girl_profiling/profiler"
|
20
|
+
require "factory_girl_profiling/initializer"
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: factory_girl_profiling
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrey Rozhkovsky
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Prints number of times when factory was build or create and time (avg,
|
56
|
+
min, max) that it took after test suite
|
57
|
+
email:
|
58
|
+
- andrey.rozhkovsky@gmail.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- .gitignore
|
64
|
+
- .rspec
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- factory_girl_profiling.gemspec
|
70
|
+
- lib/factory_girl_profiling.rb
|
71
|
+
- lib/factory_girl_profiling/initializer.rb
|
72
|
+
- lib/factory_girl_profiling/profiler.rb
|
73
|
+
- lib/factory_girl_profiling/version.rb
|
74
|
+
- spec/integration/profiler_spec.rb
|
75
|
+
- spec/lib/factory_girl_profiling/initializer_spec.rb
|
76
|
+
- spec/lib/factory_girl_profiling/profiler_spec.rb
|
77
|
+
- spec/spec_helper.rb
|
78
|
+
homepage: ''
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
metadata: {}
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ! '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ! '>='
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 2.1.11
|
99
|
+
signing_key:
|
100
|
+
specification_version: 4
|
101
|
+
summary: Prints some statistic for FactoryGirl usage after test suite
|
102
|
+
test_files:
|
103
|
+
- spec/integration/profiler_spec.rb
|
104
|
+
- spec/lib/factory_girl_profiling/initializer_spec.rb
|
105
|
+
- spec/lib/factory_girl_profiling/profiler_spec.rb
|
106
|
+
- spec/spec_helper.rb
|