test_data 0.3.1 → 0.3.2
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/CHANGELOG.md +6 -0
- data/Gemfile.lock +7 -7
- data/README.md +36 -16
- data/example/Gemfile.lock +12 -14
- data/lib/generators/test_data/webpacker_yaml_generator.rb +25 -11
- data/lib/test_data/configurators/webpacker_yaml.rb +11 -16
- data/lib/test_data/rake.rb +1 -1
- data/lib/test_data/version.rb +1 -1
- data/lib/test_data/wrap/webpacker_config.rb +42 -0
- data/lib/test_data.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e046c25f181fc9022139cd1d009142b390d7da348d9eb00dc18f03291927c35
|
4
|
+
data.tar.gz: 60dfa3ca0fbbf8389d009ceec584f2239eb01391c2e3fb88badd063669c48d28
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d3727bbd0f8bf7cb3d32c042864a624c0cf5ebcd956f7abf158aeb0cabbbc97505a4c18b5f4345a8ea4570d56384532f2ecfeed03d1319850f92a61602ecb63
|
7
|
+
data.tar.gz: dab23d60d8c459bc756e532e35e7de0e499a3b760a1f3ec652d5aea866503b6ccdac670edcc0bba0fafc1cc4f7c3281b98b21760ce84b808d5c5428b25f1d64b
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
test_data (0.3.
|
4
|
+
test_data (0.3.2)
|
5
5
|
railties (>= 6.0, < 8.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -33,7 +33,7 @@ GEM
|
|
33
33
|
erubi (1.10.0)
|
34
34
|
i18n (1.10.0)
|
35
35
|
concurrent-ruby (~> 1.0)
|
36
|
-
loofah (2.
|
36
|
+
loofah (2.16.0)
|
37
37
|
crass (~> 1.0.2)
|
38
38
|
nokogiri (>= 1.5.9)
|
39
39
|
method_source (1.0.0)
|
@@ -66,9 +66,9 @@ GEM
|
|
66
66
|
zeitwerk (~> 2.5)
|
67
67
|
rainbow (3.1.1)
|
68
68
|
rake (13.0.6)
|
69
|
-
regexp_parser (2.
|
69
|
+
regexp_parser (2.3.0)
|
70
70
|
rexml (3.2.5)
|
71
|
-
rubocop (1.26.
|
71
|
+
rubocop (1.26.1)
|
72
72
|
parallel (~> 1.10)
|
73
73
|
parser (>= 3.1.0.0)
|
74
74
|
rainbow (>= 2.2.2, < 4.0)
|
@@ -77,14 +77,14 @@ GEM
|
|
77
77
|
rubocop-ast (>= 1.16.0, < 2.0)
|
78
78
|
ruby-progressbar (~> 1.7)
|
79
79
|
unicode-display_width (>= 1.4.0, < 3.0)
|
80
|
-
rubocop-ast (1.
|
80
|
+
rubocop-ast (1.17.0)
|
81
81
|
parser (>= 3.1.1.0)
|
82
82
|
rubocop-performance (1.13.3)
|
83
83
|
rubocop (>= 1.7.0, < 2.0)
|
84
84
|
rubocop-ast (>= 0.4.0)
|
85
85
|
ruby-progressbar (1.11.0)
|
86
|
-
standard (1.9.
|
87
|
-
rubocop (= 1.26.
|
86
|
+
standard (1.9.1)
|
87
|
+
rubocop (= 1.26.1)
|
88
88
|
rubocop-performance (= 1.13.3)
|
89
89
|
thor (1.2.1)
|
90
90
|
tzinfo (2.0.4)
|
data/README.md
CHANGED
@@ -19,8 +19,8 @@ What it does:
|
|
19
19
|
app**
|
20
20
|
|
21
21
|
* Exposes a simple API for ensuring that your data will be pristine for each of
|
22
|
-
your tests, whether the test depends on test_data,
|
23
|
-
|
22
|
+
your tests, whether the test depends on test_data, factories, fixtures, or an
|
23
|
+
empty database
|
24
24
|
|
25
25
|
* Safeguards your tests from flaky failures and supercharges your build by
|
26
26
|
providing a sophisticated transaction manager that isolates each test while
|
@@ -41,11 +41,11 @@ are required**—so it may not work for every project just yet.]_
|
|
41
41
|
|
42
42
|
This gem requires a lot of documentation—not because `test_data` does a lot of
|
43
43
|
things, but because managing one's test data is an inherently complex task. If
|
44
|
-
one reason Rails apps
|
45
|
-
approaches
|
46
|
-
|
47
|
-
|
48
|
-
|
44
|
+
there's one reason Rails apps often suffer from slow tests, it's that the most
|
45
|
+
popular approaches to test data management oversimplify the problem—they might
|
46
|
+
save time up front, but tend to cost you later. The `test_data` gem, meanwhile,
|
47
|
+
is designed to tackle the problem head on: it takes longer to set up, but it'll
|
48
|
+
scale along with your application for years to come.
|
49
49
|
|
50
50
|
1. [Getting Started Guide](#getting-started-guide)
|
51
51
|
1. [Install and initialize `test_data`](#step-1-install-and-initialize-test_data)
|
@@ -106,22 +106,42 @@ And if you get stuck or need help as you're getting started, please feel free to
|
|
106
106
|
|
107
107
|
### Step 1: Install and initialize `test_data`
|
108
108
|
|
109
|
-
#### Adding
|
109
|
+
#### Adding a `:test_data` group to your Gemfile
|
110
|
+
|
111
|
+
Before even installing anything, it's important to understand that because
|
112
|
+
`test_data` defines a new Rails environment and because Rails expects
|
113
|
+
a gem group (like `:development`, `:test`, and `:production`) for each
|
114
|
+
environment, any gems we want to be available to the `test_data` gem need to be
|
115
|
+
installed with a `:test_data` group.
|
110
116
|
|
111
|
-
|
112
|
-
|
117
|
+
Since the `test_data` environment is designed to be used similarly to
|
118
|
+
`development` (i.e. with a running server and interacting via a browser), any
|
119
|
+
gems in your `:development` gem group should likely be included in a
|
120
|
+
`:test_data` gem group as well.
|
121
|
+
|
122
|
+
For example, this:
|
113
123
|
|
114
124
|
```ruby
|
115
|
-
group :development, :test
|
125
|
+
group :development, :test do
|
126
|
+
gem "standard"
|
127
|
+
gem "cypress-rails"
|
116
128
|
gem "test_data"
|
117
|
-
# … other gems available to development & test
|
118
129
|
end
|
119
130
|
```
|
120
131
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
132
|
+
Should have its first line changed to:
|
133
|
+
|
134
|
+
```ruby
|
135
|
+
group :development, :test, :test_data do
|
136
|
+
```
|
137
|
+
|
138
|
+
#### Adding the gem
|
139
|
+
|
140
|
+
Finally, add `test_data` to your Gemfile and `bundle install` it:
|
141
|
+
|
142
|
+
```ruby
|
143
|
+
gem "test_data"
|
144
|
+
```
|
125
145
|
|
126
146
|
#### Configuring the gem and initializing the database
|
127
147
|
|
data/example/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ..
|
3
3
|
specs:
|
4
|
-
test_data (0.3.
|
4
|
+
test_data (0.3.2)
|
5
5
|
railties (>= 6.0, < 8.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -103,8 +103,7 @@ GEM
|
|
103
103
|
activesupport (>= 5.0)
|
104
104
|
i18n (1.10.0)
|
105
105
|
concurrent-ruby (~> 1.0)
|
106
|
-
|
107
|
-
loofah (2.15.0)
|
106
|
+
loofah (2.16.0)
|
108
107
|
crass (~> 1.0.2)
|
109
108
|
nokogiri (>= 1.5.9)
|
110
109
|
mail (2.7.1)
|
@@ -115,7 +114,7 @@ GEM
|
|
115
114
|
mini_mime (1.1.2)
|
116
115
|
mini_portile2 (2.8.0)
|
117
116
|
minitest (5.15.0)
|
118
|
-
msgpack (1.
|
117
|
+
msgpack (1.5.1)
|
119
118
|
net-imap (0.2.3)
|
120
119
|
digest
|
121
120
|
net-protocol
|
@@ -124,8 +123,7 @@ GEM
|
|
124
123
|
digest
|
125
124
|
net-protocol
|
126
125
|
timeout
|
127
|
-
net-protocol (0.1.
|
128
|
-
io-wait
|
126
|
+
net-protocol (0.1.3)
|
129
127
|
timeout
|
130
128
|
net-smtp (0.3.1)
|
131
129
|
digest
|
@@ -139,14 +137,14 @@ GEM
|
|
139
137
|
parallel (1.22.1)
|
140
138
|
parser (3.1.1.0)
|
141
139
|
ast (~> 2.4.1)
|
142
|
-
pg (1.3.
|
140
|
+
pg (1.3.5)
|
143
141
|
pry (0.14.1)
|
144
142
|
coderay (~> 1.1)
|
145
143
|
method_source (~> 1.0)
|
146
144
|
pry-rails (0.3.9)
|
147
145
|
pry (>= 0.10.4)
|
148
146
|
public_suffix (4.0.6)
|
149
|
-
puma (5.6.
|
147
|
+
puma (5.6.4)
|
150
148
|
nio4r (~> 2.0)
|
151
149
|
racc (1.6.0)
|
152
150
|
rack (2.2.3)
|
@@ -180,14 +178,14 @@ GEM
|
|
180
178
|
zeitwerk (~> 2.5)
|
181
179
|
rainbow (3.1.1)
|
182
180
|
rake (13.0.6)
|
183
|
-
regexp_parser (2.
|
181
|
+
regexp_parser (2.3.0)
|
184
182
|
rexml (3.2.5)
|
185
183
|
rspec-core (3.11.0)
|
186
184
|
rspec-support (~> 3.11.0)
|
187
185
|
rspec-expectations (3.11.0)
|
188
186
|
diff-lcs (>= 1.2.0, < 2.0)
|
189
187
|
rspec-support (~> 3.11.0)
|
190
|
-
rspec-mocks (3.11.
|
188
|
+
rspec-mocks (3.11.1)
|
191
189
|
diff-lcs (>= 1.2.0, < 2.0)
|
192
190
|
rspec-support (~> 3.11.0)
|
193
191
|
rspec-rails (5.1.1)
|
@@ -199,7 +197,7 @@ GEM
|
|
199
197
|
rspec-mocks (~> 3.10)
|
200
198
|
rspec-support (~> 3.10)
|
201
199
|
rspec-support (3.11.0)
|
202
|
-
rubocop (1.26.
|
200
|
+
rubocop (1.26.1)
|
203
201
|
parallel (~> 1.10)
|
204
202
|
parser (>= 3.1.0.0)
|
205
203
|
rainbow (>= 2.2.2, < 4.0)
|
@@ -208,7 +206,7 @@ GEM
|
|
208
206
|
rubocop-ast (>= 1.16.0, < 2.0)
|
209
207
|
ruby-progressbar (~> 1.7)
|
210
208
|
unicode-display_width (>= 1.4.0, < 3.0)
|
211
|
-
rubocop-ast (1.
|
209
|
+
rubocop-ast (1.17.0)
|
212
210
|
parser (>= 3.1.1.0)
|
213
211
|
rubocop-performance (1.13.3)
|
214
212
|
rubocop (>= 1.7.0, < 2.0)
|
@@ -219,8 +217,8 @@ GEM
|
|
219
217
|
childprocess (>= 0.5, < 5.0)
|
220
218
|
rexml (~> 3.2, >= 3.2.5)
|
221
219
|
rubyzip (>= 1.2.2)
|
222
|
-
standard (1.9.
|
223
|
-
rubocop (= 1.26.
|
220
|
+
standard (1.9.1)
|
221
|
+
rubocop (= 1.26.1)
|
224
222
|
rubocop-performance (= 1.13.3)
|
225
223
|
strscan (3.0.1)
|
226
224
|
thor (1.2.1)
|
@@ -4,22 +4,36 @@ require_relative "../../test_data/generator_support"
|
|
4
4
|
module TestData
|
5
5
|
class WebpackerYamlGenerator < Rails::Generators::Base
|
6
6
|
AFTER_DEVELOPMENT_WEBPACK_STANZA_REGEX = /^development:/
|
7
|
+
AFTER_TEST_DATA_WEBPACK_STANZA_REGEX = /^test_data:\n <<: \*development/
|
7
8
|
|
8
9
|
def call
|
9
|
-
|
10
|
-
|
10
|
+
configurator = Configurators::WebpackerYaml.new
|
11
|
+
webpacker_config = Wrap::WebpackerConfig.new
|
12
|
+
|
13
|
+
if configurator.verify.looks_good?
|
14
|
+
TestData.log.debug "'test_data' section looks good in `config/webpacker.yml'"
|
11
15
|
else
|
12
|
-
|
13
|
-
"
|
14
|
-
|
15
|
-
|
16
|
-
|
16
|
+
unless webpacker_config.user_config.key?("test_data")
|
17
|
+
inject_into_file "config/webpacker.yml", after: AFTER_DEVELOPMENT_WEBPACK_STANZA_REGEX do
|
18
|
+
" &development"
|
19
|
+
end
|
20
|
+
inject_into_file "config/webpacker.yml", before: BEFORE_TEST_STANZA_REGEX do
|
21
|
+
<<~YAML
|
17
22
|
|
18
|
-
|
19
|
-
|
20
|
-
|
23
|
+
# Used in conjunction with the test_data gem
|
24
|
+
test_data:
|
25
|
+
<<: *development
|
26
|
+
|
27
|
+
YAML
|
28
|
+
end
|
29
|
+
end
|
21
30
|
|
22
|
-
|
31
|
+
if (missing_entries = webpacker_config.required_entries_missing_from_test_data_config)
|
32
|
+
inject_into_file "config/webpacker.yml", after: /^test_data:\n/ do
|
33
|
+
missing_entries.map { |(key, val)|
|
34
|
+
" #{key}: #{val.inspect}\n"
|
35
|
+
}.join
|
36
|
+
end
|
23
37
|
end
|
24
38
|
end
|
25
39
|
end
|
@@ -3,21 +3,23 @@ module TestData
|
|
3
3
|
class WebpackerYaml
|
4
4
|
def initialize
|
5
5
|
@generator = WebpackerYamlGenerator.new
|
6
|
-
@
|
6
|
+
@webpacker_config = Wrap::WebpackerConfig.new
|
7
7
|
end
|
8
8
|
|
9
9
|
def verify
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
if @webpacker_config.no_user_config_exists?
|
11
|
+
ConfigurationVerification.new(looks_good?: true)
|
12
|
+
elsif (user_config = @webpacker_config.user_config).nil?
|
13
|
+
ConfigurationVerification.new(problems: [
|
14
|
+
"`#{@webpacker_config.relative_user_config_path}' is not valid YAML"
|
15
|
+
])
|
16
|
+
elsif !user_config.key?("test_data")
|
15
17
|
ConfigurationVerification.new(problems: [
|
16
|
-
"
|
18
|
+
"`#{@webpacker_config.relative_user_config_path}' does not contain a `test_data' section"
|
17
19
|
])
|
18
|
-
elsif
|
20
|
+
elsif (entries = @webpacker_config.required_entries_missing_from_test_data_config)
|
19
21
|
ConfigurationVerification.new(problems: [
|
20
|
-
"'#{
|
22
|
+
"`#{@webpacker_config.relative_user_config_path}' is missing #{"entry".pluralize(entries.size)} #{entries.map { |(k, v)| "`#{k}' (default: #{v.inspect})" }.join(", ")} in its `test_data' section"
|
21
23
|
])
|
22
24
|
else
|
23
25
|
ConfigurationVerification.new(looks_good?: true)
|
@@ -27,13 +29,6 @@ module TestData
|
|
27
29
|
def configure
|
28
30
|
@generator.call
|
29
31
|
end
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
def load_yaml(pathname)
|
34
|
-
YAML.load_file(pathname)
|
35
|
-
rescue
|
36
|
-
end
|
37
32
|
end
|
38
33
|
end
|
39
34
|
end
|
data/lib/test_data/rake.rb
CHANGED
@@ -3,7 +3,7 @@ def wrong_env?
|
|
3
3
|
end
|
4
4
|
|
5
5
|
def run_in_test_data_env(task_name)
|
6
|
-
command = "RAILS_ENV=test_data #{Rails.root}/bin/rake #{task_name}"
|
6
|
+
command = "RAILS_ENV=test_data #{Rails.root}/bin/rake #{task_name} --trace"
|
7
7
|
unless system(command)
|
8
8
|
fail "An error ocurred when running: #{command}"
|
9
9
|
end
|
data/lib/test_data/version.rb
CHANGED
@@ -0,0 +1,42 @@
|
|
1
|
+
module TestData
|
2
|
+
module Wrap
|
3
|
+
class WebpackerConfig
|
4
|
+
def initialize
|
5
|
+
@user_config_path = Pathname.new("#{TestData.config.pwd}/config/webpacker.yml")
|
6
|
+
end
|
7
|
+
|
8
|
+
def relative_user_config_path
|
9
|
+
@user_config_path.relative_path_from(Rails.root)
|
10
|
+
end
|
11
|
+
|
12
|
+
def no_user_config_exists?
|
13
|
+
!@user_config_path.readable?
|
14
|
+
end
|
15
|
+
|
16
|
+
def user_config
|
17
|
+
load_yaml(@user_config_path)
|
18
|
+
end
|
19
|
+
|
20
|
+
def webpacker_gem_spec_loaded?
|
21
|
+
!!Gem.loaded_specs["webpacker"]
|
22
|
+
end
|
23
|
+
|
24
|
+
def builtin_config
|
25
|
+
webpacker_path = Gem.loaded_specs["webpacker"].full_gem_path
|
26
|
+
load_yaml(File.join(webpacker_path, "lib/install/config/webpacker.yml"))
|
27
|
+
end
|
28
|
+
|
29
|
+
def required_entries_missing_from_test_data_config
|
30
|
+
missing_keys = builtin_config["development"].keys - user_config["test_data"].keys
|
31
|
+
builtin_config["development"].slice(*missing_keys).presence
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def load_yaml(path)
|
37
|
+
YAML.load_file(path)
|
38
|
+
rescue
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/test_data.rb
CHANGED
@@ -11,6 +11,7 @@ require_relative "test_data/configurators/secrets_yaml"
|
|
11
11
|
require_relative "test_data/configurators/webpacker_yaml"
|
12
12
|
require_relative "test_data/custom_loaders/abstract_base"
|
13
13
|
require_relative "test_data/custom_loaders/rails_fixtures"
|
14
|
+
require_relative "test_data/wrap/webpacker_config"
|
14
15
|
require_relative "test_data/detects_database_emptiness"
|
15
16
|
require_relative "test_data/detects_database_existence"
|
16
17
|
require_relative "test_data/determines_when_sql_dump_was_made"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: test_data
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Searls
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -164,6 +164,7 @@ files:
|
|
164
164
|
- lib/test_data/version.rb
|
165
165
|
- lib/test_data/warns_if_database_is_newer_than_dump.rb
|
166
166
|
- lib/test_data/warns_if_dump_is_newer_than_database.rb
|
167
|
+
- lib/test_data/wrap/webpacker_config.rb
|
167
168
|
- script/reset_example_app
|
168
169
|
- script/test
|
169
170
|
- test_data.gemspec
|