minitest-rails 5.2.0 → 6.0.0.rc1
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 +1 -1
- data/README.md +22 -5
- data/lib/generators/minitest/install/install_generator.rb +1 -0
- data/lib/generators/minitest/install/templates/test/channels/application_cable/connection_test.rb.tt +23 -0
- data/lib/generators/minitest/install/templates/test/test_helper.rb.tt +7 -0
- data/lib/minitest/rails.rb +34 -0
- data/lib/minitest/rails/assertions.rb +1 -0
- data/lib/minitest/rails/assertions/action_cable.rb +232 -0
- data/lib/minitest/rails/assertions/action_mailer.rb +5 -5
- data/lib/minitest/rails/assertions/active_support.rb +4 -4
- data/lib/minitest/rails/capybara.rb +1 -0
- data/lib/minitest/rails/expectations.rb +1 -0
- data/lib/minitest/rails/expectations/action_cable.rb +197 -0
- data/lib/minitest/rails/expectations/action_mailer.rb +5 -5
- data/lib/minitest/rails/expectations/active_support.rb +4 -4
- data/lib/minitest/rails/parallelize.rb +41 -0
- data/lib/minitest/rails/version.rb +1 -1
- metadata +10 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a17c39422e4e1c7ccad8d53a784d0bda53d371331b3a351fbd4b5415d336f9b
|
4
|
+
data.tar.gz: 40367011c49265b5e634369a8fed095c40a2c4c93ad4cd38ca1941a489107837
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d049c84f5086d1b210e7881f4f51d165f53fc1494377bca532111a1ec239f443fccd930b1abdb8736ae20f2ccb8e5e825a35b156588c4e7d7b646385106872c8
|
7
|
+
data.tar.gz: '09a8905547e4a1325c4093fed20e68a3019ada1b8e52fa2dff6472d8facb087a8c098f876988d6e632fa0d58e029d50f592175a022a015a3acbdc8e387262528'
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# minitest-rails
|
2
2
|
|
3
|
-
Minitest integration for Rails
|
3
|
+
Minitest integration for Rails 6.0
|
4
4
|
|
5
5
|
[](http://travis-ci.org/blowmage/minitest-rails)
|
6
6
|
[](https://codeclimate.com/github/blowmage/minitest-rails)
|
@@ -19,13 +19,30 @@ Create a new rails app:
|
|
19
19
|
|
20
20
|
`rails new MyApp`
|
21
21
|
|
22
|
-
###
|
22
|
+
### Choosing a version
|
23
23
|
|
24
|
-
|
25
|
-
gem by adding the following to your Gemfile:
|
24
|
+
If you are running Rails 6.0 prerelease, set the gem using the github repo in the Gemfile:
|
26
25
|
|
27
26
|
```ruby
|
28
|
-
gem "minitest-rails",
|
27
|
+
gem "minitest-rails", github: "blowmage/minitest-rails"
|
28
|
+
```
|
29
|
+
|
30
|
+
If you are running Rails 5.x, specify a 3.x release in the Gemfile:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
gem "minitest-rails", "~> 3.0"
|
34
|
+
```
|
35
|
+
|
36
|
+
If you are running Rails 4.1 or 4.2, specify a 2.x release in the Gemfile:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
gem "minitest-rails", "~> 2.0"
|
40
|
+
```
|
41
|
+
|
42
|
+
If you are running Rails 4.0 or earlier, specify a 1.x release in the Gemfile:
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
gem "minitest-rails", "~> 1.0"
|
29
46
|
```
|
30
47
|
|
31
48
|
### Installing
|
@@ -26,6 +26,7 @@ module Minitest
|
|
26
26
|
empty_directory_with_keep_file "test/helpers"
|
27
27
|
empty_directory_with_keep_file "test/integration"
|
28
28
|
|
29
|
+
template "test/channels/application_cable/connection_test.rb"
|
29
30
|
template "test/application_system_test_case.rb"
|
30
31
|
template "test/test_helper.rb"
|
31
32
|
end
|
data/lib/generators/minitest/install/templates/test/channels/application_cable/connection_test.rb.tt
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
<%- if options[:spec] -%>
|
4
|
+
describe "ApplicationCable Connection", :connection do
|
5
|
+
# it "connects with cookies" do
|
6
|
+
# cookies.signed[:user_id] = 42
|
7
|
+
#
|
8
|
+
# connect
|
9
|
+
#
|
10
|
+
# connection.user_id.must_equal "42"
|
11
|
+
# end
|
12
|
+
end
|
13
|
+
<%- else -%>
|
14
|
+
class ApplicationCable::ConnectionTest < ActionCable::Connection::TestCase
|
15
|
+
# def test_connects_with_cookies
|
16
|
+
# cookies.signed[:user_id] = 42
|
17
|
+
#
|
18
|
+
# connect
|
19
|
+
#
|
20
|
+
# assert_equal connection.user_id, "42"
|
21
|
+
# end
|
22
|
+
end
|
23
|
+
<%- end -%>
|
@@ -7,6 +7,13 @@ require "minitest/rails"
|
|
7
7
|
# ENV["MT_NO_EXPECTATIONS"] = true
|
8
8
|
|
9
9
|
class ActiveSupport::TestCase
|
10
|
+
# Run tests in parallel with specified workers
|
11
|
+
<% if defined?(JRUBY_VERSION) || Gem.win_platform? -%>
|
12
|
+
parallelize(workers: :number_of_processors, with: :threads)
|
13
|
+
<%- else -%>
|
14
|
+
parallelize(workers: :number_of_processors)
|
15
|
+
<% end -%>
|
16
|
+
|
10
17
|
<% unless options[:skip_active_record] -%>
|
11
18
|
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
|
12
19
|
fixtures :all
|
data/lib/minitest/rails.rb
CHANGED
@@ -106,6 +106,34 @@ class Rails::Generators::TestCase
|
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
109
|
+
if defined? ActionCable
|
110
|
+
# TODO: require?
|
111
|
+
|
112
|
+
class ActionCable::Channel::TestCase
|
113
|
+
# Use AC::Ch::TC for the base class when describing a channel
|
114
|
+
register_spec_type(self) do |desc|
|
115
|
+
desc < ActionCable::Channel::Base if desc.is_a?(Class)
|
116
|
+
end
|
117
|
+
|
118
|
+
# Use AC::Ch::TC for the base class when described using :channel
|
119
|
+
register_spec_type(self) do |_desc, *addl|
|
120
|
+
addl.include? :channel
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
class ActionCable::Connection::TestCase
|
125
|
+
# Use AC::Co::TC for the base class when describing a connection
|
126
|
+
register_spec_type(self) do |desc|
|
127
|
+
desc < ActionCable::Connection::Base if desc.is_a?(Class)
|
128
|
+
end
|
129
|
+
|
130
|
+
# Use AC::Co::TC for the base class when described using :connection
|
131
|
+
register_spec_type(self) do |_desc, *addl|
|
132
|
+
addl.include? :connection
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
109
137
|
################################################################################
|
110
138
|
# Assertions and Expectations
|
111
139
|
################################################################################
|
@@ -113,6 +141,12 @@ end
|
|
113
141
|
require "minitest/rails/assertions"
|
114
142
|
require "minitest/rails/expectations"
|
115
143
|
|
144
|
+
################################################################################
|
145
|
+
# Support Rails parallelize
|
146
|
+
################################################################################
|
147
|
+
|
148
|
+
require "minitest/rails/parallelize"
|
149
|
+
|
116
150
|
# :stopdoc:
|
117
151
|
|
118
152
|
################################################################################
|
@@ -2,4 +2,5 @@ require "minitest/rails/assertions/active_support"
|
|
2
2
|
require "minitest/rails/assertions/action_view"
|
3
3
|
require "minitest/rails/assertions/action_dispatch"
|
4
4
|
require "minitest/rails/assertions/active_job" if defined? ActiveJob
|
5
|
+
require "minitest/rails/assertions/action_cable" if defined? ActionCable
|
5
6
|
require "minitest/rails/assertions/action_mailer" if defined? ActionMailer
|
@@ -0,0 +1,232 @@
|
|
1
|
+
class ActionCable::TestCase
|
2
|
+
##
|
3
|
+
# Asserts that the number of broadcasted messages to the stream matches the given number.
|
4
|
+
#
|
5
|
+
# def test_broadcasts
|
6
|
+
# assert_broadcasts 'messages', 0
|
7
|
+
# ActionCable.server.broadcast 'messages', { text: 'hello' }
|
8
|
+
# assert_broadcasts 'messages', 1
|
9
|
+
# ActionCable.server.broadcast 'messages', { text: 'world' }
|
10
|
+
# assert_broadcasts 'messages', 2
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# If a block is passed, that block should cause the specified number of
|
14
|
+
# messages to be broadcasted.
|
15
|
+
#
|
16
|
+
# def test_broadcasts_again
|
17
|
+
# assert_broadcasts('messages', 1) do
|
18
|
+
# ActionCable.server.broadcast 'messages', { text: 'hello' }
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
# assert_broadcasts('messages', 2) do
|
22
|
+
# ActionCable.server.broadcast 'messages', { text: 'hi' }
|
23
|
+
# ActionCable.server.broadcast 'messages', { text: 'how are you?' }
|
24
|
+
# end
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
# See also Minitest::Rails::Expectations::ActionCable::TestHelper#must_have_broadcasts
|
28
|
+
# See https://api.rubyonrails.org/v6.0/classes/ActionCable/TestHelper.html#method-i-assert_broadcasts
|
29
|
+
#
|
30
|
+
# :method: assert_broadcasts
|
31
|
+
# :call-seq: assert_broadcasts(stream, number)
|
32
|
+
|
33
|
+
##
|
34
|
+
# Asserts that no messages have been sent to the stream.
|
35
|
+
#
|
36
|
+
# def test_no_broadcasts
|
37
|
+
# refute_broadcasts 'messages'
|
38
|
+
# ActionCable.server.broadcast 'messages', { text: 'hi' }
|
39
|
+
# assert_broadcasts 'messages', 1
|
40
|
+
# end
|
41
|
+
#
|
42
|
+
# If a block is passed, that block should not cause any message to be sent.
|
43
|
+
#
|
44
|
+
# def test_broadcasts_again
|
45
|
+
# refute_broadcasts 'messages' do
|
46
|
+
# # No job messages should be sent from this block
|
47
|
+
# end
|
48
|
+
# end
|
49
|
+
#
|
50
|
+
# Note: This assertion is simply a shortcut for:
|
51
|
+
#
|
52
|
+
# assert_broadcasts 'messages', 0, &block
|
53
|
+
#
|
54
|
+
# See also Minitest::Rails::Expectations::ActionCable::TestHelper#wont_have_broadcasts
|
55
|
+
# See https://api.rubyonrails.org/v6.0/classes/ActionCable/TestHelper.html#method-i-assert_no_broadcasts
|
56
|
+
#
|
57
|
+
# :method: refute_broadcasts
|
58
|
+
# :call-seq: refute_broadcasts(stream, &block)
|
59
|
+
alias refute_broadcasts assert_no_broadcasts
|
60
|
+
|
61
|
+
##
|
62
|
+
# Asserts that the specified message has been sent to the stream.
|
63
|
+
#
|
64
|
+
# def test_assert_transmitted_message
|
65
|
+
# ActionCable.server.broadcast 'messages', text: 'hello'
|
66
|
+
# assert_broadcast_on('messages', text: 'hello')
|
67
|
+
# end
|
68
|
+
#
|
69
|
+
# If a block is passed, that block should cause a message with the specified data to be sent.
|
70
|
+
#
|
71
|
+
# def test_assert_broadcast_on_again
|
72
|
+
# assert_broadcast_on('messages', text: 'hello') do
|
73
|
+
# ActionCable.server.broadcast 'messages', text: 'hello'
|
74
|
+
# end
|
75
|
+
# end
|
76
|
+
#
|
77
|
+
# See also Minitest::Rails::Expectations::ActionCable::TestHelper#must_broadcast_on
|
78
|
+
# See https://api.rubyonrails.org/v6.0/classes/ActionCable/TestHelper.html#method-i-assert_broadcast_on
|
79
|
+
#
|
80
|
+
# :method: assert_broadcast_on
|
81
|
+
# :call-seq: assert_broadcast_on(stream, data)
|
82
|
+
end
|
83
|
+
|
84
|
+
class ActionCable::Channel::TestCase
|
85
|
+
##
|
86
|
+
# Asserts that the number of broadcasted messages to the stream matches the given number.
|
87
|
+
#
|
88
|
+
# def test_broadcasts
|
89
|
+
# assert_broadcasts 'messages', 0
|
90
|
+
# ActionCable.server.broadcast 'messages', { text: 'hello' }
|
91
|
+
# assert_broadcasts 'messages', 1
|
92
|
+
# ActionCable.server.broadcast 'messages', { text: 'world' }
|
93
|
+
# assert_broadcasts 'messages', 2
|
94
|
+
# end
|
95
|
+
#
|
96
|
+
# If a block is passed, that block should cause the specified number of
|
97
|
+
# messages to be broadcasted.
|
98
|
+
#
|
99
|
+
# def test_broadcasts_again
|
100
|
+
# assert_broadcasts('messages', 1) do
|
101
|
+
# ActionCable.server.broadcast 'messages', { text: 'hello' }
|
102
|
+
# end
|
103
|
+
#
|
104
|
+
# assert_broadcasts('messages', 2) do
|
105
|
+
# ActionCable.server.broadcast 'messages', { text: 'hi' }
|
106
|
+
# ActionCable.server.broadcast 'messages', { text: 'how are you?' }
|
107
|
+
# end
|
108
|
+
# end
|
109
|
+
#
|
110
|
+
# See also Minitest::Rails::Expectations::ActionCable::TestHelper#must_have_broadcasts
|
111
|
+
# See https://api.rubyonrails.org/v6.0/classes/ActionCable/TestHelper.html#method-i-assert_broadcasts
|
112
|
+
#
|
113
|
+
# :method: assert_broadcasts
|
114
|
+
# :call-seq: assert_broadcasts(stream, number)
|
115
|
+
|
116
|
+
##
|
117
|
+
# Asserts that no messages have been sent to the stream.
|
118
|
+
#
|
119
|
+
# def test_no_broadcasts
|
120
|
+
# refute_broadcasts 'messages'
|
121
|
+
# ActionCable.server.broadcast 'messages', { text: 'hi' }
|
122
|
+
# assert_broadcasts 'messages', 1
|
123
|
+
# end
|
124
|
+
#
|
125
|
+
# If a block is passed, that block should not cause any message to be sent.
|
126
|
+
#
|
127
|
+
# def test_broadcasts_again
|
128
|
+
# refute_broadcasts 'messages' do
|
129
|
+
# # No job messages should be sent from this block
|
130
|
+
# end
|
131
|
+
# end
|
132
|
+
#
|
133
|
+
# Note: This assertion is simply a shortcut for:
|
134
|
+
#
|
135
|
+
# assert_broadcasts 'messages', 0, &block
|
136
|
+
#
|
137
|
+
# See also Minitest::Rails::Expectations::ActionCable::TestHelper#wont_have_broadcasts
|
138
|
+
# See https://api.rubyonrails.org/v6.0/classes/ActionCable/TestHelper.html#method-i-assert_no_broadcasts
|
139
|
+
#
|
140
|
+
# :method: refute_broadcasts
|
141
|
+
# :call-seq: refute_broadcasts(stream, &block)
|
142
|
+
alias refute_broadcasts assert_no_broadcasts
|
143
|
+
|
144
|
+
##
|
145
|
+
# Asserts that the specified message has been sent to the stream.
|
146
|
+
#
|
147
|
+
# def test_assert_transmitted_message
|
148
|
+
# ActionCable.server.broadcast 'messages', text: 'hello'
|
149
|
+
# assert_broadcast_on('messages', text: 'hello')
|
150
|
+
# end
|
151
|
+
#
|
152
|
+
# If a block is passed, that block should cause a message with the specified data to be sent.
|
153
|
+
#
|
154
|
+
# def test_assert_broadcast_on_again
|
155
|
+
# assert_broadcast_on('messages', text: 'hello') do
|
156
|
+
# ActionCable.server.broadcast 'messages', text: 'hello'
|
157
|
+
# end
|
158
|
+
# end
|
159
|
+
#
|
160
|
+
# See also Minitest::Rails::Expectations::ActionCable::TestHelper#must_broadcast_on
|
161
|
+
# See https://api.rubyonrails.org/v6.0/classes/ActionCable/TestHelper.html#method-i-assert_broadcast_on
|
162
|
+
#
|
163
|
+
# :method: assert_broadcast_on
|
164
|
+
# :call-seq: assert_broadcast_on(stream, data)
|
165
|
+
|
166
|
+
##
|
167
|
+
# Asserts that no streams have been started.
|
168
|
+
#
|
169
|
+
# def test_assert_no_started_stream
|
170
|
+
# subscribe
|
171
|
+
# assert_no_streams
|
172
|
+
# end
|
173
|
+
#
|
174
|
+
# See also Minitest::Rails::Expectations::ActionCable::Channel#wont_have_streams
|
175
|
+
# See https://api.rubyonrails.org/v6.0/classes/ActionCable/Channel/TestCase/Behavior.html#method-i-assert_no_streams
|
176
|
+
#
|
177
|
+
# :method: refute_streams
|
178
|
+
alias refute_streams assert_no_streams
|
179
|
+
|
180
|
+
##
|
181
|
+
# Asserts that the specified stream has been started.
|
182
|
+
#
|
183
|
+
# def test_assert_started_stream
|
184
|
+
# subscribe
|
185
|
+
# assert_has_stream 'messages'
|
186
|
+
# end
|
187
|
+
#
|
188
|
+
# See also Minitest::Rails::Expectations::ActionCable::Channel#must_have_streams
|
189
|
+
# See https://api.rubyonrails.org/v6.0/classes/ActionCable/Channel/TestCase/Behavior.html#method-i-assert_has_stream
|
190
|
+
#
|
191
|
+
# :method: assert_has_stream
|
192
|
+
# :call-seq: assert_has_stream(stream)
|
193
|
+
|
194
|
+
##
|
195
|
+
# Asserts that the specified stream for a model has started.
|
196
|
+
#
|
197
|
+
# def test_assert_started_stream_for
|
198
|
+
# subscribe id: 42
|
199
|
+
# assert_has_stream_for User.find(42)
|
200
|
+
# end
|
201
|
+
#
|
202
|
+
# See also Minitest::Rails::Expectations::ActionCable::Channel#must_have_stream_for
|
203
|
+
# See https://api.rubyonrails.org/v6.0/classes/ActionCable/Channel/TestCase/Behavior.html#method-i-assert_has_stream_for
|
204
|
+
#
|
205
|
+
# :method: assert_has_stream_for
|
206
|
+
# :call-seq: assert_has_stream_for(object)
|
207
|
+
end
|
208
|
+
|
209
|
+
class ActionCable::Connection::TestCase
|
210
|
+
# Asserts that the connection is rejected (via +reject_unauthorized_connection+).
|
211
|
+
#
|
212
|
+
# class ApplicationCable::ConnectionTest < ActionCable::Connection::TestCase
|
213
|
+
# def test_connects_with_proper_cookie
|
214
|
+
# # Simulate the connection request with a cookie.
|
215
|
+
# cookies["user_id"] = users(:john).id
|
216
|
+
#
|
217
|
+
# connect
|
218
|
+
#
|
219
|
+
# # Assert the connection identifier matches the fixture.
|
220
|
+
# assert_equal users(:john).id, connection.user.id
|
221
|
+
# end
|
222
|
+
#
|
223
|
+
# def test_rejects_connection_without_proper_cookie
|
224
|
+
# assert_reject_connection { connect }
|
225
|
+
# end
|
226
|
+
# end
|
227
|
+
#
|
228
|
+
# See also Minitest::Rails::Expectations::ActionCable#must_reject_connection
|
229
|
+
# See https://api.rubyonrails.org/v6.0/classes/ActionCable/Connection/Assertions.html#method-i-assert_reject_connection
|
230
|
+
#
|
231
|
+
# :method: assert_reject_connection
|
232
|
+
end
|
@@ -25,7 +25,7 @@ class ActionMailer::TestCase
|
|
25
25
|
# end
|
26
26
|
#
|
27
27
|
# See also Minitest::Rails::Expectations::ActionMailer#must_have_emails
|
28
|
-
# See https://api.rubyonrails.org/
|
28
|
+
# See https://api.rubyonrails.org/v6.0/classes/ActionMailer/TestHelper.html#method-i-assert_emails
|
29
29
|
#
|
30
30
|
# :method: assert_emails
|
31
31
|
# :call-seq: assert_emails(number, &block)
|
@@ -51,7 +51,7 @@ class ActionMailer::TestCase
|
|
51
51
|
# assert_emails 0, &block
|
52
52
|
#
|
53
53
|
# See also Minitest::Rails::Expectations::ActionMailer#wont_have_emails
|
54
|
-
# See https://api.rubyonrails.org/
|
54
|
+
# See https://api.rubyonrails.org/v6.0/classes/ActionMailer/TestHelper.html#method-i-assert_no_emails
|
55
55
|
#
|
56
56
|
# :method: refute_emails
|
57
57
|
# :call-seq: refute_emails(&block)
|
@@ -84,7 +84,7 @@ class ActionMailer::TestCase
|
|
84
84
|
# end
|
85
85
|
#
|
86
86
|
# See also Minitest::Rails::Expectations::ActionMailer#must_have_enqueued_emails
|
87
|
-
# See https://api.rubyonrails.org/
|
87
|
+
# See https://api.rubyonrails.org/v6.0/classes/ActionMailer/TestHelper.html#method-i-assert_enqueued_emails
|
88
88
|
#
|
89
89
|
# :method: assert_enqueued_emails
|
90
90
|
# :call-seq: assert_enqueued_emails(number, &block)
|
@@ -122,7 +122,7 @@ class ActionMailer::TestCase
|
|
122
122
|
# end
|
123
123
|
#
|
124
124
|
# See also Minitest::Rails::Expectations::ActionMailer#must_enqueue_email_with
|
125
|
-
# See https://api.rubyonrails.org/
|
125
|
+
# See https://api.rubyonrails.org/v6.0/classes/ActionMailer/TestHelper.html#method-i-assert_enqueued_email_with
|
126
126
|
#
|
127
127
|
# :method: assert_enqueued_email_with
|
128
128
|
# :call-seq: assert_enqueued_email_with(mailer, method, args: nil, queue: "mailers", &block)
|
@@ -145,7 +145,7 @@ class ActionMailer::TestCase
|
|
145
145
|
# end
|
146
146
|
#
|
147
147
|
# See also Minitest::Rails::Expectations::ActionMailer#wont_have_enqueued_emails
|
148
|
-
# See https://api.rubyonrails.org/
|
148
|
+
# See https://api.rubyonrails.org/v6.0/classes/ActionMailer/TestHelper.html#method-i-assert_no_enqueued_emails
|
149
149
|
#
|
150
150
|
# :method: refute_enqueued_emails
|
151
151
|
# :call-seq: refute_enqueued_emails(&block)
|
@@ -8,7 +8,7 @@ class ActiveSupport::TestCase
|
|
8
8
|
# end
|
9
9
|
#
|
10
10
|
# See also Minitest::Rails::Expectations::ActiveSupport#must_change
|
11
|
-
# See https://api.rubyonrails.org/
|
11
|
+
# See https://api.rubyonrails.org/v6.0/classes/ActiveSupport/Testing/Assertions.html#method-i-assert_changes
|
12
12
|
#
|
13
13
|
# :method: assert_changes
|
14
14
|
# :call-seq: assert_changes(expression, message = nil, from: UNTRACKED, to: UNTRACKED, &block)
|
@@ -22,7 +22,7 @@ class ActiveSupport::TestCase
|
|
22
22
|
# end
|
23
23
|
#
|
24
24
|
# See also Minitest::Rails::Expectations::ActiveSupport#wont_change
|
25
|
-
# See https://api.rubyonrails.org/
|
25
|
+
# See https://api.rubyonrails.org/v6.0/classes/ActiveSupport/Testing/Assertions.html#method-i-assert_no_changes
|
26
26
|
#
|
27
27
|
# :args: expression, message = nil, &block
|
28
28
|
alias refute_changes assert_no_changes
|
@@ -36,7 +36,7 @@ class ActiveSupport::TestCase
|
|
36
36
|
# end
|
37
37
|
#
|
38
38
|
# See also Minitest::Rails::Expectations::ActiveSupport#must_change
|
39
|
-
# See https://api.rubyonrails.org/
|
39
|
+
# See https://api.rubyonrails.org/v6.0/classes/ActiveSupport/Testing/Assertions.html#method-i-assert_difference
|
40
40
|
#
|
41
41
|
# :method: assert_difference
|
42
42
|
# :call-seq: assert_difference(expression, *args, &block)
|
@@ -50,7 +50,7 @@ class ActiveSupport::TestCase
|
|
50
50
|
# end
|
51
51
|
#
|
52
52
|
# See also Minitest::Rails::Expectations::ActiveSupport#wont_change
|
53
|
-
# See https://api.rubyonrails.org/
|
53
|
+
# See https://api.rubyonrails.org/v6.0/classes/ActiveSupport/Testing/Assertions.html#method-i-assert_no_difference
|
54
54
|
#
|
55
55
|
# :args: expression, message = nil, &block
|
56
56
|
alias refute_difference assert_no_difference
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require "minitest/rails/expectations/active_support"
|
2
2
|
require "minitest/rails/expectations/action_dispatch"
|
3
3
|
require "minitest/rails/expectations/active_job" if defined? ActiveJob
|
4
|
+
require "minitest/rails/expectations/action_cable" if defined? ActionCable
|
4
5
|
require "minitest/rails/expectations/action_mailer" if defined? ActionMailer
|
@@ -0,0 +1,197 @@
|
|
1
|
+
require "active_support/concern"
|
2
|
+
|
3
|
+
module Minitest
|
4
|
+
module Rails
|
5
|
+
module Expectations
|
6
|
+
module ActionCable
|
7
|
+
module TestHelper
|
8
|
+
##
|
9
|
+
# Asserts that the number of broadcasted messages to the stream matches the given number.
|
10
|
+
#
|
11
|
+
# def test_broadcasts
|
12
|
+
# must_have_broadcasts 'messages', 0
|
13
|
+
# ActionCable.server.broadcast 'messages', { text: 'hello' }
|
14
|
+
# must_have_broadcasts 'messages', 1
|
15
|
+
# ActionCable.server.broadcast 'messages', { text: 'world' }
|
16
|
+
# must_have_broadcasts 'messages', 2
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# If a block is passed, that block should cause the specified number of
|
20
|
+
# messages to be broadcasted.
|
21
|
+
#
|
22
|
+
# def test_broadcasts_again
|
23
|
+
# must_have_broadcasts('messages', 1) do
|
24
|
+
# ActionCable.server.broadcast 'messages', { text: 'hello' }
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
# must_have_broadcasts('messages', 2) do
|
28
|
+
# ActionCable.server.broadcast 'messages', { text: 'hi' }
|
29
|
+
# ActionCable.server.broadcast 'messages', { text: 'how are you?' }
|
30
|
+
# end
|
31
|
+
# end
|
32
|
+
#
|
33
|
+
# See also ActionCable::TestHelper#assert_broadcasts
|
34
|
+
# See https://api.rubyonrails.org/v6.0/classes/ActionCable/TestHelper.html#method-i-assert_broadcasts
|
35
|
+
#
|
36
|
+
# :method: must_have_broadcasts
|
37
|
+
# :call-seq: must_have_broadcasts(stream, number)
|
38
|
+
|
39
|
+
##
|
40
|
+
# Asserts that no messages have been sent to the stream.
|
41
|
+
#
|
42
|
+
# def test_no_broadcasts
|
43
|
+
# wont_have_broadcasts 'messages'
|
44
|
+
# ActionCable.server.broadcast 'messages', { text: 'hi' }
|
45
|
+
# must_have_broadcasts 'messages', 1
|
46
|
+
# end
|
47
|
+
#
|
48
|
+
# If a block is passed, that block should not cause any message to be sent.
|
49
|
+
#
|
50
|
+
# def test_broadcasts_again
|
51
|
+
# wont_have_broadcasts 'messages' do
|
52
|
+
# # No job messages should be sent from this block
|
53
|
+
# end
|
54
|
+
# end
|
55
|
+
#
|
56
|
+
# Note: This assertion is simply a shortcut for:
|
57
|
+
#
|
58
|
+
# must_have_broadcasts 'messages', 0, &block
|
59
|
+
#
|
60
|
+
# See also ActionCable::TestHelper#wont_have_broadcasts
|
61
|
+
# See https://api.rubyonrails.org/v6.0/classes/ActionCable/TestHelper.html#method-i-assert_no_broadcasts
|
62
|
+
#
|
63
|
+
# :method: wont_have_broadcasts
|
64
|
+
# :call-seq: wont_have_broadcasts(stream, &block)
|
65
|
+
|
66
|
+
##
|
67
|
+
# Asserts that the specified message has been sent to the stream.
|
68
|
+
#
|
69
|
+
# def test_assert_transmitted_message
|
70
|
+
# ActionCable.server.broadcast 'messages', text: 'hello'
|
71
|
+
# must_broadcast_on('messages', text: 'hello')
|
72
|
+
# end
|
73
|
+
#
|
74
|
+
# If a block is passed, that block should cause a message with the specified data to be sent.
|
75
|
+
#
|
76
|
+
# def test_assert_broadcast_on_again
|
77
|
+
# must_broadcast_on('messages', text: 'hello') do
|
78
|
+
# ActionCable.server.broadcast 'messages', text: 'hello'
|
79
|
+
# end
|
80
|
+
# end
|
81
|
+
#
|
82
|
+
# See also ActionCable::TestHelper#assert_broadcast_on
|
83
|
+
# See https://api.rubyonrails.org/v6.0/classes/ActionCable/TestHelper.html#method-i-assert_broadcast_on
|
84
|
+
#
|
85
|
+
# :method: must_broadcast_on
|
86
|
+
# :call-seq: must_broadcast_on(stream, data)
|
87
|
+
|
88
|
+
extend ::ActiveSupport::Concern
|
89
|
+
|
90
|
+
included do
|
91
|
+
alias_method :must_have_broadcasts, :assert_broadcasts
|
92
|
+
alias_method :wont_have_broadcasts, :assert_no_broadcasts
|
93
|
+
alias_method :must_broadcast_on, :assert_broadcast_on
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
module Channel
|
98
|
+
##
|
99
|
+
# Asserts that no streams have been started.
|
100
|
+
#
|
101
|
+
# def test_assert_no_started_stream
|
102
|
+
# subscribe
|
103
|
+
# wont_have_streams
|
104
|
+
# end
|
105
|
+
#
|
106
|
+
# See also ActionCable::Channel::TestCase#assert_no_streams
|
107
|
+
# See https://api.rubyonrails.org/v6.0/classes/ActionCable/Channel/TestCase/Behavior.html#method-i-assert_no_streams
|
108
|
+
#
|
109
|
+
# :method: wont_have_streams
|
110
|
+
|
111
|
+
##
|
112
|
+
# Asserts that the specified stream has been started.
|
113
|
+
#
|
114
|
+
# def test_assert_started_stream
|
115
|
+
# subscribe
|
116
|
+
# must_have_streams 'messages'
|
117
|
+
# end
|
118
|
+
#
|
119
|
+
# See also ActionCable::Channel::TestCase#assert_has_stream
|
120
|
+
# See https://api.rubyonrails.org/v6.0/classes/ActionCable/Channel/TestCase/Behavior.html#method-i-assert_has_stream
|
121
|
+
#
|
122
|
+
# :method: must_have_streams
|
123
|
+
# :call-seq: must_have_streams(stream)
|
124
|
+
|
125
|
+
##
|
126
|
+
# Asserts that the specified stream for a model has started.
|
127
|
+
#
|
128
|
+
# def test_assert_started_stream_for
|
129
|
+
# subscribe id: 42
|
130
|
+
# must_have_stream_for User.find(42)
|
131
|
+
# end
|
132
|
+
#
|
133
|
+
# See also ActionCable::Channel::TestCase#assert_has_stream_for
|
134
|
+
# See https://api.rubyonrails.org/v6.0/classes/ActionCable/Channel/TestCase/Behavior.html#method-i-assert_has_stream_for
|
135
|
+
#
|
136
|
+
# :method: must_have_stream_for
|
137
|
+
# :call-seq: must_have_stream_for(object)
|
138
|
+
|
139
|
+
extend ::ActiveSupport::Concern
|
140
|
+
|
141
|
+
included do
|
142
|
+
alias_method :wont_have_streams, :assert_no_streams
|
143
|
+
alias_method :must_have_streams, :assert_has_stream
|
144
|
+
alias_method :must_have_stream_for, :assert_has_stream_for
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
module Connection
|
149
|
+
##
|
150
|
+
# Asserts that the connection is rejected (via +reject_unauthorized_connection+).
|
151
|
+
#
|
152
|
+
# describe "Application Connections", :connection do
|
153
|
+
# it "connects with proper cookie" do
|
154
|
+
# # Simulate the connection request with a cookie.
|
155
|
+
# cookies["user_id"] = users(:john).id
|
156
|
+
#
|
157
|
+
# connect
|
158
|
+
#
|
159
|
+
# # Assert the connection identifier matches the fixture.
|
160
|
+
# value(connection.user.id).must_equal users(:john).id
|
161
|
+
# end
|
162
|
+
#
|
163
|
+
# it "rejects connection without proper cookie" do
|
164
|
+
# must_reject_connection { connect }
|
165
|
+
# end
|
166
|
+
# end
|
167
|
+
#
|
168
|
+
# See also ActionCable::Connection::TestCase#assert_reject_connection
|
169
|
+
# See https://api.rubyonrails.org/v6.0/classes/ActionCable/Connection/Assertions.html#method-i-assert_reject_connection
|
170
|
+
#
|
171
|
+
# :method: must_reject_connection
|
172
|
+
|
173
|
+
extend ::ActiveSupport::Concern
|
174
|
+
|
175
|
+
included do
|
176
|
+
alias_method :must_reject_connection, :assert_reject_connection
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
unless ENV["MT_NO_EXPECTATIONS"]
|
185
|
+
class ActionCable::TestCase # :nodoc:
|
186
|
+
include Minitest::Rails::Expectations::ActionCable::TestHelper
|
187
|
+
end
|
188
|
+
|
189
|
+
class ActionCable::Channel::TestCase # :nodoc:
|
190
|
+
include Minitest::Rails::Expectations::ActionCable::TestHelper
|
191
|
+
include Minitest::Rails::Expectations::ActionCable::Channel
|
192
|
+
end
|
193
|
+
|
194
|
+
class ActionCable::Connection::TestCase # :nodoc:
|
195
|
+
include Minitest::Rails::Expectations::ActionCable::Connection
|
196
|
+
end
|
197
|
+
end
|
@@ -30,7 +30,7 @@ module Minitest
|
|
30
30
|
# end
|
31
31
|
#
|
32
32
|
# See also ActionMailer::TestClass#assert_emails
|
33
|
-
# See https://api.rubyonrails.org/
|
33
|
+
# See https://api.rubyonrails.org/v6.0/classes/ActionMailer/TestHelper.html#method-i-assert_emails
|
34
34
|
#
|
35
35
|
# :method: must_have_emails
|
36
36
|
# :call-seq: must_have_emails(number, &block)
|
@@ -56,7 +56,7 @@ module Minitest
|
|
56
56
|
# must_have_emails 0, &block
|
57
57
|
#
|
58
58
|
# See also ActionMailer::TestClass#wont_have_emails
|
59
|
-
# See https://api.rubyonrails.org/
|
59
|
+
# See https://api.rubyonrails.org/v6.0/classes/ActionMailer/TestHelper.html#method-i-assert_no_emails
|
60
60
|
#
|
61
61
|
# :method: wont_have_emails
|
62
62
|
# :call-seq: wont_have_emails(&block)
|
@@ -88,7 +88,7 @@ module Minitest
|
|
88
88
|
# end
|
89
89
|
#
|
90
90
|
# See also ActionMailer::TestClass#assert_enqueued_emails
|
91
|
-
# See https://api.rubyonrails.org/
|
91
|
+
# See https://api.rubyonrails.org/v6.0/classes/ActionMailer/TestHelper.html#method-i-assert_enqueued_emails
|
92
92
|
#
|
93
93
|
# :method: must_have_enqueued_emails
|
94
94
|
# :call-seq: must_have_enqueued_emails(number, &block)
|
@@ -126,7 +126,7 @@ module Minitest
|
|
126
126
|
# end
|
127
127
|
#
|
128
128
|
# See also ActionMailer::TestClass#assert_enqueued_email_with
|
129
|
-
# See https://api.rubyonrails.org/
|
129
|
+
# See https://api.rubyonrails.org/v6.0/classes/ActionMailer/TestHelper.html#method-i-assert_enqueued_email_with
|
130
130
|
#
|
131
131
|
# :method: must_enqueue_email_with
|
132
132
|
# :call-seq: must_enqueue_email_with(mailer, method, args: nil, queue: "mailers", &block)
|
@@ -149,7 +149,7 @@ module Minitest
|
|
149
149
|
# end
|
150
150
|
#
|
151
151
|
# See also ActionMailer::TestClass#assert_no_enqueued_emails
|
152
|
-
# See https://api.rubyonrails.org/
|
152
|
+
# See https://api.rubyonrails.org/v6.0/classes/ActionMailer/TestHelper.html#method-i-assert_no_enqueued_emails
|
153
153
|
#
|
154
154
|
# :method: wont_have_enqueued_emails
|
155
155
|
# :call-seq: wont_have_enqueued_emails(&block)
|
@@ -12,7 +12,7 @@ module Minitest
|
|
12
12
|
# end }.must_change "User.count", from: 5, to: 8
|
13
13
|
#
|
14
14
|
# See also ActiveSupport::TestCase#assert_difference
|
15
|
-
# See https://api.rubyonrails.org/
|
15
|
+
# See https://api.rubyonrails.org/v6.0/classes/ActiveSupport/Testing/Assertions.html#method-i-assert_changes
|
16
16
|
#
|
17
17
|
# :method: must_change
|
18
18
|
# :args: expression, from: UNTRACKED, to: UNTRACKED
|
@@ -27,7 +27,7 @@ module Minitest
|
|
27
27
|
# end
|
28
28
|
#
|
29
29
|
# See also ActiveSupport::TestCase#assert_difference
|
30
|
-
# See https://api.rubyonrails.org/
|
30
|
+
# See https://api.rubyonrails.org/v6.0/classes/ActiveSupport/Testing/Assertions.html#method-i-assert_no_changes
|
31
31
|
#
|
32
32
|
# :method: wont_change
|
33
33
|
# :args: expression
|
@@ -43,7 +43,7 @@ module Minitest
|
|
43
43
|
# end }.must_differ "User.count", 3
|
44
44
|
#
|
45
45
|
# See also ActiveSupport::TestCase#assert_difference
|
46
|
-
# See https://api.rubyonrails.org/
|
46
|
+
# See https://api.rubyonrails.org/v6.0/classes/ActiveSupport/Testing/Assertions.html#method-i-assert_difference
|
47
47
|
#
|
48
48
|
# :method: must_differ
|
49
49
|
# :args: expression, *args
|
@@ -56,7 +56,7 @@ module Minitest
|
|
56
56
|
# value { User.new }.wont_differ "User.count"
|
57
57
|
#
|
58
58
|
# See also ActiveSupport::TestCase#refute_difference
|
59
|
-
# See https://api.rubyonrails.org/
|
59
|
+
# See https://api.rubyonrails.org/v6.0/classes/ActiveSupport/Testing/Assertions.html#method-i-assert_no_difference
|
60
60
|
#
|
61
61
|
# :method: wont_differ
|
62
62
|
# :args: expression
|
@@ -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(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
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minitest-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 6.0.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Moore
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 6.0.0.beta1
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 6.0.0.beta1
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: minitest-autotest
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -129,6 +129,7 @@ files:
|
|
129
129
|
- lib/generators/minitest/helper/helper_generator.rb
|
130
130
|
- lib/generators/minitest/install/install_generator.rb
|
131
131
|
- lib/generators/minitest/install/templates/test/application_system_test_case.rb.tt
|
132
|
+
- lib/generators/minitest/install/templates/test/channels/application_cable/connection_test.rb.tt
|
132
133
|
- lib/generators/minitest/install/templates/test/test_helper.rb.tt
|
133
134
|
- lib/generators/minitest/integration/integration_generator.rb
|
134
135
|
- lib/generators/minitest/integration/templates/integration_spec.rb.tt
|
@@ -161,6 +162,7 @@ files:
|
|
161
162
|
- lib/minitest-rails.rb
|
162
163
|
- lib/minitest/rails.rb
|
163
164
|
- lib/minitest/rails/assertions.rb
|
165
|
+
- lib/minitest/rails/assertions/action_cable.rb
|
164
166
|
- lib/minitest/rails/assertions/action_dispatch.rb
|
165
167
|
- lib/minitest/rails/assertions/action_mailer.rb
|
166
168
|
- lib/minitest/rails/assertions/action_view.rb
|
@@ -168,10 +170,12 @@ files:
|
|
168
170
|
- lib/minitest/rails/assertions/active_support.rb
|
169
171
|
- lib/minitest/rails/capybara.rb
|
170
172
|
- lib/minitest/rails/expectations.rb
|
173
|
+
- lib/minitest/rails/expectations/action_cable.rb
|
171
174
|
- lib/minitest/rails/expectations/action_dispatch.rb
|
172
175
|
- lib/minitest/rails/expectations/action_mailer.rb
|
173
176
|
- lib/minitest/rails/expectations/active_job.rb
|
174
177
|
- lib/minitest/rails/expectations/active_support.rb
|
178
|
+
- lib/minitest/rails/parallelize.rb
|
175
179
|
- lib/minitest/rails/railtie.rb
|
176
180
|
- lib/minitest/rails/version.rb
|
177
181
|
homepage: http://blowmage.com/minitest-rails
|
@@ -186,12 +190,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
186
190
|
requirements:
|
187
191
|
- - ">="
|
188
192
|
- !ruby/object:Gem::Version
|
189
|
-
version: 2.
|
193
|
+
version: 2.5.0
|
190
194
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
191
195
|
requirements:
|
192
|
-
- - "
|
196
|
+
- - ">"
|
193
197
|
- !ruby/object:Gem::Version
|
194
|
-
version:
|
198
|
+
version: 1.3.1
|
195
199
|
requirements: []
|
196
200
|
rubygems_version: 3.0.3
|
197
201
|
signing_key:
|