test-prof 1.0.0.rc1 → 1.0.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/lib/test_prof/before_all.rb +9 -0
- data/lib/test_prof/before_all/adapters/active_record.rb +14 -0
- data/lib/test_prof/recipes/minitest/before_all.rb +32 -12
- data/lib/test_prof/recipes/rspec/before_all.rb +10 -2
- data/lib/test_prof/recipes/rspec/let_it_be.rb +3 -2
- data/lib/test_prof/version.rb +1 -1
- 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: ae1131d5828c1e2b52eab444c34c89bd82b294a7b3725f62c01ce30d7526f46b
|
4
|
+
data.tar.gz: 5f0bf2610fef5ad188999259aaca14918e3d96d9d5d2fdc9b6f60a961b02a20f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac9329e707caa20870ec22035678585a9a344968ea98f5f210a6fb0c25558d85162145ff47d731b77f9b17a71bb0c8d1fb23d57b5a46eba2af4244b2c6f269f6
|
7
|
+
data.tar.gz: dc0795ccc8916f93ffb9303d703a81da20d3723401b55d2c1ddfef45f8fb2d5879f9988c8b78cb9efe9ea0279e5adb610055bbf56433ff4a01101b9d7c6344e3
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,16 @@
|
|
2
2
|
|
3
3
|
## master (unrealeased)
|
4
4
|
|
5
|
+
## 1.0.0.rc2 (2021-01-06)
|
6
|
+
|
7
|
+
- Make Rails fixtures accesible in `before_all`. ([@palkan][])
|
8
|
+
|
9
|
+
You can load and access fixtures when explicitly enabling them via `before_all(setup_fixtures: true, &block)`.
|
10
|
+
|
11
|
+
- Minitest's `before_all` is not longer experimental. ([@palkan][])
|
12
|
+
|
13
|
+
- Add `after_all` to Minitest in addition to `before_all`. ([@palkan][])
|
14
|
+
|
5
15
|
## 1.0.0.rc1 (2020-12-30)
|
6
16
|
|
7
17
|
- Remove deprecated `AggregateFailures` cop. ([@palkan][])
|
data/lib/test_prof/before_all.rb
CHANGED
@@ -32,6 +32,12 @@ module TestProf
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
+
def setup_fixtures(test_object)
|
36
|
+
raise ArgumentError, "Current adapter doesn't support #setup_fixtures" unless adapter.respond_to?(:setup_fixtures)
|
37
|
+
|
38
|
+
adapter.setup_fixtures(test_object)
|
39
|
+
end
|
40
|
+
|
35
41
|
def config
|
36
42
|
@config ||= Configuration.new
|
37
43
|
end
|
@@ -60,8 +66,11 @@ module TestProf
|
|
60
66
|
class Configuration
|
61
67
|
HOOKS = %i[begin rollback].freeze
|
62
68
|
|
69
|
+
attr_accessor :setup_fixtures
|
70
|
+
|
63
71
|
def initialize
|
64
72
|
@hooks = Hash.new { |h, k| h[k] = HooksChain.new(k) }
|
73
|
+
@setup_fixtures = false
|
65
74
|
end
|
66
75
|
|
67
76
|
# Add `before` hook for `begin` or
|
@@ -18,6 +18,20 @@ module TestProf
|
|
18
18
|
end
|
19
19
|
::ActiveRecord::Base.connection.rollback_transaction
|
20
20
|
end
|
21
|
+
|
22
|
+
def setup_fixtures(test_object)
|
23
|
+
test_object.instance_eval do
|
24
|
+
@@already_loaded_fixtures ||= {}
|
25
|
+
@fixture_cache ||= {}
|
26
|
+
|
27
|
+
if @@already_loaded_fixtures[self.class]
|
28
|
+
@loaded_fixtures = @@already_loaded_fixtures[self.class]
|
29
|
+
else
|
30
|
+
@loaded_fixtures = load_fixtures(config)
|
31
|
+
@@already_loaded_fixtures[self.class] = @loaded_fixtures
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
21
35
|
end
|
22
36
|
end
|
23
37
|
end
|
@@ -8,33 +8,45 @@ module TestProf
|
|
8
8
|
# store instance variables
|
9
9
|
module Minitest # :nodoc: all
|
10
10
|
class Executor
|
11
|
-
attr_reader :active, :block, :captured_ivars
|
11
|
+
attr_reader :active, :block, :captured_ivars, :teardown_block, :current_test_object,
|
12
|
+
:setup_fixtures
|
12
13
|
|
13
14
|
alias active? active
|
15
|
+
alias setup_fixtures? setup_fixtures
|
14
16
|
|
15
|
-
def initialize(&block)
|
17
|
+
def initialize(setup_fixtures: false, &block)
|
18
|
+
@setup_fixtures = setup_fixtures
|
16
19
|
@block = block
|
17
20
|
@captured_ivars = []
|
18
21
|
end
|
19
22
|
|
23
|
+
def teardown(&block)
|
24
|
+
@teardown_block = block
|
25
|
+
end
|
26
|
+
|
20
27
|
def activate!(test_object)
|
28
|
+
@current_test_object = test_object
|
29
|
+
|
21
30
|
return restore_ivars(test_object) if active?
|
22
31
|
@active = true
|
23
|
-
|
32
|
+
BeforeAll.setup_fixtures(test_object) if setup_fixtures?
|
24
33
|
BeforeAll.begin_transaction do
|
25
34
|
capture!(test_object)
|
26
35
|
end
|
27
36
|
end
|
28
37
|
|
29
|
-
def
|
30
|
-
@examples_left -= 1
|
31
|
-
return unless @examples_left.zero?
|
32
|
-
|
38
|
+
def deactivate!
|
33
39
|
@active = false
|
40
|
+
|
41
|
+
current_test_object&.instance_eval(&teardown_block) if teardown_block
|
42
|
+
|
43
|
+
@current_test_object = nil
|
34
44
|
BeforeAll.rollback_transaction
|
35
45
|
end
|
36
46
|
|
37
47
|
def capture!(test_object)
|
48
|
+
return unless block
|
49
|
+
|
38
50
|
before_ivars = test_object.instance_variables
|
39
51
|
|
40
52
|
test_object.instance_eval(&block)
|
@@ -63,21 +75,29 @@ module TestProf
|
|
63
75
|
module ClassMethods
|
64
76
|
attr_accessor :before_all_executor
|
65
77
|
|
66
|
-
def before_all(&block)
|
67
|
-
self.before_all_executor = Executor.new(&block)
|
78
|
+
def before_all(setup_fixtures: BeforeAll.config.setup_fixtures, &block)
|
79
|
+
self.before_all_executor = Executor.new(setup_fixtures: setup_fixtures, &block)
|
68
80
|
|
69
81
|
prepend(Module.new do
|
70
|
-
def
|
82
|
+
def before_setup
|
71
83
|
self.class.before_all_executor.activate!(self)
|
72
84
|
super
|
73
85
|
end
|
86
|
+
end)
|
74
87
|
|
75
|
-
|
88
|
+
singleton_class.prepend(Module.new do
|
89
|
+
def run(*)
|
76
90
|
super
|
77
|
-
|
91
|
+
ensure
|
92
|
+
before_all_executor&.deactivate!
|
78
93
|
end
|
79
94
|
end)
|
80
95
|
end
|
96
|
+
|
97
|
+
def after_all(&block)
|
98
|
+
self.before_all_executor ||= Executor.new
|
99
|
+
before_all_executor.teardown(&block)
|
100
|
+
end
|
81
101
|
end
|
82
102
|
end
|
83
103
|
end
|
@@ -6,14 +6,22 @@ module TestProf
|
|
6
6
|
module BeforeAll
|
7
7
|
# Helper to wrap the whole example group into a transaction
|
8
8
|
module RSpec
|
9
|
-
def before_all(&block)
|
9
|
+
def before_all(setup_fixtures: BeforeAll.config.setup_fixtures, &block)
|
10
10
|
raise ArgumentError, "Block is required!" unless block_given?
|
11
11
|
|
12
|
-
|
12
|
+
if within_before_all?
|
13
|
+
before(:all) do
|
14
|
+
@__inspect_output = "before_all hook"
|
15
|
+
instance_eval(&block)
|
16
|
+
end
|
17
|
+
return
|
18
|
+
end
|
13
19
|
|
14
20
|
@__before_all_activated__ = true
|
15
21
|
|
16
22
|
before(:all) do
|
23
|
+
@__inspect_output = "before_all hook"
|
24
|
+
BeforeAll.setup_fixtures(self) if setup_fixtures
|
17
25
|
BeforeAll.begin_transaction do
|
18
26
|
instance_eval(&block)
|
19
27
|
end
|
@@ -108,8 +108,9 @@ module TestProf
|
|
108
108
|
|
109
109
|
LetItBe.module_for(self).module_eval do
|
110
110
|
define_method(identifier) do
|
111
|
-
# Trying to detect the context
|
112
|
-
|
111
|
+
# Trying to detect the context
|
112
|
+
# Based on https://github.com/rspec/rspec-rails/commit/7cb796db064f58da7790a92e73ab906ef50b1f34
|
113
|
+
if @__inspect_output.include?("before(:context)") || @__inspect_output.include?("before_all")
|
113
114
|
instance_variable_get(:"#{PREFIX}#{identifier}")
|
114
115
|
else
|
115
116
|
# Fallback to let definition
|
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: 1.0.0.
|
4
|
+
version: 1.0.0.rc2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vladimir Dementyev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|