test_data 0.0.1 → 0.2.1

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.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +41 -0
  3. data/.standard.yml +2 -0
  4. data/CHANGELOG.md +43 -0
  5. data/Gemfile.lock +17 -15
  6. data/LICENSE.txt +1 -6
  7. data/README.md +1232 -17
  8. data/example/.gitignore +1 -4
  9. data/example/Gemfile +3 -0
  10. data/example/Gemfile.lock +100 -71
  11. data/example/README.md +2 -22
  12. data/example/config/application.rb +3 -0
  13. data/example/config/credentials.yml.enc +1 -1
  14. data/example/config/database.yml +2 -0
  15. data/example/spec/rails_helper.rb +64 -0
  16. data/example/spec/requests/boops_spec.rb +17 -0
  17. data/example/spec/requests/rails_fixtures_override_spec.rb +106 -0
  18. data/example/spec/spec_helper.rb +94 -0
  19. data/example/test/factories.rb +4 -0
  20. data/example/test/integration/better_mode_switching_demo_test.rb +41 -0
  21. data/example/test/integration/boops_that_boop_boops_test.rb +17 -0
  22. data/example/test/integration/dont_dump_tables_test.rb +7 -0
  23. data/example/test/integration/load_rollback_truncate_test.rb +190 -0
  24. data/example/test/integration/mode_switching_demo_test.rb +38 -0
  25. data/example/test/integration/parallel_boops_with_fixtures_test.rb +10 -0
  26. data/example/test/integration/parallel_boops_without_fixtures_test.rb +9 -0
  27. data/example/test/integration/rails_fixtures_double_load_test.rb +10 -0
  28. data/example/test/integration/rails_fixtures_override_test.rb +110 -0
  29. data/example/test/integration/test_data_hooks_test.rb +89 -0
  30. data/example/test/integration/transaction_committing_boops_test.rb +27 -0
  31. data/example/test/test_helper.rb +4 -31
  32. data/lib/generators/test_data/cable_yaml_generator.rb +18 -0
  33. data/lib/generators/test_data/database_yaml_generator.rb +3 -4
  34. data/lib/generators/test_data/environment_file_generator.rb +7 -14
  35. data/lib/generators/test_data/initializer_generator.rb +51 -0
  36. data/lib/generators/test_data/secrets_yaml_generator.rb +19 -0
  37. data/lib/generators/test_data/webpacker_yaml_generator.rb +4 -3
  38. data/lib/test_data.rb +42 -1
  39. data/lib/test_data/active_record_ext.rb +11 -0
  40. data/lib/test_data/config.rb +57 -4
  41. data/lib/test_data/configurators.rb +3 -0
  42. data/lib/test_data/configurators/cable_yaml.rb +25 -0
  43. data/lib/test_data/configurators/environment_file.rb +3 -2
  44. data/lib/test_data/configurators/initializer.rb +26 -0
  45. data/lib/test_data/configurators/secrets_yaml.rb +25 -0
  46. data/lib/test_data/configurators/webpacker_yaml.rb +4 -3
  47. data/lib/test_data/custom_loaders/abstract_base.rb +25 -0
  48. data/lib/test_data/custom_loaders/rails_fixtures.rb +42 -0
  49. data/lib/test_data/dumps_database.rb +55 -5
  50. data/lib/test_data/generator_support.rb +3 -0
  51. data/lib/test_data/inserts_test_data.rb +25 -0
  52. data/lib/test_data/loads_database_dumps.rb +8 -8
  53. data/lib/test_data/log.rb +76 -0
  54. data/lib/test_data/manager.rb +187 -0
  55. data/lib/test_data/rake.rb +20 -9
  56. data/lib/test_data/save_point.rb +34 -0
  57. data/lib/test_data/statistics.rb +31 -0
  58. data/lib/test_data/truncates_test_data.rb +31 -0
  59. data/lib/test_data/verifies_dumps_are_loadable.rb +4 -4
  60. data/lib/test_data/version.rb +1 -1
  61. data/script/reset_example_app +18 -0
  62. data/script/test +78 -13
  63. data/test_data.gemspec +1 -1
  64. metadata +36 -4
  65. data/lib/test_data/transactional_data_loader.rb +0 -77
data/example/.gitignore CHANGED
@@ -18,7 +18,4 @@
18
18
  # Ignore master key for decrypting credentials and more.
19
19
  /config/master.key
20
20
 
21
- # Ignore files that are intentionally generated / asserted by the tests
22
- /config/environments/test_data.rb
23
- /test/support/test_data
24
- /db/migrate/20210418220133_add_beep_to_boops.rb
21
+
data/example/Gemfile CHANGED
@@ -10,6 +10,9 @@ group :development, :test, :test_data do
10
10
  gem "test_data", path: ".."
11
11
  gem "standard"
12
12
  gem "pry-rails"
13
+ gem "factory_bot_rails", require: false
14
+ gem "noncommittal"
15
+ gem "rspec-rails"
13
16
  end
14
17
 
15
18
  group :test do
data/example/Gemfile.lock CHANGED
@@ -1,66 +1,66 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- test_data (0.0.1)
4
+ test_data (0.2.1)
5
5
  railties (~> 6.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- actioncable (6.1.3.1)
11
- actionpack (= 6.1.3.1)
12
- activesupport (= 6.1.3.1)
10
+ actioncable (6.1.3.2)
11
+ actionpack (= 6.1.3.2)
12
+ activesupport (= 6.1.3.2)
13
13
  nio4r (~> 2.0)
14
14
  websocket-driver (>= 0.6.1)
15
- actionmailbox (6.1.3.1)
16
- actionpack (= 6.1.3.1)
17
- activejob (= 6.1.3.1)
18
- activerecord (= 6.1.3.1)
19
- activestorage (= 6.1.3.1)
20
- activesupport (= 6.1.3.1)
15
+ actionmailbox (6.1.3.2)
16
+ actionpack (= 6.1.3.2)
17
+ activejob (= 6.1.3.2)
18
+ activerecord (= 6.1.3.2)
19
+ activestorage (= 6.1.3.2)
20
+ activesupport (= 6.1.3.2)
21
21
  mail (>= 2.7.1)
22
- actionmailer (6.1.3.1)
23
- actionpack (= 6.1.3.1)
24
- actionview (= 6.1.3.1)
25
- activejob (= 6.1.3.1)
26
- activesupport (= 6.1.3.1)
22
+ actionmailer (6.1.3.2)
23
+ actionpack (= 6.1.3.2)
24
+ actionview (= 6.1.3.2)
25
+ activejob (= 6.1.3.2)
26
+ activesupport (= 6.1.3.2)
27
27
  mail (~> 2.5, >= 2.5.4)
28
28
  rails-dom-testing (~> 2.0)
29
- actionpack (6.1.3.1)
30
- actionview (= 6.1.3.1)
31
- activesupport (= 6.1.3.1)
29
+ actionpack (6.1.3.2)
30
+ actionview (= 6.1.3.2)
31
+ activesupport (= 6.1.3.2)
32
32
  rack (~> 2.0, >= 2.0.9)
33
33
  rack-test (>= 0.6.3)
34
34
  rails-dom-testing (~> 2.0)
35
35
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
36
- actiontext (6.1.3.1)
37
- actionpack (= 6.1.3.1)
38
- activerecord (= 6.1.3.1)
39
- activestorage (= 6.1.3.1)
40
- activesupport (= 6.1.3.1)
36
+ actiontext (6.1.3.2)
37
+ actionpack (= 6.1.3.2)
38
+ activerecord (= 6.1.3.2)
39
+ activestorage (= 6.1.3.2)
40
+ activesupport (= 6.1.3.2)
41
41
  nokogiri (>= 1.8.5)
42
- actionview (6.1.3.1)
43
- activesupport (= 6.1.3.1)
42
+ actionview (6.1.3.2)
43
+ activesupport (= 6.1.3.2)
44
44
  builder (~> 3.1)
45
45
  erubi (~> 1.4)
46
46
  rails-dom-testing (~> 2.0)
47
47
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
48
- activejob (6.1.3.1)
49
- activesupport (= 6.1.3.1)
48
+ activejob (6.1.3.2)
49
+ activesupport (= 6.1.3.2)
50
50
  globalid (>= 0.3.6)
51
- activemodel (6.1.3.1)
52
- activesupport (= 6.1.3.1)
53
- activerecord (6.1.3.1)
54
- activemodel (= 6.1.3.1)
55
- activesupport (= 6.1.3.1)
56
- activestorage (6.1.3.1)
57
- actionpack (= 6.1.3.1)
58
- activejob (= 6.1.3.1)
59
- activerecord (= 6.1.3.1)
60
- activesupport (= 6.1.3.1)
51
+ activemodel (6.1.3.2)
52
+ activesupport (= 6.1.3.2)
53
+ activerecord (6.1.3.2)
54
+ activemodel (= 6.1.3.2)
55
+ activesupport (= 6.1.3.2)
56
+ activestorage (6.1.3.2)
57
+ actionpack (= 6.1.3.2)
58
+ activejob (= 6.1.3.2)
59
+ activerecord (= 6.1.3.2)
60
+ activesupport (= 6.1.3.2)
61
61
  marcel (~> 1.0.0)
62
62
  mini_mime (~> 1.0.2)
63
- activesupport (6.1.3.1)
63
+ activesupport (6.1.3.2)
64
64
  concurrent-ruby (~> 1.0, >= 1.0.2)
65
65
  i18n (>= 1.6, < 2)
66
66
  minitest (>= 5.1)
@@ -69,7 +69,7 @@ GEM
69
69
  addressable (2.7.0)
70
70
  public_suffix (>= 2.0.2, < 5.0)
71
71
  ast (2.4.2)
72
- bootsnap (1.7.3)
72
+ bootsnap (1.7.5)
73
73
  msgpack (~> 1.0)
74
74
  builder (3.2.4)
75
75
  capybara (3.35.3)
@@ -82,14 +82,20 @@ GEM
82
82
  xpath (~> 3.2)
83
83
  childprocess (3.0.0)
84
84
  coderay (1.1.3)
85
- concurrent-ruby (1.1.8)
85
+ concurrent-ruby (1.1.9)
86
86
  crass (1.0.6)
87
+ diff-lcs (1.4.4)
87
88
  erubi (1.10.0)
89
+ factory_bot (6.2.0)
90
+ activesupport (>= 5.0.0)
91
+ factory_bot_rails (6.2.0)
92
+ factory_bot (~> 6.2.0)
93
+ railties (>= 5.0.0)
88
94
  globalid (0.4.2)
89
95
  activesupport (>= 4.2.0)
90
96
  i18n (1.8.10)
91
97
  concurrent-ruby (~> 1.0)
92
- loofah (2.9.1)
98
+ loofah (2.10.0)
93
99
  crass (~> 1.0.2)
94
100
  nokogiri (>= 1.5.9)
95
101
  mail (2.7.1)
@@ -97,13 +103,16 @@ GEM
97
103
  marcel (1.0.1)
98
104
  method_source (1.0.0)
99
105
  mini_mime (1.0.3)
106
+ mini_portile2 (2.5.3)
100
107
  minitest (5.14.4)
101
108
  msgpack (1.4.2)
102
109
  nio4r (2.5.7)
103
- nokogiri (1.11.3-arm64-darwin)
110
+ nokogiri (1.11.7)
111
+ mini_portile2 (~> 2.5.0)
104
112
  racc (~> 1.4)
113
+ noncommittal (0.2.0)
105
114
  parallel (1.20.1)
106
- parser (3.0.1.0)
115
+ parser (3.0.1.1)
107
116
  ast (~> 2.4.1)
108
117
  pg (1.2.3)
109
118
  pry (0.14.1)
@@ -112,35 +121,35 @@ GEM
112
121
  pry-rails (0.3.9)
113
122
  pry (>= 0.10.4)
114
123
  public_suffix (4.0.6)
115
- puma (5.2.2)
124
+ puma (5.3.2)
116
125
  nio4r (~> 2.0)
117
126
  racc (1.5.2)
118
127
  rack (2.2.3)
119
128
  rack-test (1.1.0)
120
129
  rack (>= 1.0, < 3)
121
- rails (6.1.3.1)
122
- actioncable (= 6.1.3.1)
123
- actionmailbox (= 6.1.3.1)
124
- actionmailer (= 6.1.3.1)
125
- actionpack (= 6.1.3.1)
126
- actiontext (= 6.1.3.1)
127
- actionview (= 6.1.3.1)
128
- activejob (= 6.1.3.1)
129
- activemodel (= 6.1.3.1)
130
- activerecord (= 6.1.3.1)
131
- activestorage (= 6.1.3.1)
132
- activesupport (= 6.1.3.1)
130
+ rails (6.1.3.2)
131
+ actioncable (= 6.1.3.2)
132
+ actionmailbox (= 6.1.3.2)
133
+ actionmailer (= 6.1.3.2)
134
+ actionpack (= 6.1.3.2)
135
+ actiontext (= 6.1.3.2)
136
+ actionview (= 6.1.3.2)
137
+ activejob (= 6.1.3.2)
138
+ activemodel (= 6.1.3.2)
139
+ activerecord (= 6.1.3.2)
140
+ activestorage (= 6.1.3.2)
141
+ activesupport (= 6.1.3.2)
133
142
  bundler (>= 1.15.0)
134
- railties (= 6.1.3.1)
143
+ railties (= 6.1.3.2)
135
144
  sprockets-rails (>= 2.0.0)
136
145
  rails-dom-testing (2.0.3)
137
146
  activesupport (>= 4.2.0)
138
147
  nokogiri (>= 1.6)
139
148
  rails-html-sanitizer (1.3.0)
140
149
  loofah (~> 2.3)
141
- railties (6.1.3.1)
142
- actionpack (= 6.1.3.1)
143
- activesupport (= 6.1.3.1)
150
+ railties (6.1.3.2)
151
+ actionpack (= 6.1.3.2)
152
+ activesupport (= 6.1.3.2)
144
153
  method_source
145
154
  rake (>= 0.8.7)
146
155
  thor (~> 1.0)
@@ -148,19 +157,36 @@ GEM
148
157
  rake (13.0.3)
149
158
  regexp_parser (2.1.1)
150
159
  rexml (3.2.5)
151
- rubocop (1.12.1)
160
+ rspec-core (3.10.1)
161
+ rspec-support (~> 3.10.0)
162
+ rspec-expectations (3.10.1)
163
+ diff-lcs (>= 1.2.0, < 2.0)
164
+ rspec-support (~> 3.10.0)
165
+ rspec-mocks (3.10.2)
166
+ diff-lcs (>= 1.2.0, < 2.0)
167
+ rspec-support (~> 3.10.0)
168
+ rspec-rails (5.0.1)
169
+ actionpack (>= 5.2)
170
+ activesupport (>= 5.2)
171
+ railties (>= 5.2)
172
+ rspec-core (~> 3.10)
173
+ rspec-expectations (~> 3.10)
174
+ rspec-mocks (~> 3.10)
175
+ rspec-support (~> 3.10)
176
+ rspec-support (3.10.2)
177
+ rubocop (1.14.0)
152
178
  parallel (~> 1.10)
153
179
  parser (>= 3.0.0.0)
154
180
  rainbow (>= 2.2.2, < 4.0)
155
181
  regexp_parser (>= 1.8, < 3.0)
156
182
  rexml
157
- rubocop-ast (>= 1.2.0, < 2.0)
183
+ rubocop-ast (>= 1.5.0, < 2.0)
158
184
  ruby-progressbar (~> 1.7)
159
185
  unicode-display_width (>= 1.4.0, < 3.0)
160
- rubocop-ast (1.4.1)
161
- parser (>= 2.7.1.5)
162
- rubocop-performance (1.10.1)
163
- rubocop (>= 0.90.0, < 2.0)
186
+ rubocop-ast (1.7.0)
187
+ parser (>= 3.0.1.1)
188
+ rubocop-performance (1.11.2)
189
+ rubocop (>= 1.7.0, < 2.0)
164
190
  rubocop-ast (>= 0.4.0)
165
191
  ruby-progressbar (1.11.0)
166
192
  rubyzip (2.3.0)
@@ -174,9 +200,9 @@ GEM
174
200
  actionpack (>= 4.0)
175
201
  activesupport (>= 4.0)
176
202
  sprockets (>= 3.0.0)
177
- standard (1.0.5)
178
- rubocop (= 1.12.1)
179
- rubocop-performance (= 1.10.1)
203
+ standard (1.1.1)
204
+ rubocop (= 1.14.0)
205
+ rubocop-performance (= 1.11.2)
180
206
  thor (1.1.0)
181
207
  tzinfo (2.0.4)
182
208
  concurrent-ruby (~> 1.0)
@@ -185,7 +211,7 @@ GEM
185
211
  nokogiri (~> 1.6)
186
212
  rubyzip (>= 1.3.0)
187
213
  selenium-webdriver (>= 3.0, < 4.0)
188
- websocket-driver (0.7.3)
214
+ websocket-driver (0.7.5)
189
215
  websocket-extensions (>= 0.1.0)
190
216
  websocket-extensions (0.1.5)
191
217
  xpath (3.2.0)
@@ -193,15 +219,18 @@ GEM
193
219
  zeitwerk (2.4.2)
194
220
 
195
221
  PLATFORMS
196
- arm64-darwin-20
222
+ ruby
197
223
 
198
224
  DEPENDENCIES
199
225
  bootsnap
200
226
  capybara (>= 3.26)
227
+ factory_bot_rails
228
+ noncommittal
201
229
  pg
202
230
  pry-rails
203
231
  puma
204
232
  rails
233
+ rspec-rails
205
234
  selenium-webdriver
206
235
  standard
207
236
  test_data!
data/example/README.md CHANGED
@@ -1,24 +1,4 @@
1
1
  # README
2
2
 
3
- This README would normally document whatever steps are necessary to get the
4
- application up and running.
5
-
6
- Things you may want to cover:
7
-
8
- * Ruby version
9
-
10
- * System dependencies
11
-
12
- * Configuration
13
-
14
- * Database creation
15
-
16
- * Database initialization
17
-
18
- * How to run the test suite
19
-
20
- * Services (job queues, cache servers, search engines, etc.)
21
-
22
- * Deployment instructions
23
-
24
- * ...
3
+ This is an example app used by [script/test](/script/test) to exercise the
4
+ `test_data` gem
@@ -24,6 +24,9 @@ module Example
24
24
  # Initialize configuration defaults for originally generated Rails version.
25
25
  config.load_defaults 6.1
26
26
 
27
+ # Uncomment this to switch from schema.rb to structure.sql
28
+ # config.active_record.schema_format = :sql
29
+
27
30
  # Configuration for the application, engines, and railties goes here.
28
31
  #
29
32
  # These settings can be overridden in specific environments using the files
@@ -1 +1 @@
1
- F/lkjSeOZwy+4IAYNV/+5sOwn9XOGjyNNvDkNyrpRG0kqoP8jmI4GE8mb73fdRIVoI9H7zefa3GxQ7R+udxqKWMLwAtSgTt+YGf5Eng0IzRBPp7hY2gIxFO0b84/+eG4Q6rD5xsg0kogzK3Ab4jj7f8Ci8vzFclSwqyUwP6TBCnaZJYsLMcNmF3tKBnWrJNKcQJ6Rj6/J2OH/nNi5x+KbsIgbARCJsZEK8PjD+cx8Qs9Cvk99Pj3VljLmjYA0L3jx1uCKahr0tzkkPkujBCKci05QHF/+vq0fcFduxc5wwlf5qMf7wGayz8i1YONyM9yORMrcnvSz/6AKC25np24+nmvZNsuVqtyoA4LRL+k3RBCMKo867FkwJmmGkhZSAFplFdQ2C0qJ+Gzem6UD6Lr70klDaUq1hITDqIc--nPRVkeqxjYlJDoKQ--Iu4hCDiJSpYuKL56Z/CUjA==
1
+ 5AstMrUHKXO5ed+i/hI/GnVm5IB525qXJOqPHvqfqhJSxEJSyfwKfQURigix3HsTcOwcPFIU6vPSC20bi5H8CQ7SHnYdHJuGB2T3WC9iiNiSBz49HaZoYX8ucHYoMMBbC+0u/6diYLW8ZTKR2Ab7bn4r1lkGzQjJe5clic5wNto7btjAbStXyAOHZCStXfnOFgQQhVjZno3iS7c279jaVYkYpZ12P5LbMxcJO4ipWfFexCzysIQu/WSPfmNMcvrIPijmPBvkVMJuhhDzd0yk1ysJu8jJMa8FJKx9aVd7Bes/k8Nywd04GDY6eSxyH6gkoG+BeQeqW3ig1XsuOWvx39qE9EQAcsgT13uxGc8M4wBKqIdSoibPl/79kTB843rnGlL8X/pKipJYczYJxazLSojwcQSto1UeIqQFWaDPQhz0--C7YAj7j4YQdWGiMG--JFTyHZbGKXiCdfZoBmF3xw==
@@ -20,6 +20,8 @@ default: &default
20
20
  # For details on connection pooling, see Rails configuration guide
21
21
  # https://guides.rubyonrails.org/configuring.html#database-pooling
22
22
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
23
+ host: <%= ENV.fetch("PGHOST") { "localhost" } %>
24
+ port: <%= ENV.fetch("PGPORT") { "5432" } %>
23
25
 
24
26
  development:
25
27
  <<: *default
@@ -0,0 +1,64 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ require "spec_helper"
3
+ ENV["RAILS_ENV"] ||= "test"
4
+ require File.expand_path("../config/environment", __dir__)
5
+ # Prevent database truncation if the environment is production
6
+ abort("The Rails environment is running in production mode!") if Rails.env.production?
7
+ require "rspec/rails"
8
+ # Add additional requires below this line. Rails is not loaded until this point!
9
+
10
+ # Requires supporting ruby files with custom matchers and macros, etc, in
11
+ # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
12
+ # run as spec files by default. This means that files in spec/support that end
13
+ # in _spec.rb will both be required and run as specs, causing the specs to be
14
+ # run twice. It is recommended that you do not name files matching this glob to
15
+ # end with _spec.rb. You can configure this pattern with the --pattern
16
+ # option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
17
+ #
18
+ # The following line is provided for convenience purposes. It has the downside
19
+ # of increasing the boot-up time by auto-requiring all files in the support
20
+ # directory. Alternatively, in the individual `*_spec.rb` files, manually
21
+ # require only the support files necessary.
22
+ #
23
+ # Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each { |f| require f }
24
+
25
+ # Checks for pending migrations and applies them before tests are run.
26
+ # If you are not using ActiveRecord, you can remove these lines.
27
+ begin
28
+ ActiveRecord::Migration.maintain_test_schema!
29
+ rescue ActiveRecord::PendingMigrationError => e
30
+ puts e.to_s.strip
31
+ exit 1
32
+ end
33
+ RSpec.configure do |config|
34
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
35
+ config.fixture_path = "#{::Rails.root}/test/fixtures"
36
+
37
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
38
+ # examples within a transaction, remove the following line or assign false
39
+ # instead of true.
40
+ config.use_transactional_fixtures = true
41
+
42
+ # You can uncomment this line to turn off ActiveRecord support entirely.
43
+ # config.use_active_record = false
44
+
45
+ # RSpec Rails can automatically mix in different behaviours to your tests
46
+ # based on their file location, for example enabling you to call `get` and
47
+ # `post` in specs under `spec/controllers`.
48
+ #
49
+ # You can disable this behaviour by removing the line below, and instead
50
+ # explicitly tag your specs with their type, e.g.:
51
+ #
52
+ # RSpec.describe UsersController, type: :controller do
53
+ # # ...
54
+ # end
55
+ #
56
+ # The different available types are documented in the features, such as in
57
+ # https://relishapp.com/rspec/rspec-rails/docs
58
+ config.infer_spec_type_from_file_location!
59
+
60
+ # Filter lines from Rails gems in backtraces.
61
+ config.filter_rails_from_backtrace!
62
+ # arbitrary gems may also be filtered via:
63
+ # config.filter_gems_from_backtrace("gem name")
64
+ end
@@ -0,0 +1,17 @@
1
+ require "rails_helper"
2
+
3
+ RSpec.configure do |config|
4
+ config.before(:each) do
5
+ TestData.uses_test_data
6
+ end
7
+ end
8
+
9
+ RSpec.describe "Boops", type: :request do
10
+ 30.times do |i|
11
+ it "counts the boops ##{i}" do
12
+ expect(Boop.count).to eq(10)
13
+ Boop.create!
14
+ expect(Boop.count).to eq(11)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,106 @@
1
+ require "rails_helper"
2
+
3
+ TestData.prevent_rails_fixtures_from_loading_automatically!
4
+
5
+ module TestDataModes
6
+ def uses(mode)
7
+ case mode
8
+ when :clean_slate
9
+ before(:each) { TestData.uses_clean_slate }
10
+ when :test_data
11
+ before(:each) { TestData.uses_test_data }
12
+ else
13
+ raise "Invalid test data mode: #{mode}"
14
+ end
15
+ end
16
+ end
17
+
18
+ RSpec.configure do |config|
19
+ config.extend(TestDataModes)
20
+ end
21
+
22
+ RSpec.describe "FixtureFreeTestData", type: :request do
23
+ fixtures :boops
24
+
25
+ uses :test_data
26
+ it "has 15 boops in the test_data" do
27
+ expect(Boop.count).to eq(15)
28
+ end
29
+ end
30
+
31
+ RSpec.describe "Clean Slate" do
32
+ uses :clean_slate
33
+
34
+ it "has no boops" do
35
+ expect(Boop.count).to eq(0)
36
+ end
37
+ end
38
+
39
+ RSpec.describe "FixturesUsingTest", type: :request do
40
+ fixtures :boops
41
+
42
+ before(:each) do
43
+ TestData.uses_rails_fixtures(self)
44
+ end
45
+
46
+ it "has_fixture_boops" do
47
+ expect(boops(:boop_1)).to be_persisted
48
+ expect(Boop.count).to eq(2)
49
+ end
50
+
51
+ it "does_not_get_the_other_fixture_accessor" do
52
+ expect { method(:pants) }.to raise_error(NameError)
53
+ end
54
+
55
+ it "even_explicitly_loading_test_data_will_truncate_and_then_load_fixtures" do
56
+ TestData.uses_test_data
57
+ TestData.uses_rails_fixtures(self)
58
+
59
+ expect(Boop.count).to eq(2)
60
+ end
61
+
62
+ it "load_and_rollback_leaves_them_as_is" do
63
+ boop = Boop.first
64
+ original_created_on = boop.created_at.to_date
65
+ a_year_ago = 1.year.ago.to_date
66
+
67
+ boop.update!(created_at: a_year_ago)
68
+
69
+ expect(Boop.find(boop.id).created_at.to_date).to eq(a_year_ago)
70
+
71
+ # Now after rollback
72
+ TestData.uses_rails_fixtures(self)
73
+
74
+ expect(Boop.find(boop.id).created_at.to_date).to eq(original_created_on)
75
+ end
76
+ end
77
+
78
+ RSpec.describe "SomeFixturesAndSomeTestDataInOneClassTest", type: :request do
79
+ fixtures :all
80
+
81
+ it "fixtures_work" do
82
+ TestData.uses_rails_fixtures(self)
83
+
84
+ expect(boops(:boop_1).updated_at.to_date).to eq(Date.civil(2020, 1, 1))
85
+ expect(pants(:pant_1).brand).to eq("Levi")
86
+ end
87
+
88
+ it "test_that_rewinds_to_test_data" do
89
+ TestData.uses_test_data
90
+
91
+ expect(Boop.count).to eq(15)
92
+ end
93
+
94
+ it "that_rewinds_to_the_very_start" do
95
+ TestData.uninitialize
96
+
97
+ expect(Boop.count).to eq(0)
98
+ end
99
+
100
+ it "fixtures_get_reloaded_because_cache_is_cleared" do
101
+ TestData.uses_rails_fixtures(self)
102
+
103
+ expect(boops(:boop_2).updated_at.to_date).to eq(Date.civil(2019, 1, 1))
104
+ expect(pants(:pant_2).brand).to eq("Wrangler")
105
+ end
106
+ end