minitest-rails 3.0.0 → 6.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +5 -0
  3. data/LICENSE +1 -1
  4. data/README.md +117 -0
  5. data/UPDATING.md +31 -0
  6. data/lib/generators/minitest.rb +17 -4
  7. data/lib/generators/minitest/controller/controller_generator.rb +6 -9
  8. data/lib/generators/minitest/controller/templates/{controller_spec.rb → functional_spec.rb.tt} +4 -4
  9. data/lib/generators/minitest/controller/templates/{controller_test.rb → functional_test.rb.tt} +3 -3
  10. data/lib/generators/minitest/generator/generator_generator.rb +3 -8
  11. data/lib/generators/minitest/generator/templates/{generator_spec.rb → generator_spec.rb.tt} +2 -2
  12. data/lib/generators/minitest/generator/templates/{generator_test.rb → generator_test.rb.tt} +1 -2
  13. data/lib/generators/minitest/helper/helper_generator.rb +5 -3
  14. data/lib/generators/minitest/install/install_generator.rb +21 -8
  15. data/lib/generators/minitest/install/templates/test/application_system_test_case.rb.tt +10 -0
  16. data/lib/generators/minitest/install/templates/test/channels/application_cable/connection_test.rb.tt +23 -0
  17. data/lib/generators/minitest/install/templates/test/test_helper.rb.tt +23 -0
  18. data/lib/generators/minitest/integration/integration_generator.rb +12 -9
  19. data/lib/generators/minitest/integration/templates/integration_spec.rb.tt +9 -0
  20. data/lib/generators/minitest/integration/templates/integration_test.rb.tt +9 -0
  21. data/lib/generators/minitest/job/job_generator.rb +13 -10
  22. data/lib/generators/minitest/job/templates/unit_spec.rb.tt +9 -0
  23. data/lib/generators/minitest/job/templates/{job_test.rb → unit_test.rb.tt} +3 -3
  24. data/lib/generators/minitest/mailer/mailer_generator.rb +8 -11
  25. data/lib/generators/minitest/mailer/templates/functional_spec.rb.tt +21 -0
  26. data/lib/generators/minitest/mailer/templates/{mailer_test.rb → functional_test.rb.tt} +3 -3
  27. data/lib/generators/minitest/mailer/templates/{preview.rb → preview.rb.tt} +0 -0
  28. data/lib/generators/minitest/model/model_generator.rb +9 -12
  29. data/lib/generators/minitest/model/templates/{fixtures.yml → fixtures.yml.tt} +3 -3
  30. data/lib/generators/minitest/model/templates/unit_spec.rb.tt +9 -0
  31. data/lib/generators/minitest/model/templates/unit_test.rb.tt +9 -0
  32. data/lib/generators/minitest/plugin/plugin_generator.rb +15 -0
  33. data/lib/generators/minitest/plugin/templates/%file_name%_test.rb.tt +15 -0
  34. data/lib/generators/minitest/plugin/templates/test_helper.rb +2 -0
  35. data/lib/generators/minitest/scaffold/scaffold_generator.rb +28 -23
  36. data/lib/generators/minitest/scaffold/templates/api_functional_spec.rb.tt +42 -0
  37. data/lib/generators/minitest/scaffold/templates/api_functional_test.rb.tt +44 -0
  38. data/lib/generators/minitest/scaffold/templates/functional_spec.rb.tt +52 -0
  39. data/lib/generators/minitest/scaffold/templates/{controller_test.rb → functional_test.rb.tt} +16 -16
  40. data/lib/generators/minitest/scaffold/templates/system_spec.rb.tt +55 -0
  41. data/lib/generators/minitest/scaffold/templates/system_test.rb.tt +57 -0
  42. data/lib/generators/minitest/system/system_generator.rb +25 -0
  43. data/lib/generators/minitest/system/templates/application_system_test_case.rb.tt +10 -0
  44. data/lib/generators/minitest/system/templates/system_spec.rb.tt +9 -0
  45. data/lib/generators/minitest/system/templates/system_test.rb.tt +9 -0
  46. data/lib/minitest/rails.rb +76 -105
  47. data/lib/minitest/rails/assertions.rb +6 -906
  48. data/lib/minitest/rails/assertions/action_cable.rb +232 -0
  49. data/lib/minitest/rails/assertions/action_dispatch.rb +356 -0
  50. data/lib/minitest/rails/assertions/action_mailer.rb +153 -0
  51. data/lib/minitest/rails/assertions/action_view.rb +356 -0
  52. data/lib/minitest/rails/assertions/active_job.rb +151 -0
  53. data/lib/minitest/rails/assertions/active_support.rb +57 -0
  54. data/lib/minitest/rails/capybara.rb +17 -0
  55. data/lib/minitest/rails/expectations.rb +5 -565
  56. data/lib/minitest/rails/expectations/action_cable.rb +197 -0
  57. data/lib/minitest/rails/expectations/action_dispatch.rb +307 -0
  58. data/lib/minitest/rails/expectations/action_mailer.rb +175 -0
  59. data/lib/minitest/rails/expectations/active_job.rb +182 -0
  60. data/lib/minitest/rails/expectations/active_support.rb +73 -0
  61. data/lib/minitest/rails/parallelize.rb +41 -0
  62. data/lib/minitest/rails/railtie.rb +3 -2
  63. data/lib/minitest/rails/version.rb +1 -1
  64. metadata +87 -92
  65. data/.autotest +0 -23
  66. data/.gemtest +0 -0
  67. data/.travis.yml +0 -25
  68. data/CHANGELOG.rdoc +0 -223
  69. data/Gemfile +0 -7
  70. data/Manifest.txt +0 -76
  71. data/README.rdoc +0 -110
  72. data/Rakefile +0 -30
  73. data/gemfiles/5.0.gemfile +0 -5
  74. data/gemfiles/head.gemfile +0 -5
  75. data/lib/generators/.document +0 -0
  76. data/lib/generators/minitest/install/templates/test_helper.rb +0 -19
  77. data/lib/generators/minitest/integration/templates/integration_spec.rb +0 -8
  78. data/lib/generators/minitest/integration/templates/integration_test.rb +0 -7
  79. data/lib/generators/minitest/job/templates/job_spec.rb +0 -9
  80. data/lib/generators/minitest/mailer/templates/mailer_spec.rb +0 -20
  81. data/lib/generators/minitest/model/templates/model_spec.rb +0 -11
  82. data/lib/generators/minitest/model/templates/model_test.rb +0 -13
  83. data/lib/generators/minitest/scaffold/templates/api_controller_spec.rb +0 -42
  84. data/lib/generators/minitest/scaffold/templates/api_controller_test.rb +0 -44
  85. data/lib/generators/minitest/scaffold/templates/controller_spec.rb +0 -52
  86. data/lib/minitest/rails/constant_lookup.rb +0 -52
  87. data/lib/minitest/rails/controller.rb +0 -14
  88. data/minitest-rails.gemspec +0 -48
  89. data/tasks/test.rake +0 -29
  90. data/test/generators/test_controller_generator.rb +0 -58
  91. data/test/generators/test_generator_generator.rb +0 -58
  92. data/test/generators/test_helper_generator.rb +0 -34
  93. data/test/generators/test_install_generator.rb +0 -27
  94. data/test/generators/test_job_generator.rb +0 -45
  95. data/test/generators/test_mailer_generator.rb +0 -42
  96. data/test/generators/test_model_generator.rb +0 -80
  97. data/test/generators/test_scaffold_generator.rb +0 -26
  98. data/test/helper.rb +0 -93
  99. data/test/rails/action_dispatch/test_assertions.rb +0 -39
  100. data/test/rails/action_dispatch/test_expectations.rb +0 -39
  101. data/test/rails/action_dispatch/test_spec_type.rb +0 -49
  102. data/test/rails/action_mailer/test_mailers.rb +0 -109
  103. data/test/rails/action_mailer/test_spec_type.rb +0 -47
  104. data/test/rails/action_view/test_helpers.rb +0 -73
  105. data/test/rails/action_view/test_spec_type.rb +0 -58
  106. data/test/rails/active_job/test_assertions.rb +0 -46
  107. data/test/rails/active_job/test_expectations.rb +0 -55
  108. data/test/rails/active_job/test_spec_type.rb +0 -49
  109. data/test/rails/active_support/test_assertions.rb +0 -31
  110. data/test/rails/active_support/test_expectations.rb +0 -21
  111. data/test/rails/active_support/test_spec_type.rb +0 -28
  112. data/test/rails/generators/test_spec_type.rb +0 -45
  113. data/test/rails/test_constant_lookup.rb +0 -58
  114. data/test/test_sanity.rb +0 -7
@@ -0,0 +1,175 @@
1
+ require "active_support/concern"
2
+
3
+ module Minitest
4
+ module Rails
5
+ module Expectations
6
+ module ActionMailer
7
+ ##
8
+ # Asserts that the number of emails sent matches the given number.
9
+ #
10
+ # def test_emails
11
+ # must_have_emails 0
12
+ # ContactMailer.welcome.deliver_now
13
+ # must_have_emails 1
14
+ # ContactMailer.welcome.deliver_now
15
+ # must_have_emails 2
16
+ # end
17
+ #
18
+ # If a block is passed, that block should cause the specified number of
19
+ # emails to be sent.
20
+ #
21
+ # def test_emails_again
22
+ # must_have_emails 1 do
23
+ # ContactMailer.welcome.deliver_now
24
+ # end
25
+ #
26
+ # must_have_emails 2 do
27
+ # ContactMailer.welcome.deliver_now
28
+ # ContactMailer.welcome.deliver_later
29
+ # end
30
+ # end
31
+ #
32
+ # See also ActionMailer::TestClass#assert_emails
33
+ # See https://api.rubyonrails.org/v6.1/classes/ActionMailer/TestHelper.html#method-i-assert_emails
34
+ #
35
+ # :method: must_have_emails
36
+ # :call-seq: must_have_emails(number, &block)
37
+
38
+ # Asserts that no emails have been sent.
39
+ #
40
+ # def test_emails
41
+ # wont_have_emails
42
+ # ContactMailer.welcome.deliver_now
43
+ # must_have_emails 1
44
+ # end
45
+ #
46
+ # If a block is passed, that block should not cause any emails to be sent.
47
+ #
48
+ # def test_emails_again
49
+ # wont_have_emails do
50
+ # # No emails should be sent from this block
51
+ # end
52
+ # end
53
+ #
54
+ # Note: This assertion is simply a shortcut for:
55
+ #
56
+ # must_have_emails 0, &block
57
+ #
58
+ # See also ActionMailer::TestClass#wont_have_emails
59
+ # See https://api.rubyonrails.org/v6.1/classes/ActionMailer/TestHelper.html#method-i-assert_no_emails
60
+ #
61
+ # :method: wont_have_emails
62
+ # :call-seq: wont_have_emails(&block)
63
+
64
+ ##
65
+ # Asserts that the number of emails enqueued for later delivery matches
66
+ # the given number.
67
+ #
68
+ # def test_emails
69
+ # must_have_enqueued_emails 0
70
+ # ContactMailer.welcome.deliver_later
71
+ # must_have_enqueued_emails 1
72
+ # ContactMailer.welcome.deliver_later
73
+ # must_have_enqueued_emails 2
74
+ # end
75
+ #
76
+ # If a block is passed, that block should cause the specified number of
77
+ # emails to be enqueued.
78
+ #
79
+ # def test_emails_again
80
+ # must_have_enqueued_emails 1 do
81
+ # ContactMailer.welcome.deliver_later
82
+ # end
83
+ #
84
+ # must_have_enqueued_emails 2 do
85
+ # ContactMailer.welcome.deliver_later
86
+ # ContactMailer.welcome.deliver_later
87
+ # end
88
+ # end
89
+ #
90
+ # See also ActionMailer::TestClass#assert_enqueued_emails
91
+ # See https://api.rubyonrails.org/v6.1/classes/ActionMailer/TestHelper.html#method-i-assert_enqueued_emails
92
+ #
93
+ # :method: must_have_enqueued_emails
94
+ # :call-seq: must_have_enqueued_emails(number, &block)
95
+
96
+ ##
97
+ # Asserts that a specific email has been enqueued, optionally
98
+ # matching arguments.
99
+ #
100
+ # def test_email
101
+ # ContactMailer.welcome.deliver_later
102
+ # must_enqueue_email_with ContactMailer, :welcome
103
+ # end
104
+ #
105
+ # def test_email_with_arguments
106
+ # ContactMailer.welcome("Hello", "Goodbye").deliver_later
107
+ # must_enqueue_email_with ContactMailer, :welcome, args: ["Hello", "Goodbye"]
108
+ # end
109
+ #
110
+ # If a block is passed, that block should cause the specified email
111
+ # to be enqueued.
112
+ #
113
+ # def test_email_in_block
114
+ # must_enqueue_email_with ContactMailer, :welcome do
115
+ # ContactMailer.welcome.deliver_later
116
+ # end
117
+ # end
118
+ #
119
+ # If +args+ is provided as a Hash, a parameterized email is matched.
120
+ #
121
+ # def test_parameterized_email
122
+ # must_enqueue_email_with ContactMailer, :welcome,
123
+ # args: {email: 'user@example.com'} do
124
+ # ContactMailer.with(email: 'user@example.com').welcome.deliver_later
125
+ # end
126
+ # end
127
+ #
128
+ # See also ActionMailer::TestClass#assert_enqueued_email_with
129
+ # See https://api.rubyonrails.org/v6.1/classes/ActionMailer/TestHelper.html#method-i-assert_enqueued_email_with
130
+ #
131
+ # :method: must_enqueue_email_with
132
+ # :call-seq: must_enqueue_email_with(mailer, method, args: nil, queue: "mailers", &block)
133
+
134
+ ##
135
+ # Asserts that no emails are enqueued for later delivery.
136
+ #
137
+ # def test_no_emails
138
+ # wont_have_enqueued_emails
139
+ # ContactMailer.welcome.deliver_later
140
+ # wont_have_enqueued_emails 1
141
+ # end
142
+ #
143
+ # If a block is provided, it should not cause any emails to be enqueued.
144
+ #
145
+ # def test_no_emails
146
+ # wont_have_enqueued_emails do
147
+ # # No emails should be enqueued from this block
148
+ # end
149
+ # end
150
+ #
151
+ # See also ActionMailer::TestClass#assert_no_enqueued_emails
152
+ # See https://api.rubyonrails.org/v6.1/classes/ActionMailer/TestHelper.html#method-i-assert_no_enqueued_emails
153
+ #
154
+ # :method: wont_have_enqueued_emails
155
+ # :call-seq: wont_have_enqueued_emails(&block)
156
+
157
+ extend ::ActiveSupport::Concern
158
+
159
+ included do
160
+ alias_method :must_have_emails, :assert_emails
161
+ alias_method :wont_have_emails, :assert_no_emails
162
+ alias_method :must_have_enqueued_emails, :assert_enqueued_emails
163
+ alias_method :must_enqueue_email_with, :assert_enqueued_email_with
164
+ alias_method :wont_have_enqueued_emails, :assert_no_enqueued_emails
165
+ end
166
+ end
167
+ end
168
+ end
169
+ end
170
+
171
+ unless ENV["MT_NO_EXPECTATIONS"]
172
+ class ActionMailer::TestCase # :nodoc:
173
+ include Minitest::Rails::Expectations::ActionMailer
174
+ end
175
+ end
@@ -0,0 +1,182 @@
1
+ require "active_support/concern"
2
+
3
+ module Minitest
4
+ module Rails
5
+ module Expectations
6
+ # This exists as a module to allow easy mixing into classes
7
+ # other than ActiveJob::TestCase where you might want to do
8
+ # job testing e.g. in an Active Record model which triggers
9
+ # jobs in a callback.
10
+ module ActiveJob
11
+ ##
12
+ # Expects that the number of enqueued jobs matches the given number.
13
+ #
14
+ # def test_jobs
15
+ # must_enqueue_jobs 0
16
+ # HelloJob.perform_later('david')
17
+ # must_enqueue_jobs 1
18
+ # HelloJob.perform_later('abdelkader')
19
+ # must_enqueue_jobs 2
20
+ # end
21
+ #
22
+ # If a block is passed, that block should cause the specified number of
23
+ # jobs to be enqueued.
24
+ #
25
+ # def test_jobs_again
26
+ # must_enqueue_jobs 1 do
27
+ # HelloJob.perform_later('cristian')
28
+ # end
29
+ #
30
+ # must_enqueue_jobs 2 do
31
+ # HelloJob.perform_later('aaron')
32
+ # HelloJob.perform_later('rafael')
33
+ # end
34
+ # end
35
+ #
36
+ # See also ActiveJob::TestCase#assert_enqueued_jobs
37
+ #
38
+ # :method: must_enqueue_jobs
39
+ # :call-seq: must_enqueue_jobs(number)
40
+
41
+ ##
42
+ # Expects that no jobs have been enqueued.
43
+ #
44
+ # def test_jobs
45
+ # wont_enqueue_jobs
46
+ # HelloJob.perform_later('jeremy')
47
+ # must_enqueue_jobs 1
48
+ # end
49
+ #
50
+ # If a block is passed, that block should not cause any job to be enqueued.
51
+ #
52
+ # def test_jobs_again
53
+ # wont_enqueue_jobs do
54
+ # # No job should be enqueued from this block
55
+ # end
56
+ # end
57
+ #
58
+ # Note: This expectation is simply a shortcut for:
59
+ #
60
+ # must_enqueue_jobs 0, &block
61
+ #
62
+ # See also ActiveJob::TestCase#refute_enqueued_jobs
63
+ #
64
+ # :method: wont_enqueue_jobs
65
+ # :call-seq: wont_enqueue_jobs(number)
66
+
67
+ ##
68
+ # Expects that the number of performed jobs matches the given number.
69
+ # If no block is passed, <tt>perform_enqueued_jobs</tt>d
70
+ # must be called around the job call.
71
+ #
72
+ # def test_jobs
73
+ # must_perform_jobs 0
74
+ #
75
+ # perform_enqueued_jobs do
76
+ # HelloJob.perform_later('xavier')
77
+ # end
78
+ # must_perform_jobs 1
79
+ #
80
+ # perform_enqueued_jobs do
81
+ # HelloJob.perform_later('yves')
82
+ # must_perform_jobs 2
83
+ # end
84
+ # end
85
+ #
86
+ # If a block is passed, that block should cause the specified number of
87
+ # jobs to be performed.
88
+ #
89
+ # def test_jobs_again
90
+ # must_perform_jobs 1 do
91
+ # HelloJob.perform_later('robin')
92
+ # end
93
+ #
94
+ # must_perform_jobs 2 do
95
+ # HelloJob.perform_later('carlos')
96
+ # HelloJob.perform_later('sean')
97
+ # end
98
+ # end
99
+ #
100
+ # See also ActiveJob::TestCase#assert_performed_jobs
101
+ #
102
+ # :method: must_perform_jobs
103
+ # :call-seq: must_perform_jobs(number)
104
+
105
+ ##
106
+ # Expects that no jobs have been performed.
107
+ #
108
+ # def test_jobs
109
+ # wont_perform_jobs
110
+ #
111
+ # perform_enqueued_jobs do
112
+ # HelloJob.perform_later('matthew')
113
+ # must_perform_jobs 1
114
+ # end
115
+ # end
116
+ #
117
+ # If a block is passed, that block should not cause any job to be performed.
118
+ #
119
+ # def test_jobs_again
120
+ # wont_perform_jobs do
121
+ # # No job should be performed from this block
122
+ # end
123
+ # end
124
+ #
125
+ # Note: This assertion is simply a shortcut for:
126
+ #
127
+ # must_perform_jobs 0, &block
128
+ #
129
+ # See also ActiveJob::TestCase#refute_performed_jobs
130
+ #
131
+ # :method: wont_perform_jobs
132
+ # :call-seq: wont_perform_jobs(number)
133
+
134
+ ##
135
+ # Expects that the job passed in the block has been enqueued with the given arguments.
136
+ #
137
+ # def test_must_enqueue_with
138
+ # must_enqueue_with(job: MyJob, args: [1,2,3], queue: 'low') do
139
+ # MyJob.perform_later(1,2,3)
140
+ # end
141
+ # end
142
+ #
143
+ # See also Minitest::Rails::Expectations#assert_enqueued_with
144
+ #
145
+ # :method: must_enqueue_with
146
+ # :call-seq: must_enqueue_with(args)
147
+
148
+ ##
149
+ # Expects that the job passed in the block has been performed with the given arguments.
150
+ #
151
+ # def test_must_perform_with
152
+ # must_perform_with(job: MyJob, args: [1,2,3], queue: 'high') do
153
+ # MyJob.perform_later(1,2,3)
154
+ # end
155
+ # end
156
+ #
157
+ # See also Minitest::Rails::Expectations#assert_performed_with
158
+ #
159
+ # :method: must_perform_with
160
+ # :call-seq: must_perform_with(args)
161
+
162
+ extend ::ActiveSupport::Concern
163
+ include ::ActiveJob::TestHelper
164
+
165
+ included do
166
+ alias_method :must_enqueue_jobs, :assert_enqueued_jobs
167
+ alias_method :must_perform_jobs, :assert_performed_jobs
168
+ alias_method :wont_enqueue_jobs, :assert_no_enqueued_jobs
169
+ alias_method :wont_perform_jobs, :assert_no_performed_jobs
170
+ alias_method :must_enqueue_with, :assert_enqueued_with
171
+ alias_method :must_perform_with, :assert_performed_with
172
+ end
173
+ end
174
+ end
175
+ end
176
+ end
177
+
178
+ unless ENV["MT_NO_EXPECTATIONS"]
179
+ class ActiveJob::TestCase # :nodoc:
180
+ include Minitest::Rails::Expectations::ActiveJob
181
+ end
182
+ end
@@ -0,0 +1,73 @@
1
+ module Minitest
2
+ module Rails
3
+ module Expectations
4
+ module ActiveSupport
5
+ ##
6
+ # Assertion that the result of evaluating an expression is changed before and
7
+ # after invoking the passed in block.
8
+ #
9
+ # value { User.create password: "valid" }.must_change "User.count"
10
+ # value { 3.times do
11
+ # User.create password: "valid"
12
+ # end }.must_change "User.count", from: 5, to: 8
13
+ #
14
+ # See also ActiveSupport::TestCase#assert_difference
15
+ # See https://api.rubyonrails.org/v6.1/classes/ActiveSupport/Testing/Assertions.html#method-i-assert_changes
16
+ #
17
+ # :method: must_change
18
+ # :args: expression, from: UNTRACKED, to: UNTRACKED
19
+ infect_an_assertion :assert_changes, :must_change, :block
20
+
21
+ ##
22
+ # Assertion that the result of evaluating an expression is not changed before
23
+ # and after invoking the passed in block.
24
+ #
25
+ # refute_changes "Status.all_good?" do
26
+ # post :create, params: { status: { ok: true } }
27
+ # end
28
+ #
29
+ # See also ActiveSupport::TestCase#assert_difference
30
+ # See https://api.rubyonrails.org/v6.1/classes/ActiveSupport/Testing/Assertions.html#method-i-assert_no_changes
31
+ #
32
+ # :method: wont_change
33
+ # :args: expression
34
+ infect_an_assertion :refute_changes, :wont_change, :block
35
+
36
+ ##
37
+ # Test numeric difference between the return value of an expression as a
38
+ # result of what is evaluated.
39
+ #
40
+ # value { User.create password: "valid" }.must_differ "User.count"
41
+ # value { 3.times do
42
+ # User.create password: "valid"
43
+ # end }.must_differ "User.count", 3
44
+ #
45
+ # See also ActiveSupport::TestCase#assert_difference
46
+ # See https://api.rubyonrails.org/v6.1/classes/ActiveSupport/Testing/Assertions.html#method-i-assert_difference
47
+ #
48
+ # :method: must_differ
49
+ # :args: expression, *args
50
+ infect_an_assertion :assert_difference, :must_differ, :block
51
+
52
+ ##
53
+ # Assertion that the numeric result of evaluating an expression is not changed
54
+ # before and after invoking.
55
+ #
56
+ # value { User.new }.wont_differ "User.count"
57
+ #
58
+ # See also ActiveSupport::TestCase#refute_difference
59
+ # See https://api.rubyonrails.org/v6.1/classes/ActiveSupport/Testing/Assertions.html#method-i-assert_no_difference
60
+ #
61
+ # :method: wont_differ
62
+ # :args: expression
63
+ infect_an_assertion :refute_difference, :wont_differ, :block
64
+ end
65
+ end
66
+ end
67
+ end
68
+
69
+ unless ENV["MT_NO_EXPECTATIONS"]
70
+ class Object # :nodoc:
71
+ include Minitest::Rails::Expectations::ActiveSupport
72
+ end
73
+ end
@@ -0,0 +1,41 @@
1
+ require "pathname"
2
+ require "rails"
3
+
4
+ # :stopdoc:
5
+
6
+ ##
7
+ # These changes are here to support the spec DSL when using Rails parallelize.
8
+ # The issue is the spec DSL creates Class objects that are not assigned to
9
+ # a Ruby constant. When those Class objects are passed through Drb they are
10
+ # wrapped in a DrbObject and cannot be run. The solution is to assign each Class
11
+ # object to a constant. Hopefully the constant name is consistent enough that
12
+ # the constant can be passed across processes (or even machines).
13
+
14
+ module Minitest
15
+ module Rails
16
+ ##
17
+ # This module is a placeholder for all the Test classes created using the
18
+ # spec DSL. Normally all classes are created but not assigned to a constant.
19
+ # This module is where constants will be created for these classes.
20
+ module SpecTests #:nodoc:
21
+ end
22
+ end
23
+ end
24
+
25
+ module Kernel #:nodoc:
26
+ alias describe_before_minitest_spec_constant_fix describe
27
+ private :describe_before_minitest_spec_constant_fix
28
+ def describe *args, &block
29
+ cls = describe_before_minitest_spec_constant_fix(*args, &block)
30
+ cls_const = "Test__#{cls.name.to_s.split(/\W/).reject(&:empty?).join('_'.freeze)}"
31
+ if block.source_location
32
+ source_path, line_num = block.source_location
33
+ source_path = Pathname.new(File.expand_path(source_path)).relative_path_from(Rails.root).to_s
34
+ source_path = source_path.split(/\W/).reject(&:empty?).join("_".freeze)
35
+ cls_const += "__#{source_path}__#{line_num}"
36
+ end
37
+ cls_const += "_1" while Minitest::Rails::SpecTests.const_defined? cls_const
38
+ Minitest::Rails::SpecTests.const_set cls_const, cls
39
+ cls
40
+ end
41
+ end