factory_trace 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 47eb79312468fdf6bb3625c9046f6372d44cf56b84b052d1018d049b4f2d25fb
4
- data.tar.gz: 763c2b6a5b1af979b2a7ef3f64e5ed7beb2ce74a88e8f40826d5939b9fe338ae
3
+ metadata.gz: 7f8ffd7275b885d4354634c3a47c9697d96e40774e065526631c229263a52a80
4
+ data.tar.gz: 392e63586adb5d09b04f44ff80f3bd71606508e58ed21dc72525e10454f0b705
5
5
  SHA512:
6
- metadata.gz: 8376bf6ccb33ff20681d990ed2710cb7e821524d9748ac8ae9222a58215abdc735b35aa5f55f851e669bd8e44c2c3f81795a646783e8b81c63c90c168ab4c7d4
7
- data.tar.gz: b1262635dc1965e4107987f0bf686ae6bc94ac468d60906af41c93bf8f988cccccc7331c08a0723f793c5c463f2538764edbc832f1ab2649c5bc930ab390fb5f
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/check_unused'
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 = CheckUnused.new(tracker.storage).check!
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 CheckUnused
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
- suffix =
19
- case
20
- when result[:factory] && result[:trait]
21
- "trait '#{result[:trait].name}' of factory '#{result[:factory].name}'"
22
- when result[:factory]
23
- "factory '#{result[:factory].name}'"
24
- else
25
- "global trait '#{result[:trait].name}'"
26
- end
27
- "#{result[:code]} #{suffix}"
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
@@ -1,3 +1,3 @@
1
1
  module FactoryTrace
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
@@ -1,6 +1,5 @@
1
- if defined?(RSpec)
2
- RSpec.configure do |config|
3
- config.before(:suite) { FactoryTrace.start }
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.0
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