detektiiv 0.1.1 → 0.1.2

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: 901bce66c7ebe12735bfa41fdc83d812660f20640fe3ba76915e6bf59383b52f
4
- data.tar.gz: 0153ae3fa2723036d9f74aa6eff3c52cf7ed6e5e46e2d33e6675e0031b4a3a0d
3
+ metadata.gz: 9f3c713f58968281bdbf88ea909c63a4e5376ffedb02c9c303f07993d9be4e03
4
+ data.tar.gz: e3961fdb0d4fcd2cc6597401477ff88f406f30d3bb49dc7b64ea9a70155d4d8d
5
5
  SHA512:
6
- metadata.gz: 494821fc7bdee2c1c435d324fb5b623bd6a6a7a19c8bdf7941ce744c41fd11c14af84e945f858e99d8fba32f5569ca68e8fbb6ff11886c814608eafb323ba700
7
- data.tar.gz: 2a07f1f41fa806e09da2b475f4206e7785519dd8d5ae18aa26e698a2d27cdd55195581a7db6e1bf1f21fe56768c6e8487bcfbedc2f3a5800dda36df9305df7d9
6
+ metadata.gz: c561cf5e4a7346437932bce2bb506590c273a5c207d62b34986c8fa92a77e1e64570bda1587b08f19aafbbacfb1f607fb3395b94463e7d8e7a925fb80efa3473
7
+ data.tar.gz: 2853e5d3e97105e3f37eaf91526cc2580a4b580337cd63f84f9eb167c12122fb0bc282b0db1ac1f76cb49b048c0e92a2f04bf3afec3495d98496910cff715f00
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- detektiiv (0.1.1)
4
+ detektiiv (0.1.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # Detektiiv
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/detektiiv`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ Detektiiv discovers factory file path defined in other namespace that call from rails application.
6
4
 
7
5
  ## Installation
8
6
 
@@ -16,13 +14,26 @@ And then execute:
16
14
 
17
15
  $ bundle
18
16
 
19
- Or install it yourself as:
17
+ ## Usage
20
18
 
21
- $ gem install detektiiv
19
+ Initialize Detektiiv after loading factory_bot gem.
22
20
 
23
- ## Usage
21
+ ```
22
+ Detektiiv.configure do |config|
23
+ config.application_name = 'Rails application name'
24
+ config.logfile_path = '/tmp/detektiiv.log'
25
+ end
24
26
 
25
- TODO: Write usage instructions here
27
+ Detektiiv.exec_patch!
28
+ ```
29
+
30
+ Then running test. If there are calling factory defined in other namespace, below log shows up.
31
+
32
+ ```
33
+ # Logfile created on 2019-07-13 13:33:02 +0900 by logger.rb/61378
34
+ {:filepath=>#<Proc:0x00007fb3a43c4c18@/Users/kamillle/sample_app/.bundle/bundler/gems/other_app/spec/factories/book.rb:3>}
35
+ {:caller=>"[\"/Users/kamillle/sample_app/spec/models/author_spec.rb:50:in `block (3 levels) in <top (required)>'\"]"}
36
+ ```
26
37
 
27
38
  ## Development
28
39
 
data/lib/detektiiv.rb CHANGED
@@ -4,6 +4,8 @@ require "detektiiv/version"
4
4
  require "detektiiv/configuration"
5
5
 
6
6
  module Detektiiv
7
+ class InitializationError < StandardError; end
8
+
7
9
  class << self
8
10
  def configure
9
11
  yield(configuration)
@@ -14,10 +16,11 @@ module Detektiiv
14
16
  end
15
17
 
16
18
  def exec_patch!
19
+ raise InitializationError, 'exec_patch! must be called after load factory_bot gem' unless defined?(FactoryBot)
20
+
17
21
  require "detektiiv/factory_runner_patch"
18
22
 
19
23
  ::FactoryBot::FactoryRunner.prepend Detektiiv::FactoryRunnerPatch
20
24
  end
21
25
  end
22
26
  end
23
-
@@ -2,8 +2,6 @@
2
2
 
3
3
  module Detektiiv
4
4
  module FactoryRunnerPatch
5
- LOGGER = Logger.new("#{Detektiiv.configuration.logfile_path}")
6
-
7
5
  def run
8
6
  logging_bad_factory_call
9
7
 
@@ -24,9 +22,19 @@ module Detektiiv
24
22
  if factory_defined_filename&.to_s&.include?("#{Detektiiv.configuration.application_name}/spec/factories") || factory_defined_filename&.to_s&.include?('factory_bot') || factory_defined_filename.nil?
25
23
  return
26
24
  else
27
- LOGGER.debug(factory_defined_filename)
28
- LOGGER.debug(caller: caller.select {|i| i.include?("#{Detektiiv.configuration.application_name}/spec") }.to_s)
25
+ logger.debug(filepath: factory_defined_filename)
26
+ logger.debug(caller: caller.select {|i| i.include?("#{Detektiiv.configuration.application_name}/spec") }.to_s)
27
+ end
28
+ end
29
+
30
+ def logger
31
+ @logger ||= Logger.new("#{Detektiiv.configuration.logfile_path}")
32
+
33
+ @logger.formatter = proc do |_severity, _datetime, _progname, msg|
34
+ "#{msg}\n"
29
35
  end
36
+
37
+ @logger
30
38
  end
31
39
  end
32
40
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Detektiiv
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: detektiiv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - kamillle
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-12 00:00:00.000000000 Z
11
+ date: 2019-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler