factory_girl-dependency_tree 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8be1bcf551ed6ff36dbde7240cd5b8f4950d30b9
4
+ data.tar.gz: 13da3f208a9a34401f08c5cb10c084aa5ddeb2b5
5
+ SHA512:
6
+ metadata.gz: fad0eaee222540c01e78b68817e56a58ed0028cb264b327b071a979c77dce9b21dcddc000b24ad0bf45b2ac1fb7151250ba6392635e8eef4dde295cb1d2e1fb9
7
+ data.tar.gz: ea8799fd3c5138e1c78675fec39a3150d5f3ce25d39258370b77217ea49db41a0c7b7c22ba405a4d23071f82b1df30f714c42c4c9e1a6208b0be5eecef70d218
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.3
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in factory_girl-dependency_tree.gemspec
4
+ gemspec
@@ -0,0 +1,18 @@
1
+ # FactoryGirl::DependencyTree
2
+
3
+ a simple library for analyzing the dependencies between your factory_girl factories
4
+
5
+ ## Installation
6
+
7
+ ```rb
8
+ gem 'factory_girl-dependency_tree'
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ The `::analyze!` method is an example for how this can be used. Here is a script you should be able to run with Rails depending on how complex your test environment is. It will output the dependency tree and warn you if there are any factories that are being called more than once.
14
+
15
+ ```sh
16
+ rails runner "require 'factory_girl-depedency_tree'; FactoryGirl::DependencyTree.analyze!"
17
+ ```
18
+
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,26 @@
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/dependency_tree/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "factory_girl-dependency_tree"
8
+ spec.version = FactoryGirl::DependencyTree::VERSION
9
+ spec.authors = ["Josh Bodah"]
10
+ spec.email = ["jb3689@yahoo.com"]
11
+
12
+ spec.summary = %q{a simple library for analyzing the dependencies between your factory_girl factories}
13
+ spec.homepage = "https://github.com/backupify/factory_girl-dependency_tree"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = "exe"
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency 'rubytree'
21
+ spec.add_dependency 'factory_girl'
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.10"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "minitest"
26
+ end
@@ -0,0 +1,68 @@
1
+ require 'factory_girl/dependency_tree/version'
2
+ require 'tree'
3
+
4
+ module FactoryGirl
5
+ module DependencyTree
6
+ %i{create build build_stubbed attributes_for build_list create_list build_pair create_pair}.each do |sym|
7
+ define_method(sym) do |*args, &block|
8
+ FactoryGirl::DependencyTree.record("#{sym}##{args.first}") do
9
+ super *args, &block
10
+ end
11
+ end
12
+ end
13
+
14
+ class << self
15
+ # Example method for kicking off a sample dependency analysis
16
+ # You should load your environment before calling this (e.g.
17
+ # use `rails runner`)
18
+ def analyze!
19
+ # Install
20
+ FactoryGirl.singleton_class.prepend(FactoryGirl::DependencyTree)
21
+
22
+ # Run
23
+ FactoryGirl.find_definitions if FactoryGirl.factories.none?
24
+ FactoryGirl.factories.map(&:name).each do |f|
25
+ begin
26
+ FactoryGirl.create(f)
27
+ rescue => e
28
+ puts "Couldn't analyze factory #{f} due to #{e}"
29
+ end
30
+ end
31
+
32
+ # Report
33
+ puts "Printing the dependency tree of each FactoryGirl factory..."
34
+ FactoryGirl::DependencyTree.forest.each do |t|
35
+ t.print_tree(t.node_depth, nil, -> (n, pre) { puts "#{pre} #{n.content}" })
36
+ end
37
+
38
+ puts '***'
39
+
40
+ puts "Printing the FactoryGirl factories with more than one call to another single factory..."
41
+ FactoryGirl::DependencyTree.forest.each do |tree|
42
+ children = tree.each.to_a[1..-1]
43
+ child_counts = children.map(&:content).reduce(Hash.new(0)) {|c,n| c[n] += 1; c}
44
+ puts "===\n#{tree.content}\n#{child_counts}" if child_counts.values.any? {|v| v > 1}
45
+ end
46
+ end
47
+
48
+ def record(name)
49
+ if @node
50
+ node = Tree::TreeNode.new(SecureRandom.uuid, name)
51
+ @node << node
52
+ @node = node
53
+ else
54
+ @node = Tree::TreeNode.new(SecureRandom.uuid, name)
55
+ forest << @node
56
+ end
57
+ yield.tap { @node = @node.parent }
58
+ rescue => e
59
+ @node = nil
60
+ raise e
61
+ end
62
+
63
+ def forest
64
+ @forest ||= []
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,5 @@
1
+ module FactoryGirl
2
+ module DependencyTree
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: factory_girl-dependency_tree
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Josh Bodah
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-12-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rubytree
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: factory_girl
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
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: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email:
85
+ - jb3689@yahoo.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - Gemfile
93
+ - README.md
94
+ - Rakefile
95
+ - factory_girl-dependency_tree.gemspec
96
+ - lib/factory_girl/dependency_tree.rb
97
+ - lib/factory_girl/dependency_tree/version.rb
98
+ homepage: https://github.com/backupify/factory_girl-dependency_tree
99
+ licenses: []
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 2.4.8
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: a simple library for analyzing the dependencies between your factory_girl
121
+ factories
122
+ test_files: []