test_data 0.2.2 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +19 -0
- data/Gemfile.lock +42 -42
- data/LICENSE.txt +1 -1
- data/README.md +66 -44
- data/example/Gemfile.lock +142 -123
- 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/detects_database_existence.rb +19 -0
- data/lib/test_data/determines_databases_associated_dump_time.rb +13 -0
- data/lib/test_data/determines_when_sql_dump_was_made.rb +24 -0
- data/lib/test_data/dumps_database.rb +3 -0
- data/lib/test_data/railtie.rb +4 -0
- data/lib/test_data/rake.rb +40 -10
- data/lib/test_data/records_dump_metadata.rb +9 -0
- data/lib/test_data/version.rb +1 -1
- data/lib/test_data/warns_if_database_is_newer_than_dump.rb +32 -0
- data/lib/test_data/warns_if_dump_is_newer_than_database.rb +36 -0
- data/lib/test_data/wrap/webpacker_config.rb +42 -0
- data/lib/test_data.rb +13 -1
- data/script/test +34 -0
- data/test_data.gemspec +1 -1
- metadata +18 -5
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
@@ -1,3 +1,22 @@
|
|
1
|
+
# 0.3.2
|
2
|
+
|
3
|
+
- Improve the flexibility of the webpacker config generator
|
4
|
+
- Improve failure output when an error is raised during rake tests that fork
|
5
|
+
into a `test_data` env
|
6
|
+
|
7
|
+
# 0.3.1
|
8
|
+
|
9
|
+
- Loosen railties dependencies after verifying basic Rails 7 support
|
10
|
+
|
11
|
+
# 0.3.0
|
12
|
+
|
13
|
+
- Add a `test_data:reinitialize` task that will delete the `test_data` database
|
14
|
+
if necessary before invoking `test_data:initialize`
|
15
|
+
- Warn if re-initializing and the local database appears to have been dumped
|
16
|
+
or loaded from a dump that is newer than the dumps on disk
|
17
|
+
- Add a warning on app load if the dumps on disk appear
|
18
|
+
newer than the local `test_data` database
|
19
|
+
|
1
20
|
# 0.2.2
|
2
21
|
|
3
22
|
- Improve performance of Rails fixtures being repeatedly loaded by changing the
|
data/Gemfile.lock
CHANGED
@@ -1,96 +1,96 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
test_data (0.
|
5
|
-
railties (
|
4
|
+
test_data (0.3.2)
|
5
|
+
railties (>= 6.0, < 8.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
actionpack (
|
11
|
-
actionview (=
|
12
|
-
activesupport (=
|
13
|
-
rack (~> 2.0, >= 2.0
|
10
|
+
actionpack (7.0.2.3)
|
11
|
+
actionview (= 7.0.2.3)
|
12
|
+
activesupport (= 7.0.2.3)
|
13
|
+
rack (~> 2.0, >= 2.2.0)
|
14
14
|
rack-test (>= 0.6.3)
|
15
15
|
rails-dom-testing (~> 2.0)
|
16
16
|
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
17
|
-
actionview (
|
18
|
-
activesupport (=
|
17
|
+
actionview (7.0.2.3)
|
18
|
+
activesupport (= 7.0.2.3)
|
19
19
|
builder (~> 3.1)
|
20
20
|
erubi (~> 1.4)
|
21
21
|
rails-dom-testing (~> 2.0)
|
22
22
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
23
|
-
activesupport (
|
23
|
+
activesupport (7.0.2.3)
|
24
24
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
25
25
|
i18n (>= 1.6, < 2)
|
26
26
|
minitest (>= 5.1)
|
27
27
|
tzinfo (~> 2.0)
|
28
|
-
zeitwerk (~> 2.3)
|
29
28
|
ast (2.4.2)
|
30
29
|
builder (3.2.4)
|
31
30
|
coderay (1.1.3)
|
32
|
-
concurrent-ruby (1.1.
|
31
|
+
concurrent-ruby (1.1.10)
|
33
32
|
crass (1.0.6)
|
34
33
|
erubi (1.10.0)
|
35
|
-
i18n (1.
|
34
|
+
i18n (1.10.0)
|
36
35
|
concurrent-ruby (~> 1.0)
|
37
|
-
loofah (2.
|
36
|
+
loofah (2.16.0)
|
38
37
|
crass (~> 1.0.2)
|
39
38
|
nokogiri (>= 1.5.9)
|
40
39
|
method_source (1.0.0)
|
41
|
-
mini_portile2 (2.
|
42
|
-
minitest (5.
|
43
|
-
nokogiri (1.
|
44
|
-
mini_portile2 (~> 2.
|
40
|
+
mini_portile2 (2.8.0)
|
41
|
+
minitest (5.15.0)
|
42
|
+
nokogiri (1.13.3)
|
43
|
+
mini_portile2 (~> 2.8.0)
|
45
44
|
racc (~> 1.4)
|
46
|
-
parallel (1.
|
47
|
-
parser (3.
|
45
|
+
parallel (1.22.1)
|
46
|
+
parser (3.1.1.0)
|
48
47
|
ast (~> 2.4.1)
|
49
48
|
pry (0.14.1)
|
50
49
|
coderay (~> 1.1)
|
51
50
|
method_source (~> 1.0)
|
52
|
-
racc (1.
|
51
|
+
racc (1.6.0)
|
53
52
|
rack (2.2.3)
|
54
53
|
rack-test (1.1.0)
|
55
54
|
rack (>= 1.0, < 3)
|
56
55
|
rails-dom-testing (2.0.3)
|
57
56
|
activesupport (>= 4.2.0)
|
58
57
|
nokogiri (>= 1.6)
|
59
|
-
rails-html-sanitizer (1.
|
58
|
+
rails-html-sanitizer (1.4.2)
|
60
59
|
loofah (~> 2.3)
|
61
|
-
railties (
|
62
|
-
actionpack (=
|
63
|
-
activesupport (=
|
60
|
+
railties (7.0.2.3)
|
61
|
+
actionpack (= 7.0.2.3)
|
62
|
+
activesupport (= 7.0.2.3)
|
64
63
|
method_source
|
65
|
-
rake (>=
|
64
|
+
rake (>= 12.2)
|
66
65
|
thor (~> 1.0)
|
67
|
-
|
68
|
-
|
69
|
-
|
66
|
+
zeitwerk (~> 2.5)
|
67
|
+
rainbow (3.1.1)
|
68
|
+
rake (13.0.6)
|
69
|
+
regexp_parser (2.3.0)
|
70
70
|
rexml (3.2.5)
|
71
|
-
rubocop (1.
|
71
|
+
rubocop (1.26.1)
|
72
72
|
parallel (~> 1.10)
|
73
|
-
parser (>= 3.
|
73
|
+
parser (>= 3.1.0.0)
|
74
74
|
rainbow (>= 2.2.2, < 4.0)
|
75
75
|
regexp_parser (>= 1.8, < 3.0)
|
76
76
|
rexml
|
77
|
-
rubocop-ast (>= 1.
|
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.
|
81
|
-
parser (>=
|
82
|
-
rubocop-performance (1.
|
83
|
-
rubocop (>=
|
80
|
+
rubocop-ast (1.17.0)
|
81
|
+
parser (>= 3.1.1.0)
|
82
|
+
rubocop-performance (1.13.3)
|
83
|
+
rubocop (>= 1.7.0, < 2.0)
|
84
84
|
rubocop-ast (>= 0.4.0)
|
85
85
|
ruby-progressbar (1.11.0)
|
86
|
-
standard (1.
|
87
|
-
rubocop (= 1.
|
88
|
-
rubocop-performance (= 1.
|
89
|
-
thor (1.1
|
86
|
+
standard (1.9.1)
|
87
|
+
rubocop (= 1.26.1)
|
88
|
+
rubocop-performance (= 1.13.3)
|
89
|
+
thor (1.2.1)
|
90
90
|
tzinfo (2.0.4)
|
91
91
|
concurrent-ruby (~> 1.0)
|
92
|
-
unicode-display_width (2.
|
93
|
-
zeitwerk (2.4
|
92
|
+
unicode-display_width (2.1.0)
|
93
|
+
zeitwerk (2.5.4)
|
94
94
|
|
95
95
|
PLATFORMS
|
96
96
|
ruby
|
@@ -103,4 +103,4 @@ DEPENDENCIES
|
|
103
103
|
test_data!
|
104
104
|
|
105
105
|
BUNDLED WITH
|
106
|
-
2.
|
106
|
+
2.3.10
|
data/LICENSE.txt
CHANGED
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)
|
@@ -61,6 +61,7 @@ we have reckoned with to this point.
|
|
61
61
|
* [test_data:configure](#test_dataconfigure)
|
62
62
|
* [test_data:verify_config](#test_dataverify_config)
|
63
63
|
* [test_data:initialize](#test_datainitialize)
|
64
|
+
* [test_data:reinitialize](#test_datareinitialize)
|
64
65
|
* [test_data:dump](#test_datadump)
|
65
66
|
* [test_data:load](#test_dataload)
|
66
67
|
* [test_data:create_database](#test_datacreate_database)
|
@@ -105,22 +106,42 @@ And if you get stuck or need help as you're getting started, please feel free to
|
|
105
106
|
|
106
107
|
### Step 1: Install and initialize `test_data`
|
107
108
|
|
108
|
-
#### 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.
|
116
|
+
|
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.
|
109
121
|
|
110
|
-
|
111
|
-
it to the `:development`, `:test`, and (the all new!) `:test_data` gem groups:
|
122
|
+
For example, this:
|
112
123
|
|
113
124
|
```ruby
|
114
|
-
group :development, :test
|
125
|
+
group :development, :test do
|
126
|
+
gem "standard"
|
127
|
+
gem "cypress-rails"
|
115
128
|
gem "test_data"
|
116
|
-
# … other gems available to development & test
|
117
129
|
end
|
118
130
|
```
|
119
131
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
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
|
+
```
|
124
145
|
|
125
146
|
#### Configuring the gem and initializing the database
|
126
147
|
|
@@ -430,23 +451,21 @@ to update your test data. Here's how to do it:
|
|
430
451
|
1. Be sure there's nothing in your local `test_data` database that you added
|
431
452
|
intentionally and forgot to dump, because it's about to be erased
|
432
453
|
|
433
|
-
2. Run `rake test_data:
|
434
|
-
|
435
|
-
3. Run `rake test_data:load` to recreate the `test_data` database and load
|
436
|
-
the latest SQL dumps into it
|
454
|
+
2. Run `rake test_data:reinitialize` drop and recreate the `test_data`
|
455
|
+
database and load the latest SQL dumps into it
|
437
456
|
|
438
|
-
|
457
|
+
3. Run any pending migrations with `RAILS_ENV=test_data bin/rake db:migrate`
|
439
458
|
|
440
|
-
|
459
|
+
4. If you need to create any additional data, start up the server
|
441
460
|
(`RAILS_ENV=test_data bin/rails s`), just like in [Step
|
442
461
|
2](#step-2-create-some-test-data)
|
443
462
|
|
444
|
-
|
463
|
+
5. Export your newly-updated `test_data` database with `rake test_data:dump`
|
445
464
|
|
446
|
-
|
465
|
+
6. Ensure your tests are passing and then commit the resulting SQL files
|
447
466
|
|
448
467
|
* If the local `test_data` database is already up-to-date with the current SQL
|
449
|
-
dumps, follow steps **
|
468
|
+
dumps, follow steps **3 through 6** above
|
450
469
|
|
451
470
|
It's important to keep in mind that your test data SQL dumps are a shared,
|
452
471
|
generated resource among your team (just like a `structure.sql` or `schema.rb`
|
@@ -664,6 +683,18 @@ your seed file. Specifically:
|
|
664
683
|
* Otherwise, it invokes the task `db:schema:load` and `db:seed` (similar to
|
665
684
|
Rails' built-in `db:setup` task)
|
666
685
|
|
686
|
+
### test_data:reinitialize
|
687
|
+
|
688
|
+
This task is designed for the situation where you may already have a `test_data`
|
689
|
+
database created and simply want to drop it and replace it with whatever dumps
|
690
|
+
are in the `test/support/test_data` directory.
|
691
|
+
|
692
|
+
Dropping the database requires confirmation, either interactively or by setting
|
693
|
+
the environment variable `TEST_DATA_CONFIRM`. It will additionally warn you in
|
694
|
+
the event that the local database appears to be newer than the dumps on disk
|
695
|
+
that would replace it. From there, this task behaves the same way as `rake
|
696
|
+
test_data:initialize`.
|
697
|
+
|
667
698
|
### test_data:dump
|
668
699
|
|
669
700
|
This task is designed to be run after you've created or updated your test data
|
@@ -775,8 +806,8 @@ There are two additional things to keep in mind if using this method:
|
|
775
806
|
|
776
807
|
1. Using this feature requires that you've first invoked
|
777
808
|
[TestData.prevent_rails_fixtures_from_loading_automatically!](#testdataprevent_rails_fixtures_from_loading_automatically)
|
778
|
-
to override Rails' default behavior
|
779
|
-
started running
|
809
|
+
before your tests have started running to override Rails' default behavior
|
810
|
+
before any of your tests have loaded or started running
|
780
811
|
|
781
812
|
2. Because the method depends on Rails' fixture caching mechanism, it must be
|
782
813
|
passed an instance of the running test class (e.g.
|
@@ -1227,20 +1258,9 @@ result in a significantly slower overall test suite. Instead, if you group tests
|
|
1227
1258
|
that use the same type of test data together (e.g. by separating them into
|
1228
1259
|
separate suites), you might find profound speed gains.
|
1229
1260
|
|
1230
|
-
To illustrate
|
1231
|
-
and 5 that
|
1232
|
-
|
1233
|
-
the only operation needed by the second call will be a rollback to the savepoint
|
1234
|
-
taken after the test data was loaded. If, however, a `uses_test_data` test is
|
1235
|
-
followed by a `uses_rails_fixtures` test, then a lot more work is required:
|
1236
|
-
first a rollback, then the truncation of the test data, then a load of the
|
1237
|
-
fixtures followed by creation of a new savepoint—which would in tunr be undone
|
1238
|
-
again if the _next_ test happened to call `uses_test_data`. Switching between
|
1239
|
-
tests that use different sources of test data can cause significant unnecessary
|
1240
|
-
thrashing.
|
1241
|
-
|
1242
|
-
To illustrate the above, if all of these tests ran in random order (the
|
1243
|
-
default), you might see:
|
1261
|
+
To illustrate this, suppose you had 5 tests that relied on your `test_data` data
|
1262
|
+
and 5 that relied on Rails fixtures. If all of these tests ran in random order
|
1263
|
+
(the default), you might see the following behavior at run-time:
|
1244
1264
|
|
1245
1265
|
```
|
1246
1266
|
$ bin/rails test test/example_test.rb
|
@@ -1272,9 +1292,11 @@ data into sub-suites that are run serially, on e after the other.
|
|
1272
1292
|
[minitest-suite](https://github.com/testdouble/minitest-suite) to accomplish
|
1273
1293
|
exactly this. Just declare something like `suite :test_data` or `suite
|
1274
1294
|
:fixtures` at the top of each test class
|
1275
|
-
* If you're using RSpec, the
|
1276
|
-
|
1277
|
-
|
1295
|
+
* If you're using RSpec, the [suite option combined with a custom
|
1296
|
+
ordering](https://gist.github.com/myronmarston/8fea012b9eb21b637335bb29069bce6b)
|
1297
|
+
can accomplish this. You might also consider using
|
1298
|
+
[tags](https://relishapp.com/rspec/rspec-core/v/3-10/docs/command-line/tag-option)
|
1299
|
+
to organize your tests by type, but you'll likely have to
|
1278
1300
|
run a separate CLI invocation for each to avoid the tests from being
|
1279
1301
|
interleaved
|
1280
1302
|
|