factory_trace 0.1.0 → 0.1.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 +4 -4
- data/lib/factory_trace.rb +3 -3
- data/lib/factory_trace/{check_unused.rb → find_unused.rb} +9 -3
- data/lib/factory_trace/printer.rb +10 -10
- data/lib/factory_trace/version.rb +1 -1
- data/lib/integrations/rspec.rb +4 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f8ffd7275b885d4354634c3a47c9697d96e40774e065526631c229263a52a80
|
4
|
+
data.tar.gz: 392e63586adb5d09b04f44ff80f3bd71606508e58ed21dc72525e10454f0b705
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3017d866a2b4d76f812e9ebf14a2c476a2d716fea6c5696b03ce83947e008431f340186caff533be69fe73d7da95b7f2f2b7c08d9cf257af4921ebbdf5d33d2f
|
7
|
+
data.tar.gz: 601ae2b6b8d370a3be34abe13404b50a3516789519548de30b15a60c66c712c3b4e2ad6bedd128dd75b53b7e08954d783142e85eca1e89e1f7cc4b70110f7e54
|
data/lib/factory_trace.rb
CHANGED
@@ -4,10 +4,10 @@ require 'factory_bot'
|
|
4
4
|
require 'factory_trace/configuration'
|
5
5
|
require 'factory_trace/version'
|
6
6
|
require 'factory_trace/tracker'
|
7
|
-
require 'factory_trace/
|
7
|
+
require 'factory_trace/find_unused'
|
8
8
|
require 'factory_trace/printer'
|
9
9
|
# Integrations
|
10
|
-
require 'integrations/rspec'
|
10
|
+
require 'integrations/rspec' if defined?(RSpec::Core)
|
11
11
|
|
12
12
|
module FactoryTrace
|
13
13
|
class << self
|
@@ -20,7 +20,7 @@ module FactoryTrace
|
|
20
20
|
def stop
|
21
21
|
return unless configuration.enabled
|
22
22
|
|
23
|
-
result =
|
23
|
+
result = FindUnused.new(tracker.storage).check!
|
24
24
|
|
25
25
|
printer.print(result)
|
26
26
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module FactoryTrace
|
2
|
-
class
|
2
|
+
class FindUnused
|
3
3
|
|
4
4
|
# @param [Hash<Symbol, Set<Symbol>>]
|
5
5
|
def initialize(data)
|
@@ -27,7 +27,8 @@ module FactoryTrace
|
|
27
27
|
output << {code: :unused, trait: trait} unless data['_traits'].include?(trait.name.to_s)
|
28
28
|
end
|
29
29
|
|
30
|
-
output
|
30
|
+
output.unshift(code: :unused, value: output.size)
|
31
|
+
output.unshift(code: :used, value: data['_total_used'])
|
31
32
|
end
|
32
33
|
|
33
34
|
private
|
@@ -39,7 +40,7 @@ module FactoryTrace
|
|
39
40
|
# @return [Hash<String, Set<String>>]
|
40
41
|
def prepare(data)
|
41
42
|
# +_traits+ is for global traits
|
42
|
-
output = {'_traits' => Set.new}
|
43
|
+
output = {'_traits' => Set.new, '_total_used' => count_total(data)}
|
43
44
|
|
44
45
|
data.each do |factory_name, trait_names|
|
45
46
|
factory_name = factory_name.to_s
|
@@ -70,6 +71,11 @@ module FactoryTrace
|
|
70
71
|
output
|
71
72
|
end
|
72
73
|
|
74
|
+
# @param [Hash<Symbol, Set<Symbol>>]
|
75
|
+
def count_total(data)
|
76
|
+
data.reduce(0) { |result, (_factory, traits)| result + 1 + traits.size }
|
77
|
+
end
|
78
|
+
|
73
79
|
attr_reader :initial_data
|
74
80
|
end
|
75
81
|
end
|
@@ -15,16 +15,16 @@ module FactoryTrace
|
|
15
15
|
|
16
16
|
# @param [Hash<Symbol, Object>] result
|
17
17
|
def convert(result)
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
18
|
+
case
|
19
|
+
when result[:value]
|
20
|
+
"total number of unique #{result[:code]} factories & traits: #{result[:value]}"
|
21
|
+
when result[:factory] && result[:trait]
|
22
|
+
"#{result[:code]} trait '#{result[:trait].name}' of factory '#{result[:factory].name}'"
|
23
|
+
when result[:factory]
|
24
|
+
"#{result[:code]} factory '#{result[:factory].name}'"
|
25
|
+
else
|
26
|
+
"#{result[:code]} global trait '#{result[:trait].name}'"
|
27
|
+
end
|
28
28
|
end
|
29
29
|
|
30
30
|
attr_reader :io
|
data/lib/integrations/rspec.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
config.after(:suite) { FactoryTrace.stop }
|
5
|
-
end
|
1
|
+
RSpec.configure do |config|
|
2
|
+
config.before(:suite) { FactoryTrace.start }
|
3
|
+
config.after(:suite) { FactoryTrace.stop }
|
6
4
|
end
|
5
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: factory_trace
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- djezzzl
|
@@ -74,8 +74,8 @@ extensions: []
|
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
76
|
- lib/factory_trace.rb
|
77
|
-
- lib/factory_trace/check_unused.rb
|
78
77
|
- lib/factory_trace/configuration.rb
|
78
|
+
- lib/factory_trace/find_unused.rb
|
79
79
|
- lib/factory_trace/printer.rb
|
80
80
|
- lib/factory_trace/tracker.rb
|
81
81
|
- lib/factory_trace/version.rb
|