minitest-rails 3.0.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +5 -0
  3. data/LICENSE +1 -1
  4. data/README.md +94 -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 +19 -8
  15. data/lib/generators/minitest/install/templates/test/test_helper.rb.tt +16 -0
  16. data/lib/generators/minitest/integration/integration_generator.rb +12 -9
  17. data/lib/generators/minitest/integration/templates/integration_spec.rb.tt +9 -0
  18. data/lib/generators/minitest/integration/templates/integration_test.rb.tt +9 -0
  19. data/lib/generators/minitest/job/job_generator.rb +13 -10
  20. data/lib/generators/minitest/job/templates/unit_spec.rb.tt +9 -0
  21. data/lib/generators/minitest/job/templates/{job_test.rb → unit_test.rb.tt} +3 -3
  22. data/lib/generators/minitest/mailer/mailer_generator.rb +8 -11
  23. data/lib/generators/minitest/mailer/templates/functional_spec.rb.tt +21 -0
  24. data/lib/generators/minitest/mailer/templates/{mailer_test.rb → functional_test.rb.tt} +3 -3
  25. data/lib/generators/minitest/mailer/templates/{preview.rb → preview.rb.tt} +0 -0
  26. data/lib/generators/minitest/model/model_generator.rb +9 -12
  27. data/lib/generators/minitest/model/templates/{fixtures.yml → fixtures.yml.tt} +3 -3
  28. data/lib/generators/minitest/model/templates/unit_spec.rb.tt +9 -0
  29. data/lib/generators/minitest/model/templates/unit_test.rb.tt +9 -0
  30. data/lib/generators/minitest/plugin/plugin_generator.rb +15 -0
  31. data/lib/generators/minitest/plugin/templates/%file_name%_test.rb.tt +15 -0
  32. data/lib/generators/minitest/plugin/templates/test_helper.rb +2 -0
  33. data/lib/generators/minitest/scaffold/scaffold_generator.rb +21 -23
  34. data/lib/generators/minitest/scaffold/templates/api_functional_spec.rb.tt +42 -0
  35. data/lib/generators/minitest/scaffold/templates/api_functional_test.rb.tt +44 -0
  36. data/lib/generators/minitest/scaffold/templates/functional_spec.rb.tt +52 -0
  37. data/lib/generators/minitest/scaffold/templates/{controller_test.rb → functional_test.rb.tt} +16 -16
  38. data/lib/minitest/rails.rb +45 -108
  39. data/lib/minitest/rails/assertions.rb +5 -906
  40. data/lib/minitest/rails/assertions/action_dispatch.rb +356 -0
  41. data/lib/minitest/rails/assertions/action_mailer.rb +115 -0
  42. data/lib/minitest/rails/assertions/action_view.rb +356 -0
  43. data/lib/minitest/rails/assertions/active_job.rb +151 -0
  44. data/lib/minitest/rails/assertions/active_support.rb +29 -0
  45. data/lib/minitest/rails/expectations.rb +4 -565
  46. data/lib/minitest/rails/expectations/action_dispatch.rb +307 -0
  47. data/lib/minitest/rails/expectations/action_mailer.rb +136 -0
  48. data/lib/minitest/rails/expectations/active_job.rb +182 -0
  49. data/lib/minitest/rails/expectations/active_support.rb +42 -0
  50. data/lib/minitest/rails/railtie.rb +3 -2
  51. data/lib/minitest/rails/version.rb +1 -1
  52. metadata +72 -89
  53. data/.autotest +0 -23
  54. data/.gemtest +0 -0
  55. data/.travis.yml +0 -25
  56. data/CHANGELOG.rdoc +0 -223
  57. data/Gemfile +0 -7
  58. data/Manifest.txt +0 -76
  59. data/README.rdoc +0 -110
  60. data/Rakefile +0 -30
  61. data/gemfiles/5.0.gemfile +0 -5
  62. data/gemfiles/head.gemfile +0 -5
  63. data/lib/generators/.document +0 -0
  64. data/lib/generators/minitest/install/templates/test_helper.rb +0 -19
  65. data/lib/generators/minitest/integration/templates/integration_spec.rb +0 -8
  66. data/lib/generators/minitest/integration/templates/integration_test.rb +0 -7
  67. data/lib/generators/minitest/job/templates/job_spec.rb +0 -9
  68. data/lib/generators/minitest/mailer/templates/mailer_spec.rb +0 -20
  69. data/lib/generators/minitest/model/templates/model_spec.rb +0 -11
  70. data/lib/generators/minitest/model/templates/model_test.rb +0 -13
  71. data/lib/generators/minitest/scaffold/templates/api_controller_spec.rb +0 -42
  72. data/lib/generators/minitest/scaffold/templates/api_controller_test.rb +0 -44
  73. data/lib/generators/minitest/scaffold/templates/controller_spec.rb +0 -52
  74. data/lib/minitest/rails/constant_lookup.rb +0 -52
  75. data/lib/minitest/rails/controller.rb +0 -14
  76. data/minitest-rails.gemspec +0 -48
  77. data/tasks/test.rake +0 -29
  78. data/test/generators/test_controller_generator.rb +0 -58
  79. data/test/generators/test_generator_generator.rb +0 -58
  80. data/test/generators/test_helper_generator.rb +0 -34
  81. data/test/generators/test_install_generator.rb +0 -27
  82. data/test/generators/test_job_generator.rb +0 -45
  83. data/test/generators/test_mailer_generator.rb +0 -42
  84. data/test/generators/test_model_generator.rb +0 -80
  85. data/test/generators/test_scaffold_generator.rb +0 -26
  86. data/test/helper.rb +0 -93
  87. data/test/rails/action_dispatch/test_assertions.rb +0 -39
  88. data/test/rails/action_dispatch/test_expectations.rb +0 -39
  89. data/test/rails/action_dispatch/test_spec_type.rb +0 -49
  90. data/test/rails/action_mailer/test_mailers.rb +0 -109
  91. data/test/rails/action_mailer/test_spec_type.rb +0 -47
  92. data/test/rails/action_view/test_helpers.rb +0 -73
  93. data/test/rails/action_view/test_spec_type.rb +0 -58
  94. data/test/rails/active_job/test_assertions.rb +0 -46
  95. data/test/rails/active_job/test_expectations.rb +0 -55
  96. data/test/rails/active_job/test_spec_type.rb +0 -49
  97. data/test/rails/active_support/test_assertions.rb +0 -31
  98. data/test/rails/active_support/test_expectations.rb +0 -21
  99. data/test/rails/active_support/test_spec_type.rb +0 -28
  100. data/test/rails/generators/test_spec_type.rb +0 -45
  101. data/test/rails/test_constant_lookup.rb +0 -58
  102. data/test/test_sanity.rb +0 -7
@@ -4,102 +4,58 @@ require "minitest/spec"
4
4
  require "minitest/mock"
5
5
  require "minitest/hell" if ENV["MT_HELL"]
6
6
 
7
- ################################################################################
8
- # Do we support old school controller tests?
9
- ################################################################################
10
-
11
- module Minitest
12
- module Rails
13
- def self.controller_tests?
14
- require "rails-controller-testing"
15
- return true
16
- rescue LoadError
17
- return false
18
- end
19
- end
20
- end
21
-
22
- ################################################################################
23
- # Add and configure the spec DSL
24
- ################################################################################
25
-
26
7
  require "active_support/test_case"
27
- require "minitest/rails/constant_lookup"
8
+ require "active_support/testing/constant_lookup"
9
+
28
10
  class ActiveSupport::TestCase
11
+ # Add and configure the spec DSL
29
12
  # Remove describe method if present
30
- class << self
31
- remove_method :describe
32
- end if self.respond_to?(:describe) &&
33
- self.method(:describe).owner == ActiveSupport::TestCase
13
+ if respond_to?(:describe) &&
14
+ method(:describe).owner == ActiveSupport::TestCase
15
+ class << self
16
+ remove_method :describe
17
+ end
18
+ end
34
19
 
35
20
  # Add spec DSL
36
21
  extend Minitest::Spec::DSL
37
22
 
38
23
  # Resolve constants from the test name when using the spec DSL
39
- include Minitest::Rails::ConstantLookup
40
- end
24
+ include ActiveSupport::Testing::ConstantLookup
41
25
 
42
- class ActiveSupport::TestCase
43
- if defined?(ActiveRecord::Base)
44
- # Use AS::TestCase for the base class when describing a model
26
+ # Use AS::TC for the base class when describing a model
27
+ if defined? ActiveRecord
45
28
  register_spec_type(self) do |desc|
46
29
  desc < ActiveRecord::Base if desc.is_a?(Class)
47
30
  end
48
31
  end
49
- register_spec_type(self) do |desc, *addl|
50
- addl.include? :model
51
- end
52
- end
53
32
 
54
- if Minitest::Rails.controller_tests?
55
- require "action_controller/test_case"
56
- require "minitest/rails/controller"
57
- class ActionController::TestCase
58
- # Use AC::TestCase for the base class when describing a controller
59
- register_spec_type(self) do |desc|
60
- Class === desc && desc < ActionController::Metal
61
- end
62
- register_spec_type(/Controller( ?Test)?\z/i, self)
63
- register_spec_type(self) do |desc, *addl|
64
- addl.include? :controller
65
- end
66
-
67
- # Resolve the controller from the test name when using the spec DSL
68
- def self.determine_default_controller_class(name)
69
- controller = determine_constant_from_test_name(name) do |constant|
70
- Class === constant && constant < ActionController::Metal
71
- end
72
- raise NameError.new("Unable to resolve controller for #{name}") if controller.nil?
73
- controller
74
- end
33
+ # Use AS::TC for the base class when described using :model
34
+ register_spec_type(self) do |_desc, *addl|
35
+ addl.include? :model
75
36
  end
76
37
  end
77
38
 
78
39
  require "action_view/test_case"
79
- class ActionView::TestCase
80
- # Use AV::TestCase for the base class for helpers and views
81
- register_spec_type(/(Helper( ?Test)?| View Test)\z/i, self)
82
- register_spec_type(self) do |desc, *addl|
83
- addl.include?(:view) ||
84
- addl.include?(:helper)
85
- end
86
40
 
87
- # Resolve the helper or view from the test name when using the spec DSL
88
- def self.determine_default_helper_class(name)
89
- determine_constant_from_test_name(name) do |constant|
90
- Module === constant && !(Class === constant)
91
- end
41
+ class ActionView::TestCase
42
+ # Use AV::TC for the base class when described using :view or :helper
43
+ register_spec_type(self) do |_desc, *addl|
44
+ addl.include?(:view) || addl.include?(:helper)
92
45
  end
93
46
  end
94
47
 
95
48
  if defined? ActiveJob
49
+ # TODO: require?
50
+
96
51
  class ActiveJob::TestCase
97
- # Use AJ::TestCase for the base when describing a job
52
+ # Use AJ::TC for the base when describing a job
98
53
  register_spec_type(self) do |desc|
99
54
  desc < ActiveJob::Base if desc.is_a?(Class)
100
55
  end
101
- register_spec_type(/Job( ?Test)?\z/i, self)
102
- register_spec_type(self) do |desc, *addl|
56
+
57
+ # Use AJ::TC for the base class when described using :job
58
+ register_spec_type(self) do |_desc, *addl|
103
59
  addl.include? :job
104
60
  end
105
61
  end
@@ -108,64 +64,45 @@ end
108
64
  if defined? ActionMailer
109
65
  require "action_mailer/test_helper"
110
66
  require "action_mailer/test_case"
67
+
111
68
  class ActionMailer::TestCase
112
- # Use AM::TestCase for the base class when describing a mailer
69
+ # Use AM::TC for the base class when describing a mailer
113
70
  register_spec_type(self) do |desc|
114
71
  desc < ActionMailer::Base if desc.is_a?(Class)
115
72
  end
116
- register_spec_type(/Mailer( ?Test)?\z/i, self)
117
- register_spec_type(self) do |desc, *addl|
118
- addl.include? :mailer
119
- end
120
73
 
121
- # Resolve the mailer from the test name when using the spec DSL
122
- def self.determine_default_mailer(name)
123
- mailer = determine_constant_from_test_name(name) do |constant|
124
- Class === constant && constant < ::ActionMailer::Base
125
- end
126
- raise ActionMailer::NonInferrableMailerError.new(name) if mailer.nil?
127
- mailer
74
+ # Use AM::TC for the base class when described using :mailer
75
+ register_spec_type(self) do |_desc, *addl|
76
+ addl.include? :mailer
128
77
  end
129
78
  end
130
79
  end
131
80
 
132
81
  require "action_dispatch/testing/integration"
82
+
133
83
  class ActionDispatch::IntegrationTest
134
- if Minitest::Rails.controller_tests?
135
- # Register by Integration name only
136
- register_spec_type(/Integration( ?Test)?\z/i, self)
137
- register_spec_type(self) do |desc, *addl|
138
- addl.include? :integration
139
- end
140
- else
141
- # Use AD::IntegrationTest for the base class when describing a controller
142
- register_spec_type(self) do |desc|
143
- Class === desc && desc < ActionController::Metal
144
- end
145
- # Register by name, either Integration or Controller
146
- register_spec_type(/(Integration|Controller)( ?Test)?\z/i, self)
147
- register_spec_type(self) do |desc, *addl|
148
- addl.include?(:integration) ||
149
- addl.include?(:controller)
150
- end
84
+ # Use AD:IT for the base class when describing a controller
85
+ register_spec_type(self) do |desc|
86
+ desc < ActionController::Metal if desc.is_a?(Class)
87
+ end
88
+
89
+ # Use AD:IT for the base class when described using :integration
90
+ register_spec_type(self) do |_desc, *addl|
91
+ addl.include? :integration
151
92
  end
152
93
  end
153
94
 
95
+ # TODO: Rails::Generators::TestCase require?
96
+
154
97
  class Rails::Generators::TestCase
98
+ # Use R::G::TC for the base class when describing a generator
155
99
  register_spec_type(self) do |desc|
156
100
  desc < Rails::Generators::Base if desc.is_a?(Class)
157
101
  end
158
- register_spec_type(/Generator( ?Test)?\z/i, self)
159
- register_spec_type(self) do |desc, *addl|
160
- addl.include? :generator
161
- end
162
102
 
163
- def self.determine_default_generator(name)
164
- generator = determine_constant_from_test_name(name) do |constant|
165
- Class === constant && constant < Rails::Generators::Base
166
- end
167
- raise NameError.new("Unable to resolve generator for #{name}") if generator.nil?
168
- generator
103
+ # Use R::G::TC for the base class when described using :generator
104
+ register_spec_type(self) do |_desc, *addl|
105
+ addl.include? :generator
169
106
  end
170
107
  end
171
108
 
@@ -1,906 +1,5 @@
1
- class ActiveSupport::TestCase
2
- ##
3
- # Checks the numeric difference between the return value of an expression as a result of what is evaluated.
4
- #
5
- # assert_difference "User.count", +1 do
6
- # User.create
7
- # end
8
- #
9
- # See also Minitest::Rails::Expectations#must_change
10
- #
11
- # :method: assert_difference
12
- # :call-seq: assert_difference(expression, difference = 1, message = nil, &block)
13
-
14
- ##
15
- # Checks that the numeric result of evaluating an expression is not changed before and after invoking.
16
- #
17
- # assert_no_difference "User.count" do
18
- # User.new
19
- # end
20
- #
21
- # See also Minitest::Rails::Expectations#wont_change
22
- #
23
- # :method: assert_no_difference
24
- # :call-seq: assert_no_difference(expression, message = nil, &block)
25
-
26
- ##
27
- # Checks that the numeric result of evaluating an expression is not changed before and after invoking.
28
- #
29
- # refute_difference "User.count", do
30
- # User.new
31
- # end
32
- #
33
- # See also Minitest::Rails::Expectations#wont_change
34
- #
35
- # :args: expression, message = nil, &block
36
- alias :refute_difference :assert_no_difference
37
-
38
- end
39
-
40
- class ActionView::TestCase
41
- ##
42
- # Checks the numeric difference between the return value of an expression as a result of what is evaluated.
43
- #
44
- # assert_difference "User.count", +1 do
45
- # User.create
46
- # end
47
- #
48
- # See also Minitest::Rails::Expectations#must_change
49
- #
50
- # :method: assert_difference
51
- # :call-seq: assert_difference(expression, difference = 1, message = nil, &block)
52
-
53
- ##
54
- # Checks that the numeric result of evaluating an expression is not changed before and after invoking.
55
- #
56
- # assert_no_difference "User.count" do
57
- # User.new
58
- # end
59
- #
60
- # See also Minitest::Rails::Expectations#wont_change
61
- #
62
- # :method: assert_no_difference
63
- # :call-seq: assert_no_difference(expression, message = nil, &block)
64
-
65
- ##
66
- # Checks that the numeric result of evaluating an expression is not changed before and after invoking.
67
- #
68
- # refute_difference "User.count", do
69
- # User.new
70
- # end
71
- #
72
- # See also Minitest::Rails::Expectations#wont_change
73
- #
74
- # :args: expression, message = nil, &block
75
- alias :refute_difference :assert_no_difference
76
-
77
- # Asserts that the response is one of the following types:
78
- #
79
- # * <tt>:success</tt> - Status code was in the 200-299 range
80
- # * <tt>:redirect</tt> - Status code was in the 300-399 range
81
- # * <tt>:missing</tt> - Status code was 404
82
- # * <tt>:error</tt> - Status code was in the 500-599 range
83
- #
84
- # You can also pass an explicit status number like <tt>assert_response(501)</tt>
85
- # or its symbolic equivalent <tt>assert_response(:not_implemented)</tt>.
86
- # See Rack::Utils::SYMBOL_TO_STATUS_CODE for a full list.
87
- #
88
- # # assert that the response was a redirection
89
- # assert_response :redirect
90
- #
91
- # # assert that the response code was status code 401 (unauthorized)
92
- # assert_response 401
93
- #
94
- # See also Minitest::Rails::Expectations#must_respond_with
95
- #
96
- # :method: assert_response
97
- # :call-seq: assert_response(type, message = nil)
98
-
99
- ##
100
- # Assert that the redirection options passed in match those of the redirect called in the latest action.
101
- # This match can be partial, such that <tt>assert_redirected_to(controller: "weblog")</tt> will also
102
- # match the redirection of <tt>redirect_to(controller: "weblog", action: "show")</tt> and so on.
103
- #
104
- # # assert that the redirection was to the "index" action on the WeblogController
105
- # assert_redirected_to controller: "weblog", action: "index"
106
- #
107
- # # assert that the redirection was to the named route login_url
108
- # assert_redirected_to login_url
109
- #
110
- # # assert that the redirection was to the url for @customer
111
- # assert_redirected_to @customer
112
- #
113
- # # asserts that the redirection matches the regular expression
114
- # assert_redirected_to %r(\Ahttp://example.org)
115
- #
116
- # See also Minitest::Rails::Expectations#must_redirect_to
117
- #
118
- # :method: assert_redirected_to
119
- # :call-seq: assert_redirected_to(options = {}, message=nil)
120
-
121
- ##
122
- # Asserts that the provided options can be used to generate the provided path. This is the inverse of +assert_recognizes+.
123
- # The +extras+ parameter is used to tell the request the names and values of additional request parameters that would be in
124
- # a query string. The +message+ parameter allows you to specify a custom error message for assertion failures.
125
- #
126
- # The +defaults+ parameter is unused.
127
- #
128
- # # Asserts that the default action is generated for a route with no action
129
- # assert_generates "/items", controller: "items", action: "index"
130
- #
131
- # # Tests that the list action is properly routed
132
- # assert_generates "/items/list", controller: "items", action: "list"
133
- #
134
- # # Tests the generation of a route with a parameter
135
- # assert_generates "/items/list/1", { controller: "items", action: "list", id: "1" }
136
- #
137
- # # Asserts that the generated route gives us our custom route
138
- # assert_generates "changesets/12", { controller: 'scm', action: 'show_diff', revision: "12" }
139
- #
140
- # See also Minitest::Rails::Expectations#must_route_to
141
- #
142
- # :method: assert_generates
143
- # :call-seq: assert_generates(expected_path, options, defaults={}, extras = {}, message=nil)
144
-
145
- ##
146
- # Asserts that the routing of the given +path+ was handled correctly and that the parsed options (given in the +expected_options+ hash)
147
- # match +path+. Basically, it asserts that \Rails recognizes the route given by +expected_options+.
148
- #
149
- # Pass a hash in the second argument (+path+) to specify the request method. This is useful for routes
150
- # requiring a specific HTTP method. The hash should contain a :path with the incoming request path
151
- # and a :method containing the required HTTP verb.
152
- #
153
- # # assert that POSTing to /items will call the create action on ItemsController
154
- # assert_recognizes({controller: 'items', action: 'create'}, {path: 'items', method: :post})
155
- #
156
- # You can also pass in +extras+ with a hash containing URL parameters that would normally be in the query string. This can be used
157
- # to assert that values in the query string string will end up in the params hash correctly. To test query strings you must use the
158
- # extras argument, appending the query string on the path directly will not work. For example:
159
- #
160
- # # assert that a path of '/items/list/1?view=print' returns the correct options
161
- # assert_recognizes({controller: 'items', action: 'list', id: '1', view: 'print'}, 'items/list/1', { view: "print" })
162
- #
163
- # The +message+ parameter allows you to pass in an error message that is displayed upon failure.
164
- #
165
- # # Check the default route (i.e., the index action)
166
- # assert_recognizes({controller: 'items', action: 'index'}, 'items')
167
- #
168
- # # Test a specific action
169
- # assert_recognizes({controller: 'items', action: 'list'}, 'items/list')
170
- #
171
- # # Test an action with a parameter
172
- # assert_recognizes({controller: 'items', action: 'destroy', id: '1'}, 'items/destroy/1')
173
- #
174
- # # Test a custom route
175
- # assert_recognizes({controller: 'items', action: 'show', id: '1'}, 'view/item1')
176
- #
177
- # See also Minitest::Rails::Expectations#must_route_from
178
- #
179
- # :method: assert_recognizes
180
- # :call-seq: assert_recognizes(expected_options, path, extras={}, msg=nil)
181
-
182
- ##
183
- # Asserts that path and options match both ways; in other words, it verifies that <tt>path</tt> generates
184
- # <tt>options</tt> and then that <tt>options</tt> generates <tt>path</tt>. This essentially combines +assert_recognizes+
185
- # and +assert_generates+ into one step.
186
- #
187
- # The +extras+ hash allows you to specify options that would normally be provided as a query string to the action. The
188
- # +message+ parameter allows you to specify a custom error message to display upon failure.
189
- #
190
- # # Assert a basic route: a controller with the default action (index)
191
- # assert_routing '/home', controller: 'home', action: 'index'
192
- #
193
- # # Test a route generated with a specific controller, action, and parameter (id)
194
- # assert_routing '/entries/show/23', controller: 'entries', action: 'show', id: 23
195
- #
196
- # # Assert a basic route (controller + default action), with an error message if it fails
197
- # assert_routing '/store', { controller: 'store', action: 'index' }, {}, {}, 'Route for store index not generated properly'
198
- #
199
- # # Tests a route, providing a defaults hash
200
- # assert_routing 'controller/action/9', {id: "9", item: "square"}, {controller: "controller", action: "action"}, {}, {item: "square"}
201
- #
202
- # # Tests a route with a HTTP method
203
- # assert_routing({ method: 'put', path: '/product/321' }, { controller: "product", action: "update", id: "321" })
204
- #
205
- # See also Minitest::Rails::Expectations#must_route
206
- #
207
- # :method: assert_routing
208
- # :call-seq: assert_routing(path, options, defaults={}, extras={}, message=nil)
209
-
210
- # An assertion that selects elements and makes one or more equality tests.
211
- #
212
- # If the first argument is an element, selects all matching elements
213
- # starting from (and including) that element and all its children in
214
- # depth-first order.
215
- #
216
- # If no element if specified, calling +assert_select+ selects from the
217
- # response HTML unless +assert_select+ is called from within an +assert_select+ block.
218
- #
219
- # When called with a block +assert_select+ passes an array of selected elements
220
- # to the block. Calling +assert_select+ from the block, with no element specified,
221
- # runs the assertion on the complete set of elements selected by the enclosing assertion.
222
- # Alternatively the array may be iterated through so that +assert_select+ can be called
223
- # separately for each element.
224
- #
225
- #
226
- # ==== Example
227
- # If the response contains two ordered lists, each with four list elements then:
228
- # assert_select "ol" do |elements|
229
- # elements.each do |element|
230
- # assert_select element, "li", 4
231
- # end
232
- # end
233
- #
234
- # will pass, as will:
235
- # assert_select "ol" do
236
- # assert_select "li", 8
237
- # end
238
- #
239
- # The selector may be a CSS selector expression (String), an expression
240
- # with substitution values, or an HTML::Selector object.
241
- #
242
- # === Equality Tests
243
- #
244
- # The equality test may be one of the following:
245
- # * <tt>true</tt> - Assertion is true if at least one element selected.
246
- # * <tt>false</tt> - Assertion is true if no element selected.
247
- # * <tt>String/Regexp</tt> - Assertion is true if the text value of at least
248
- # one element matches the string or regular expression.
249
- # * <tt>Integer</tt> - Assertion is true if exactly that number of
250
- # elements are selected.
251
- # * <tt>Range</tt> - Assertion is true if the number of selected
252
- # elements fit the range.
253
- # If no equality test specified, the assertion is true if at least one
254
- # element selected.
255
- #
256
- # To perform more than one equality tests, use a hash with the following keys:
257
- # * <tt>:text</tt> - Narrow the selection to elements that have this text
258
- # value (string or regexp).
259
- # * <tt>:html</tt> - Narrow the selection to elements that have this HTML
260
- # content (string or regexp).
261
- # * <tt>:count</tt> - Assertion is true if the number of selected elements
262
- # is equal to this value.
263
- # * <tt>:minimum</tt> - Assertion is true if the number of selected
264
- # elements is at least this value.
265
- # * <tt>:maximum</tt> - Assertion is true if the number of selected
266
- # elements is at most this value.
267
- #
268
- # If the method is called with a block, once all equality tests are
269
- # evaluated the block is called with an array of all matched elements.
270
- #
271
- # # At least one form element
272
- # assert_select "form"
273
- #
274
- # # Form element includes four input fields
275
- # assert_select "form input", 4
276
- #
277
- # # Page title is "Welcome"
278
- # assert_select "title", "Welcome"
279
- #
280
- # # Page title is "Welcome" and there is only one title element
281
- # assert_select "title", {count: 1, text: "Welcome"},
282
- # "Wrong title or more than one title element"
283
- #
284
- # # Page contains no forms
285
- # assert_select "form", false, "This page must contain no forms"
286
- #
287
- # # Test the content and style
288
- # assert_select "body div.header ul.menu"
289
- #
290
- # # Use substitution values
291
- # assert_select "ol>li#?", /item-\d+/
292
- #
293
- # # All input fields in the form have a name
294
- # assert_select "form input" do
295
- # assert_select "[name=?]", /.+/ # Not empty
296
- # end
297
- #
298
- # See also Minitest::Rails::Expectations#must_select
299
- #
300
- # :method: assert_select
301
- # :call-seq: assert_select(*args, &block)
302
-
303
- # Extracts the body of an email and runs nested assertions on it.
304
- #
305
- # You must enable deliveries for this assertion to work, use:
306
- # ActionMailer::Base.perform_deliveries = true
307
- #
308
- # assert_select_email do
309
- # assert_select "h1", "Email alert"
310
- # end
311
- #
312
- # assert_select_email do
313
- # items = assert_select "ol>li"
314
- # items.each do
315
- # # Work with items here...
316
- # end
317
- # end
318
- #
319
- # See also Minitest::Rails::Expectations#must_select_email
320
- #
321
- # :method: assert_select_email
322
- # :call-seq: assert_select_email(&block)
323
-
324
- # Extracts the content of an element, treats it as encoded HTML and runs
325
- # nested assertion on it.
326
- #
327
- # You typically call this method within another assertion to operate on
328
- # all currently selected elements. You can also pass an element or array
329
- # of elements.
330
- #
331
- # The content of each element is un-encoded, and wrapped in the root
332
- # element +encoded+. It then calls the block with all un-encoded elements.
333
- #
334
- # # Selects all bold tags from within the title of an Atom feed's entries (perhaps to nab a section name prefix)
335
- # assert_select "feed[xmlns='http://www.w3.org/2005/Atom']" do
336
- # # Select each entry item and then the title item
337
- # assert_select "entry>title" do
338
- # # Run assertions on the encoded title elements
339
- # assert_select_encoded do
340
- # assert_select "b"
341
- # end
342
- # end
343
- # end
344
- #
345
- #
346
- # # Selects all paragraph tags from within the description of an RSS feed
347
- # assert_select "rss[version=2.0]" do
348
- # # Select description element of each feed item.
349
- # assert_select "channel>item>description" do
350
- # # Run assertions on the encoded elements.
351
- # assert_select_encoded do
352
- # assert_select "p"
353
- # end
354
- # end
355
- # end
356
- #
357
- # See also Minitest::Rails::Expectations#must_select_encoded
358
- #
359
- # :method: assert_select_encoded
360
- # :call-seq: assert_select_encoded(element = nil, &block)
361
-
362
- ##
363
- # Checks that two HTML strings are equivalent. That they contain the same elements and attributes with the associated values.
364
- #
365
- # assert_dom_equal '<a href="http://www.example.com">Apples</a>',
366
- # link_to("Apples", "http://www.example.com")
367
- #
368
- # See also Minitest::Rails::Expectations#must_dom_equal
369
- #
370
- # :method: assert_dom_equal
371
- # :call-seq: assert_dom_equal(expected, actual, message = nil)
372
-
373
- ##
374
- # Checks that two HTML strings are not equivalent. That they do not contain the same elements and attributes with the associated values.
375
- #
376
- # assert_dom_not_equal '<a href="http://www.example.com">Oranges</a>',
377
- # link_to("Apples", "http://www.example.com")
378
- #
379
- # See also Minitest::Rails::Expectations#wont_dom_equal
380
- #
381
- # :method: assert_dom_not_equal
382
- # :call-seq: assert_dom_not_equal(expected, actual, message = nil)
383
-
384
- ##
385
- # Checks that two HTML strings are not equivalent. That they do not contain the same elements and attributes with the associated values.
386
- #
387
- # refute_dom_equal '<a href="http://www.example.com">Oranges</a>',
388
- # link_to("Apples", "http://www.example.com")
389
- #
390
- # See also Minitest::Rails::Expectations#wont_dom_equal
391
- #
392
- # :method: assert_dom_equal
393
- # :call-seq: assert_dom_equal(expected, actual, message = nil)
394
- alias :refute_dom_equal :assert_dom_not_equal
395
- end
396
-
397
- class ActionDispatch::IntegrationTest
398
- ##
399
- # Checks the numeric difference between the return value of an expression as a result of what is evaluated.
400
- #
401
- # assert_difference "User.count", +1 do
402
- # User.create
403
- # end
404
- #
405
- # See also Minitest::Rails::Expectations#must_change
406
- #
407
- # :method: assert_difference
408
- # :call-seq: assert_difference(expression, difference = 1, message = nil, &block)
409
-
410
- ##
411
- # Checks that the numeric result of evaluating an expression is not changed before and after invoking.
412
- #
413
- # assert_no_difference "User.count" do
414
- # User.new
415
- # end
416
- #
417
- # See also Minitest::Rails::Expectations#wont_change
418
- #
419
- # :method: assert_no_difference
420
- # :call-seq: assert_no_difference(expression, message = nil, &block)
421
-
422
- ##
423
- # Checks that the numeric result of evaluating an expression is not changed before and after invoking.
424
- #
425
- # refute_difference "User.count", do
426
- # User.new
427
- # end
428
- #
429
- # See also Minitest::Rails::Expectations#wont_change
430
- #
431
- # :args: expression, message = nil, &block
432
- alias :refute_difference :assert_no_difference
433
-
434
- # Asserts that the response is one of the following types:
435
- #
436
- # * <tt>:success</tt> - Status code was in the 200-299 range
437
- # * <tt>:redirect</tt> - Status code was in the 300-399 range
438
- # * <tt>:missing</tt> - Status code was 404
439
- # * <tt>:error</tt> - Status code was in the 500-599 range
440
- #
441
- # You can also pass an explicit status number like <tt>assert_response(501)</tt>
442
- # or its symbolic equivalent <tt>assert_response(:not_implemented)</tt>.
443
- # See Rack::Utils::SYMBOL_TO_STATUS_CODE for a full list.
444
- #
445
- # # assert that the response was a redirection
446
- # assert_response :redirect
447
- #
448
- # # assert that the response code was status code 401 (unauthorized)
449
- # assert_response 401
450
- #
451
- # See also Minitest::Rails::Expectations#must_respond_with
452
- #
453
- # :method: assert_response
454
- # :call-seq: assert_response(type, message = nil)
455
-
456
- ##
457
- # Assert that the redirection options passed in match those of the redirect called in the latest action.
458
- # This match can be partial, such that <tt>assert_redirected_to(controller: "weblog")</tt> will also
459
- # match the redirection of <tt>redirect_to(controller: "weblog", action: "show")</tt> and so on.
460
- #
461
- # # assert that the redirection was to the "index" action on the WeblogController
462
- # assert_redirected_to controller: "weblog", action: "index"
463
- #
464
- # # assert that the redirection was to the named route login_url
465
- # assert_redirected_to login_url
466
- #
467
- # # assert that the redirection was to the url for @customer
468
- # assert_redirected_to @customer
469
- #
470
- # # asserts that the redirection matches the regular expression
471
- # assert_redirected_to %r(\Ahttp://example.org)
472
- #
473
- # See also Minitest::Rails::Expectations#must_redirect_to
474
- #
475
- # :method: assert_redirected_to
476
- # :call-seq: assert_redirected_to(options = {}, message=nil)
477
-
478
- ##
479
- # Asserts that the provided options can be used to generate the provided path. This is the inverse of +assert_recognizes+.
480
- # The +extras+ parameter is used to tell the request the names and values of additional request parameters that would be in
481
- # a query string. The +message+ parameter allows you to specify a custom error message for assertion failures.
482
- #
483
- # The +defaults+ parameter is unused.
484
- #
485
- # # Asserts that the default action is generated for a route with no action
486
- # assert_generates "/items", controller: "items", action: "index"
487
- #
488
- # # Tests that the list action is properly routed
489
- # assert_generates "/items/list", controller: "items", action: "list"
490
- #
491
- # # Tests the generation of a route with a parameter
492
- # assert_generates "/items/list/1", { controller: "items", action: "list", id: "1" }
493
- #
494
- # # Asserts that the generated route gives us our custom route
495
- # assert_generates "changesets/12", { controller: 'scm', action: 'show_diff', revision: "12" }
496
- #
497
- # See also Minitest::Rails::Expectations#must_route_to
498
- #
499
- # :method: assert_generates
500
- # :call-seq: assert_generates(expected_path, options, defaults={}, extras = {}, message=nil)
501
-
502
- ##
503
- # Asserts that the routing of the given +path+ was handled correctly and that the parsed options (given in the +expected_options+ hash)
504
- # match +path+. Basically, it asserts that \Rails recognizes the route given by +expected_options+.
505
- #
506
- # Pass a hash in the second argument (+path+) to specify the request method. This is useful for routes
507
- # requiring a specific HTTP method. The hash should contain a :path with the incoming request path
508
- # and a :method containing the required HTTP verb.
509
- #
510
- # # assert that POSTing to /items will call the create action on ItemsController
511
- # assert_recognizes({controller: 'items', action: 'create'}, {path: 'items', method: :post})
512
- #
513
- # You can also pass in +extras+ with a hash containing URL parameters that would normally be in the query string. This can be used
514
- # to assert that values in the query string string will end up in the params hash correctly. To test query strings you must use the
515
- # extras argument, appending the query string on the path directly will not work. For example:
516
- #
517
- # # assert that a path of '/items/list/1?view=print' returns the correct options
518
- # assert_recognizes({controller: 'items', action: 'list', id: '1', view: 'print'}, 'items/list/1', { view: "print" })
519
- #
520
- # The +message+ parameter allows you to pass in an error message that is displayed upon failure.
521
- #
522
- # # Check the default route (i.e., the index action)
523
- # assert_recognizes({controller: 'items', action: 'index'}, 'items')
524
- #
525
- # # Test a specific action
526
- # assert_recognizes({controller: 'items', action: 'list'}, 'items/list')
527
- #
528
- # # Test an action with a parameter
529
- # assert_recognizes({controller: 'items', action: 'destroy', id: '1'}, 'items/destroy/1')
530
- #
531
- # # Test a custom route
532
- # assert_recognizes({controller: 'items', action: 'show', id: '1'}, 'view/item1')
533
- #
534
- # See also Minitest::Rails::Expectations#must_route_from
535
- #
536
- # :method: assert_recognizes
537
- # :call-seq: assert_recognizes(expected_options, path, extras={}, msg=nil)
538
-
539
- ##
540
- # Asserts that path and options match both ways; in other words, it verifies that <tt>path</tt> generates
541
- # <tt>options</tt> and then that <tt>options</tt> generates <tt>path</tt>. This essentially combines +assert_recognizes+
542
- # and +assert_generates+ into one step.
543
- #
544
- # The +extras+ hash allows you to specify options that would normally be provided as a query string to the action. The
545
- # +message+ parameter allows you to specify a custom error message to display upon failure.
546
- #
547
- # # Assert a basic route: a controller with the default action (index)
548
- # assert_routing '/home', controller: 'home', action: 'index'
549
- #
550
- # # Test a route generated with a specific controller, action, and parameter (id)
551
- # assert_routing '/entries/show/23', controller: 'entries', action: 'show', id: 23
552
- #
553
- # # Assert a basic route (controller + default action), with an error message if it fails
554
- # assert_routing '/store', { controller: 'store', action: 'index' }, {}, {}, 'Route for store index not generated properly'
555
- #
556
- # # Tests a route, providing a defaults hash
557
- # assert_routing 'controller/action/9', {id: "9", item: "square"}, {controller: "controller", action: "action"}, {}, {item: "square"}
558
- #
559
- # # Tests a route with a HTTP method
560
- # assert_routing({ method: 'put', path: '/product/321' }, { controller: "product", action: "update", id: "321" })
561
- #
562
- # See also Minitest::Rails::Expectations#must_route
563
- #
564
- # :method: assert_routing
565
- # :call-seq: assert_routing(path, options, defaults={}, extras={}, message=nil)
566
-
567
- # An assertion that selects elements and makes one or more equality tests.
568
- #
569
- # If the first argument is an element, selects all matching elements
570
- # starting from (and including) that element and all its children in
571
- # depth-first order.
572
- #
573
- # If no element if specified, calling +assert_select+ selects from the
574
- # response HTML unless +assert_select+ is called from within an +assert_select+ block.
575
- #
576
- # When called with a block +assert_select+ passes an array of selected elements
577
- # to the block. Calling +assert_select+ from the block, with no element specified,
578
- # runs the assertion on the complete set of elements selected by the enclosing assertion.
579
- # Alternatively the array may be iterated through so that +assert_select+ can be called
580
- # separately for each element.
581
- #
582
- #
583
- # ==== Example
584
- # If the response contains two ordered lists, each with four list elements then:
585
- # assert_select "ol" do |elements|
586
- # elements.each do |element|
587
- # assert_select element, "li", 4
588
- # end
589
- # end
590
- #
591
- # will pass, as will:
592
- # assert_select "ol" do
593
- # assert_select "li", 8
594
- # end
595
- #
596
- # The selector may be a CSS selector expression (String), an expression
597
- # with substitution values, or an HTML::Selector object.
598
- #
599
- # === Equality Tests
600
- #
601
- # The equality test may be one of the following:
602
- # * <tt>true</tt> - Assertion is true if at least one element selected.
603
- # * <tt>false</tt> - Assertion is true if no element selected.
604
- # * <tt>String/Regexp</tt> - Assertion is true if the text value of at least
605
- # one element matches the string or regular expression.
606
- # * <tt>Integer</tt> - Assertion is true if exactly that number of
607
- # elements are selected.
608
- # * <tt>Range</tt> - Assertion is true if the number of selected
609
- # elements fit the range.
610
- # If no equality test specified, the assertion is true if at least one
611
- # element selected.
612
- #
613
- # To perform more than one equality tests, use a hash with the following keys:
614
- # * <tt>:text</tt> - Narrow the selection to elements that have this text
615
- # value (string or regexp).
616
- # * <tt>:html</tt> - Narrow the selection to elements that have this HTML
617
- # content (string or regexp).
618
- # * <tt>:count</tt> - Assertion is true if the number of selected elements
619
- # is equal to this value.
620
- # * <tt>:minimum</tt> - Assertion is true if the number of selected
621
- # elements is at least this value.
622
- # * <tt>:maximum</tt> - Assertion is true if the number of selected
623
- # elements is at most this value.
624
- #
625
- # If the method is called with a block, once all equality tests are
626
- # evaluated the block is called with an array of all matched elements.
627
- #
628
- # # At least one form element
629
- # assert_select "form"
630
- #
631
- # # Form element includes four input fields
632
- # assert_select "form input", 4
633
- #
634
- # # Page title is "Welcome"
635
- # assert_select "title", "Welcome"
636
- #
637
- # # Page title is "Welcome" and there is only one title element
638
- # assert_select "title", {count: 1, text: "Welcome"},
639
- # "Wrong title or more than one title element"
640
- #
641
- # # Page contains no forms
642
- # assert_select "form", false, "This page must contain no forms"
643
- #
644
- # # Test the content and style
645
- # assert_select "body div.header ul.menu"
646
- #
647
- # # Use substitution values
648
- # assert_select "ol>li#?", /item-\d+/
649
- #
650
- # # All input fields in the form have a name
651
- # assert_select "form input" do
652
- # assert_select "[name=?]", /.+/ # Not empty
653
- # end
654
- #
655
- # See also Minitest::Rails::Expectations#must_select
656
- #
657
- # :method: assert_select
658
- # :call-seq: assert_select(*args, &block)
659
-
660
- # Extracts the body of an email and runs nested assertions on it.
661
- #
662
- # You must enable deliveries for this assertion to work, use:
663
- # ActionMailer::Base.perform_deliveries = true
664
- #
665
- # assert_select_email do
666
- # assert_select "h1", "Email alert"
667
- # end
668
- #
669
- # assert_select_email do
670
- # items = assert_select "ol>li"
671
- # items.each do
672
- # # Work with items here...
673
- # end
674
- # end
675
- #
676
- # See also Minitest::Rails::Expectations#must_select_email
677
- #
678
- # :method: assert_select_email
679
- # :call-seq: assert_select_email(&block)
680
-
681
- # Extracts the content of an element, treats it as encoded HTML and runs
682
- # nested assertion on it.
683
- #
684
- # You typically call this method within another assertion to operate on
685
- # all currently selected elements. You can also pass an element or array
686
- # of elements.
687
- #
688
- # The content of each element is un-encoded, and wrapped in the root
689
- # element +encoded+. It then calls the block with all un-encoded elements.
690
- #
691
- # # Selects all bold tags from within the title of an Atom feed's entries (perhaps to nab a section name prefix)
692
- # assert_select "feed[xmlns='http://www.w3.org/2005/Atom']" do
693
- # # Select each entry item and then the title item
694
- # assert_select "entry>title" do
695
- # # Run assertions on the encoded title elements
696
- # assert_select_encoded do
697
- # assert_select "b"
698
- # end
699
- # end
700
- # end
701
- #
702
- #
703
- # # Selects all paragraph tags from within the description of an RSS feed
704
- # assert_select "rss[version=2.0]" do
705
- # # Select description element of each feed item.
706
- # assert_select "channel>item>description" do
707
- # # Run assertions on the encoded elements.
708
- # assert_select_encoded do
709
- # assert_select "p"
710
- # end
711
- # end
712
- # end
713
- #
714
- # See also Minitest::Rails::Expectations#must_select_encoded
715
- #
716
- # :method: assert_select_encoded
717
- # :call-seq: assert_select_encoded(element = nil, &block)
718
-
719
- ##
720
- # Checks that two HTML strings are equivalent. That they contain the same elements and attributes with the associated values.
721
- #
722
- # assert_dom_equal '<a href="http://www.example.com">Apples</a>',
723
- # link_to("Apples", "http://www.example.com")
724
- #
725
- # See also Minitest::Rails::Expectations#must_dom_equal
726
- #
727
- # :method: assert_dom_equal
728
- # :call-seq: assert_dom_equal(expected, actual, message = nil)
729
-
730
- ##
731
- # Checks that two HTML strings are not equivalent. That they do not contain the same elements and attributes with the associated values.
732
- #
733
- # assert_dom_not_equal '<a href="http://www.example.com">Oranges</a>',
734
- # link_to("Apples", "http://www.example.com")
735
- #
736
- # See also Minitest::Rails::Expectations#wont_dom_equal
737
- #
738
- # :method: assert_dom_not_equal
739
- # :call-seq: assert_dom_not_equal(expected, actual, message = nil)
740
-
741
- ##
742
- # Checks that two HTML strings are not equivalent. That they do not contain the same elements and attributes with the associated values.
743
- #
744
- # refute_dom_equal '<a href="http://www.example.com">Oranges</a>',
745
- # link_to("Apples", "http://www.example.com")
746
- #
747
- # See also Minitest::Rails::Expectations#wont_dom_equal
748
- #
749
- # :method: assert_dom_equal
750
- # :call-seq: assert_dom_equal(expected, actual, message = nil)
751
- alias :refute_dom_equal :assert_dom_not_equal
752
- end
753
-
754
- if defined? ActiveJob
755
- class ActiveJob::TestCase
756
- # Asserts that the number of enqueued jobs matches the given number.
757
- #
758
- # def test_jobs
759
- # assert_enqueued_jobs 0
760
- # HelloJob.perform_later('david')
761
- # assert_enqueued_jobs 1
762
- # HelloJob.perform_later('abdelkader')
763
- # assert_enqueued_jobs 2
764
- # end
765
- #
766
- # If a block is passed, that block should cause the specified number of
767
- # jobs to be enqueued.
768
- #
769
- # def test_jobs_again
770
- # assert_enqueued_jobs 1 do
771
- # HelloJob.perform_later('cristian')
772
- # end
773
- #
774
- # assert_enqueued_jobs 2 do
775
- # HelloJob.perform_later('aaron')
776
- # HelloJob.perform_later('rafael')
777
- # end
778
- # end
779
- #
780
- # See also Minitest::Rails::Expectations#must_enqueue_jobs
781
- #
782
- # :method: assert_enqueued_jobs
783
- # :call-seq: assert_enqueued_jobs(number)
784
-
785
- ##
786
- # Asserts that no jobs have been enqueued.
787
- #
788
- # def test_jobs
789
- # assert_no_enqueued_jobs
790
- # HelloJob.perform_later('jeremy')
791
- # assert_enqueued_jobs 1
792
- # end
793
- #
794
- # If a block is passed, that block should not cause any job to be enqueued.
795
- #
796
- # def test_jobs_again
797
- # assert_no_enqueued_jobs do
798
- # # No job should be enqueued from this block
799
- # end
800
- # end
801
- #
802
- # Note: This assertion is simply a shortcut for:
803
- #
804
- # assert_enqueued_jobs 0, &block
805
- #
806
- # See also Minitest::Rails::Expectations#wont_enqueue_jobs
807
- #
808
- # :method: assert_no_enqueued_jobs
809
- # :call-seq: assert_no_enqueued_jobs(number)
810
-
811
- ##
812
- # Asserts that the number of performed jobs matches the given number.
813
- # If no block is passed, <tt>perform_enqueued_jobs</tt>d
814
- # must be called around the job call.
815
- #
816
- # def test_jobs
817
- # assert_performed_jobs 0
818
- #
819
- # perform_enqueued_jobs do
820
- # HelloJob.perform_later('xavier')
821
- # end
822
- # assert_performed_jobs 1
823
- #
824
- # perform_enqueued_jobs do
825
- # HelloJob.perform_later('yves')
826
- # assert_performed_jobs 2
827
- # end
828
- # end
829
- #
830
- # If a block is passed, that block should cause the specified number of
831
- # jobs to be performed.
832
- #
833
- # def test_jobs_again
834
- # assert_performed_jobs 1 do
835
- # HelloJob.perform_later('robin')
836
- # end
837
- #
838
- # assert_performed_jobs 2 do
839
- # HelloJob.perform_later('carlos')
840
- # HelloJob.perform_later('sean')
841
- # end
842
- # end
843
- #
844
- # See also Minitest::Rails::Expectations#must_perform_jobs
845
- #
846
- # :method: assert_performed_jobs
847
- # :call-seq: assert_performed_jobs(number)
848
-
849
- ##
850
- # Asserts that no jobs have been performed.
851
- #
852
- # def test_jobs
853
- # assert_no_performed_jobs
854
- #
855
- # perform_enqueued_jobs do
856
- # HelloJob.perform_later('matthew')
857
- # assert_performed_jobs 1
858
- # end
859
- # end
860
- #
861
- # If a block is passed, that block should not cause any job to be performed.
862
- #
863
- # def test_jobs_again
864
- # assert_no_performed_jobs do
865
- # # No job should be performed from this block
866
- # end
867
- # end
868
- #
869
- # Note: This assertion is simply a shortcut for:
870
- #
871
- # assert_performed_jobs 0, &block
872
- #
873
- # See also Minitest::Rails::Expectations#wont_perform_jobs
874
- #
875
- # :method: assert_no_performed_jobs
876
- # :call-seq: assert_no_performed_jobs(number)
877
-
878
- ##
879
- # Asserts that the job passed in the block has been enqueued with the given arguments.
880
- #
881
- # def test_assert_enqueued_with
882
- # assert_enqueued_with(job: MyJob, args: [1,2,3], queue: 'low') do
883
- # MyJob.perform_later(1,2,3)
884
- # end
885
- # end
886
- #
887
- # See also Minitest::Rails::Expectations#must_enqueue_with
888
- #
889
- # :method: assert_enqueued_with
890
- # :call-seq: assert_enqueued_with(args)
891
-
892
- ##
893
- # Asserts that the job passed in the block has been performed with the given arguments.
894
- #
895
- # def test_assert_performed_with
896
- # assert_performed_with(job: MyJob, args: [1,2,3], queue: 'high') do
897
- # MyJob.perform_later(1,2,3)
898
- # end
899
- # end
900
- #
901
- # See also Minitest::Rails::Expectations#must_perform_with
902
- #
903
- # :method: assert_performed_with
904
- # :call-seq: assert_performed_with(args)
905
- end
906
- end
1
+ require "minitest/rails/assertions/active_support"
2
+ require "minitest/rails/assertions/action_view"
3
+ require "minitest/rails/assertions/action_dispatch"
4
+ require "minitest/rails/assertions/active_job" if defined? ActiveJob
5
+ require "minitest/rails/assertions/action_mailer" if defined? ActionMailer