test-prof 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/guides/factory_default.md +8 -6
- data/guides/factory_doctor.md +1 -1
- data/guides/factory_prof.md +2 -2
- data/lib/test_prof/event_prof/custom_events/factory_create.rb +11 -9
- data/lib/test_prof/factory_bot.rb +11 -0
- data/lib/test_prof/factory_default.rb +7 -7
- data/lib/test_prof/factory_default/{factory_girl_patch.rb → factory_bot_patch.rb} +1 -1
- data/lib/test_prof/factory_doctor.rb +4 -4
- data/lib/test_prof/factory_doctor/{factory_girl_patch.rb → factory_bot_patch.rb} +1 -1
- data/lib/test_prof/factory_prof.rb +2 -2
- data/lib/test_prof/factory_prof/{factory_girl_patch.rb → factory_bot_patch.rb} +2 -2
- data/lib/test_prof/factory_prof/factory_builders/{factory_girl.rb → factory_bot.rb} +6 -6
- data/lib/test_prof/version.rb +1 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96ef8d4c37db3d7b4f3524eb9cf68d6633a4190e
|
4
|
+
data.tar.gz: 71d465796a527f2ed0a0f6e9b965f2b0cd5c5f6f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a9e26f087b6d8ecc45730ddb146faa22a9621e3067eaad03f2592a9835ce9a11f0705dd4e3ef346a00c126710f10f78fc930dd44f2899c607c2fe89d0d4de7d
|
7
|
+
data.tar.gz: d90751192e854fcd2269c4a8bb0464c47f1ae7589b51b020da7c39a4a973d8aa8a494274a7895aedc1af32485f18f9dbd515e6db8018e974958fd7858fd7dfe4
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Change log
|
2
2
|
|
3
|
+
## master branch
|
4
|
+
|
5
|
+
- [#46](https://github.com/palkan/test-prof/pull/46) Support FactoryBot, which is [former FactoryGirl](https://github.com/thoughtbot/factory_bot/pull/1051),
|
6
|
+
while maintaining compatibility with latter. ([@Shkrt][])
|
7
|
+
|
3
8
|
## 0.4.2
|
4
9
|
|
5
10
|
- Fix bug with multiple `before_all` within one group. ([@palkan][])
|
data/guides/factory_default.md
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
_Factory Default_ aims to help you cope with _factory cascades_ (see [FactoryProf](https://github.com/palkan/test-prof/tree/master/guides/factory_prof.md)) by reusing associated records.
|
4
4
|
|
5
|
+
**NOTE**. Only works with FactoryGirl/FactoryBot.
|
6
|
+
|
5
7
|
It can be very useful when you're working on a typical SaaS application (or other hierarchical data).
|
6
8
|
|
7
9
|
Consider an example. Assume we have the following factories:
|
@@ -82,7 +84,7 @@ describe "PATCH #update" do
|
|
82
84
|
end
|
83
85
|
```
|
84
86
|
|
85
|
-
|
87
|
+
**NOTE**. This feature introduces a bit of _magic_ to your tests, so use it with caution ('cause tests should be human-readable first). Good idea is to use defaults for top-level entities only (such as tenants in multi-tenancy apps).
|
86
88
|
|
87
89
|
## Instructions
|
88
90
|
|
@@ -92,18 +94,18 @@ In your `spec_helper.rb`:
|
|
92
94
|
require "test_prof/recipes/rspec/factory_default"
|
93
95
|
```
|
94
96
|
|
95
|
-
This adds two new methods to
|
97
|
+
This adds two new methods to FactoryBot:
|
96
98
|
|
97
|
-
- `
|
99
|
+
- `FactoryBot#set_factory_default(factory, object)` – use the `object` as default for associations built with `factory`
|
98
100
|
|
99
101
|
Example:
|
100
102
|
|
101
103
|
```ruby
|
102
104
|
let(:user) { create(:user) }
|
103
105
|
|
104
|
-
before {
|
106
|
+
before { FactoryBot.set_factory_default(:user, user) }
|
105
107
|
```
|
106
108
|
|
107
|
-
- `
|
109
|
+
- `FactoryBot#create_default(factory, *args)` – is a shortcut for `create` + `set_factory_default`.
|
108
110
|
|
109
|
-
|
111
|
+
**NOTE**. Defaults are cleaned up after each example.
|
data/guides/factory_doctor.md
CHANGED
data/guides/factory_prof.md
CHANGED
@@ -16,12 +16,12 @@ Example output:
|
|
16
16
|
|
17
17
|
It shows both the total number of the factory runs and the number of _top-level_ runs, i.e. not during another factory invocation (e.g. when using associations.)
|
18
18
|
|
19
|
-
**NOTE**: FactoryProf only tracks the database-persisted factories. In case of FactoryGirl these are the factories
|
19
|
+
**NOTE**: FactoryProf only tracks the database-persisted factories. In case of FactoryGirl/FactoryBot these are the factories
|
20
20
|
provided by using `create` strategy. In case of Fabrication - objects that created using `create` method.
|
21
21
|
|
22
22
|
## Instructions
|
23
23
|
|
24
|
-
FactoryProf can be used with FactoryGirl or Fabrication - application can be bundled with both gems at the same time.
|
24
|
+
FactoryProf can be used with FactoryGirl/FactoryBot or Fabrication - application can be bundled with both gems at the same time.
|
25
25
|
|
26
26
|
To activate FactoryProf use `FPROF` environment variable:
|
27
27
|
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "test_prof/ext/string_strip_heredoc"
|
4
|
+
require "test_prof/factory_bot"
|
4
5
|
|
5
6
|
using TestProf::StringStripHeredoc
|
6
7
|
|
@@ -18,7 +19,7 @@ module TestProf::EventProf::CustomEvents
|
|
18
19
|
class << self
|
19
20
|
def setup!
|
20
21
|
@depth = 0
|
21
|
-
|
22
|
+
TestProf::FactoryBot::FactoryRunner.prepend RunnerPatch
|
22
23
|
end
|
23
24
|
|
24
25
|
def track(factory)
|
@@ -44,14 +45,15 @@ module TestProf::EventProf::CustomEvents
|
|
44
45
|
end
|
45
46
|
|
46
47
|
TestProf.activate('EVENT_PROF', 'factory.create') do
|
47
|
-
if TestProf
|
48
|
-
'factory_girl',
|
49
|
-
<<-MSG.strip_heredoc
|
50
|
-
Failed to load FactoryGirl.
|
51
|
-
|
52
|
-
Make sure that "factory_girl" gem is in your Gemfile.
|
53
|
-
MSG
|
54
|
-
)
|
48
|
+
if defined? TestProf::FactoryBot
|
55
49
|
TestProf::EventProf::CustomEvents::FactoryCreate.setup!
|
50
|
+
else
|
51
|
+
TestProf.log(:error,
|
52
|
+
<<-MSG.strip_heredoc
|
53
|
+
Failed to load factory_bot / factory_girl.
|
54
|
+
|
55
|
+
Make sure that any of them is in your Gemfile.
|
56
|
+
MSG
|
57
|
+
)
|
56
58
|
end
|
57
59
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module TestProf # :nodoc: all
|
4
|
+
FACTORY_GIRL_NAMES = { 'factory_bot' => '::FactoryBot', 'factory_girl' => '::FactoryGirl' }.freeze
|
5
|
+
|
6
|
+
FACTORY_GIRL_NAMES.find do |name, cname|
|
7
|
+
TestProf.require(name) do
|
8
|
+
TestProf::FactoryBot = Object.const_get(cname)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "test_prof/factory_default/
|
3
|
+
require "test_prof/factory_default/factory_bot_patch"
|
4
4
|
|
5
5
|
module TestProf
|
6
6
|
# FactoryDefault allows use to re-use associated objects
|
@@ -10,7 +10,7 @@ module TestProf
|
|
10
10
|
def create_default(name, *args, &block)
|
11
11
|
set_factory_default(
|
12
12
|
name,
|
13
|
-
|
13
|
+
TestProf::FactoryBot.create(name, *args, &block)
|
14
14
|
)
|
15
15
|
end
|
16
16
|
|
@@ -21,11 +21,11 @@ module TestProf
|
|
21
21
|
|
22
22
|
class << self
|
23
23
|
def init
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
TestProf::FactoryBot::Syntax::Methods.include DefaultSyntax
|
25
|
+
TestProf::FactoryBot.extend DefaultSyntax
|
26
|
+
TestProf::FactoryBot::Strategy::Create.prepend StrategyExt
|
27
|
+
TestProf::FactoryBot::Strategy::Build.prepend StrategyExt
|
28
|
+
TestProf::FactoryBot::Strategy::Stub.prepend StrategyExt
|
29
29
|
|
30
30
|
@store = {}
|
31
31
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "test_prof/factory_doctor/
|
3
|
+
require "test_prof/factory_doctor/factory_bot_patch"
|
4
4
|
|
5
5
|
module TestProf
|
6
6
|
# FactoryDoctor is a tool that helps you identify
|
@@ -49,9 +49,9 @@ module TestProf
|
|
49
49
|
|
50
50
|
log :info, "FactoryDoctor enabled"
|
51
51
|
|
52
|
-
# Monkey-patch FactoryGirl
|
53
|
-
::
|
54
|
-
defined?(::
|
52
|
+
# Monkey-patch FactoryBot / FactoryGirl
|
53
|
+
TestProf::FactoryBot::FactoryRunner.prepend(FactoryBotPatch) if
|
54
|
+
defined?(TestProf::FactoryBot)
|
55
55
|
|
56
56
|
subscribe!
|
57
57
|
|
@@ -2,14 +2,14 @@
|
|
2
2
|
|
3
3
|
require "test_prof/factory_prof/printers/simple"
|
4
4
|
require "test_prof/factory_prof/printers/flamegraph"
|
5
|
-
require "test_prof/factory_prof/factory_builders/
|
5
|
+
require "test_prof/factory_prof/factory_builders/factory_bot"
|
6
6
|
require "test_prof/factory_prof/factory_builders/fabrication"
|
7
7
|
|
8
8
|
module TestProf
|
9
9
|
# FactoryProf collects "factory stacks" that can be used to build
|
10
10
|
# flamegraphs or detect most popular factories
|
11
11
|
module FactoryProf
|
12
|
-
FACTORY_BUILDERS = [FactoryBuilders::
|
12
|
+
FACTORY_BUILDERS = [FactoryBuilders::FactoryBot,
|
13
13
|
FactoryBuilders::Fabrication].freeze
|
14
14
|
|
15
15
|
# FactoryProf configuration
|
@@ -3,9 +3,9 @@
|
|
3
3
|
module TestProf
|
4
4
|
module FactoryProf
|
5
5
|
# Wrap #run method with FactoryProf tracking
|
6
|
-
module
|
6
|
+
module FactoryBotPatch
|
7
7
|
def run(strategy = @strategy)
|
8
|
-
FactoryBuilders::
|
8
|
+
FactoryBuilders::FactoryBot.track(strategy, @name) { super }
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
@@ -1,18 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "test_prof/factory_prof/
|
3
|
+
require "test_prof/factory_prof/factory_bot_patch"
|
4
|
+
require "test_prof/factory_bot"
|
4
5
|
|
5
6
|
module TestProf
|
6
7
|
module FactoryProf
|
7
8
|
module FactoryBuilders
|
8
9
|
# implementation of #patch and #track methods
|
9
10
|
# to provide unified interface for all factory-building gems
|
10
|
-
class
|
11
|
-
# Monkey-patch FactoryGirl
|
11
|
+
class FactoryBot
|
12
|
+
# Monkey-patch FactoryBot / FactoryGirl
|
12
13
|
def self.patch
|
13
|
-
TestProf.
|
14
|
-
::
|
15
|
-
end
|
14
|
+
TestProf::FactoryBot::FactoryRunner.prepend(FactoryBotPatch) if
|
15
|
+
defined? TestProf::FactoryBot
|
16
16
|
end
|
17
17
|
|
18
18
|
def self.track(strategy, factory, &block)
|
data/lib/test_prof/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: test-prof
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vladimir Dementyev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -136,17 +136,18 @@ files:
|
|
136
136
|
- lib/test_prof/ext/float_duration.rb
|
137
137
|
- lib/test_prof/ext/string_strip_heredoc.rb
|
138
138
|
- lib/test_prof/ext/string_truncate.rb
|
139
|
+
- lib/test_prof/factory_bot.rb
|
139
140
|
- lib/test_prof/factory_default.rb
|
140
|
-
- lib/test_prof/factory_default/
|
141
|
+
- lib/test_prof/factory_default/factory_bot_patch.rb
|
141
142
|
- lib/test_prof/factory_doctor.rb
|
142
|
-
- lib/test_prof/factory_doctor/
|
143
|
+
- lib/test_prof/factory_doctor/factory_bot_patch.rb
|
143
144
|
- lib/test_prof/factory_doctor/minitest.rb
|
144
145
|
- lib/test_prof/factory_doctor/rspec.rb
|
145
146
|
- lib/test_prof/factory_prof.rb
|
146
147
|
- lib/test_prof/factory_prof/fabrication_patch.rb
|
148
|
+
- lib/test_prof/factory_prof/factory_bot_patch.rb
|
147
149
|
- lib/test_prof/factory_prof/factory_builders/fabrication.rb
|
148
|
-
- lib/test_prof/factory_prof/factory_builders/
|
149
|
-
- lib/test_prof/factory_prof/factory_girl_patch.rb
|
150
|
+
- lib/test_prof/factory_prof/factory_builders/factory_bot.rb
|
150
151
|
- lib/test_prof/factory_prof/printers/flamegraph.rb
|
151
152
|
- lib/test_prof/factory_prof/printers/simple.rb
|
152
153
|
- lib/test_prof/logging.rb
|