rspec-rails 1.3.2 → 7.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (268) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data/.document +4 -6
  4. data/.yardopts +11 -0
  5. data/Capybara.md +28 -0
  6. data/Changelog.md +1343 -0
  7. data/LICENSE.md +25 -0
  8. data/README.md +383 -0
  9. data/lib/generators/rspec/channel/channel_generator.rb +12 -0
  10. data/lib/generators/rspec/channel/templates/channel_spec.rb.erb +7 -0
  11. data/lib/generators/rspec/controller/controller_generator.rb +51 -0
  12. data/lib/generators/rspec/controller/templates/controller_spec.rb +16 -0
  13. data/lib/generators/rspec/controller/templates/request_spec.rb +19 -0
  14. data/lib/generators/rspec/controller/templates/routing_spec.rb +13 -0
  15. data/lib/generators/rspec/controller/templates/view_spec.rb +5 -0
  16. data/lib/generators/rspec/feature/feature_generator.rb +29 -0
  17. data/lib/generators/rspec/feature/templates/feature_singular_spec.rb +5 -0
  18. data/lib/generators/rspec/feature/templates/feature_spec.rb +5 -0
  19. data/lib/generators/rspec/generator/generator_generator.rb +24 -0
  20. data/lib/generators/rspec/generator/templates/generator_spec.rb +5 -0
  21. data/lib/generators/rspec/helper/helper_generator.rb +16 -0
  22. data/lib/generators/rspec/helper/templates/helper_spec.rb +17 -0
  23. data/lib/generators/rspec/install/install_generator.rb +80 -0
  24. data/lib/generators/rspec/install/templates/spec/rails_helper.rb +89 -0
  25. data/lib/generators/rspec/job/job_generator.rb +13 -0
  26. data/lib/generators/rspec/job/templates/job_spec.rb.erb +7 -0
  27. data/lib/generators/rspec/mailbox/mailbox_generator.rb +14 -0
  28. data/lib/generators/rspec/mailbox/templates/mailbox_spec.rb.erb +7 -0
  29. data/lib/generators/rspec/mailer/mailer_generator.rb +30 -0
  30. data/lib/generators/rspec/mailer/templates/fixture +3 -0
  31. data/lib/generators/rspec/mailer/templates/mailer_spec.rb +25 -0
  32. data/lib/generators/rspec/mailer/templates/preview.rb +13 -0
  33. data/lib/generators/rspec/model/model_generator.rb +37 -0
  34. data/lib/generators/rspec/model/templates/fixtures.yml +19 -0
  35. data/lib/generators/rspec/model/templates/model_spec.rb +7 -0
  36. data/lib/generators/rspec/request/request_generator.rb +17 -0
  37. data/lib/generators/rspec/request/templates/request_spec.rb +10 -0
  38. data/lib/generators/rspec/scaffold/scaffold_generator.rb +136 -0
  39. data/lib/generators/rspec/scaffold/templates/api_controller_spec.rb +129 -0
  40. data/lib/generators/rspec/scaffold/templates/api_request_spec.rb +131 -0
  41. data/lib/generators/rspec/scaffold/templates/controller_spec.rb +145 -0
  42. data/lib/generators/rspec/scaffold/templates/edit_spec.rb +27 -0
  43. data/lib/generators/rspec/scaffold/templates/index_spec.rb +26 -0
  44. data/lib/generators/rspec/scaffold/templates/new_spec.rb +22 -0
  45. data/lib/generators/rspec/scaffold/templates/request_spec.rb +138 -0
  46. data/lib/generators/rspec/scaffold/templates/routing_spec.rb +46 -0
  47. data/lib/generators/rspec/scaffold/templates/show_spec.rb +21 -0
  48. data/lib/generators/rspec/system/system_generator.rb +24 -0
  49. data/lib/generators/rspec/system/templates/system_spec.rb +9 -0
  50. data/lib/generators/rspec/view/templates/view_spec.rb +5 -0
  51. data/lib/generators/rspec/view/view_generator.rb +22 -0
  52. data/lib/generators/rspec.rb +56 -0
  53. data/lib/rspec/rails/active_record.rb +25 -0
  54. data/lib/rspec/rails/adapters.rb +196 -0
  55. data/lib/rspec/rails/configuration.rb +222 -0
  56. data/lib/rspec/rails/example/channel_example_group.rb +93 -0
  57. data/lib/rspec/rails/example/controller_example_group.rb +217 -0
  58. data/lib/rspec/rails/example/feature_example_group.rb +53 -0
  59. data/lib/rspec/rails/example/helper_example_group.rb +42 -0
  60. data/lib/rspec/rails/example/job_example_group.rb +23 -0
  61. data/lib/rspec/rails/example/mailbox_example_group.rb +80 -0
  62. data/lib/rspec/rails/example/mailer_example_group.rb +38 -0
  63. data/lib/rspec/rails/example/model_example_group.rb +11 -0
  64. data/lib/rspec/rails/example/rails_example_group.rb +23 -0
  65. data/lib/rspec/rails/example/request_example_group.rb +27 -0
  66. data/lib/rspec/rails/example/routing_example_group.rb +61 -0
  67. data/lib/rspec/rails/example/system_example_group.rb +180 -0
  68. data/lib/rspec/rails/example/view_example_group.rb +214 -0
  69. data/lib/rspec/rails/example.rb +13 -0
  70. data/lib/rspec/rails/extensions/active_record/proxy.rb +11 -0
  71. data/lib/rspec/rails/extensions.rb +1 -0
  72. data/lib/rspec/rails/feature_check.rb +51 -0
  73. data/lib/rspec/rails/file_fixture_support.rb +18 -0
  74. data/lib/rspec/rails/fixture_file_upload_support.rb +45 -0
  75. data/lib/rspec/rails/fixture_support.rb +88 -0
  76. data/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb +173 -0
  77. data/lib/rspec/rails/matchers/action_cable/have_streams.rb +58 -0
  78. data/lib/rspec/rails/matchers/action_cable.rb +65 -0
  79. data/lib/rspec/rails/matchers/action_mailbox.rb +73 -0
  80. data/lib/rspec/rails/matchers/active_job.rb +517 -0
  81. data/lib/rspec/rails/matchers/base_matcher.rb +179 -0
  82. data/lib/rspec/rails/matchers/be_a_new.rb +83 -0
  83. data/lib/rspec/rails/matchers/be_new_record.rb +30 -0
  84. data/lib/rspec/rails/matchers/be_valid.rb +49 -0
  85. data/lib/rspec/rails/matchers/have_enqueued_mail.rb +258 -0
  86. data/lib/rspec/rails/matchers/have_http_status.rb +381 -0
  87. data/lib/rspec/rails/matchers/have_rendered.rb +64 -0
  88. data/lib/rspec/rails/matchers/redirect_to.rb +38 -0
  89. data/lib/rspec/rails/matchers/relation_match_array.rb +3 -0
  90. data/lib/rspec/rails/matchers/routing_matchers.rb +125 -0
  91. data/lib/rspec/rails/matchers/send_email.rb +122 -0
  92. data/lib/rspec/rails/matchers.rb +36 -0
  93. data/lib/rspec/rails/tasks/rspec.rake +49 -0
  94. data/lib/rspec/rails/vendor/capybara.rb +32 -0
  95. data/lib/rspec/rails/version.rb +9 -0
  96. data/lib/rspec/rails/view_assigns.rb +27 -0
  97. data/lib/rspec/rails/view_path_builder.rb +29 -0
  98. data/lib/rspec/rails/view_rendering.rb +166 -0
  99. data/lib/rspec/rails/view_spec_methods.rb +56 -0
  100. data/lib/rspec/rails.rb +18 -0
  101. data/lib/rspec-rails.rb +97 -0
  102. data.tar.gz.sig +0 -0
  103. metadata +307 -261
  104. metadata.gz.sig +0 -0
  105. data/Contribute.rdoc +0 -4
  106. data/History.rdoc +0 -302
  107. data/License.txt +0 -33
  108. data/Manifest.txt +0 -165
  109. data/README.rdoc +0 -45
  110. data/Rakefile +0 -72
  111. data/TODO.txt +0 -17
  112. data/Upgrade.rdoc +0 -148
  113. data/generators/integration_spec/integration_spec_generator.rb +0 -10
  114. data/generators/integration_spec/templates/integration_spec.rb +0 -4
  115. data/generators/rspec/CHANGES +0 -1
  116. data/generators/rspec/rspec_generator.rb +0 -72
  117. data/generators/rspec/templates/previous_failures.txt +0 -0
  118. data/generators/rspec/templates/rcov.opts +0 -2
  119. data/generators/rspec/templates/rspec.rake +0 -144
  120. data/generators/rspec/templates/script/autospec +0 -6
  121. data/generators/rspec/templates/script/spec +0 -10
  122. data/generators/rspec/templates/spec.opts +0 -4
  123. data/generators/rspec/templates/spec_helper.rb +0 -54
  124. data/generators/rspec_controller/USAGE +0 -33
  125. data/generators/rspec_controller/rspec_controller_generator.rb +0 -47
  126. data/generators/rspec_controller/templates/controller_spec.rb +0 -25
  127. data/generators/rspec_controller/templates/helper_spec.rb +0 -11
  128. data/generators/rspec_controller/templates/view_spec.rb +0 -12
  129. data/generators/rspec_default_values.rb +0 -28
  130. data/generators/rspec_model/USAGE +0 -18
  131. data/generators/rspec_model/rspec_model_generator.rb +0 -35
  132. data/generators/rspec_model/templates/model_spec.rb +0 -13
  133. data/generators/rspec_scaffold/rspec_scaffold_generator.rb +0 -154
  134. data/generators/rspec_scaffold/templates/controller_spec.rb +0 -131
  135. data/generators/rspec_scaffold/templates/edit_erb_spec.rb +0 -25
  136. data/generators/rspec_scaffold/templates/helper_spec.rb +0 -11
  137. data/generators/rspec_scaffold/templates/index_erb_spec.rb +0 -27
  138. data/generators/rspec_scaffold/templates/new_erb_spec.rb +0 -25
  139. data/generators/rspec_scaffold/templates/routing_spec.rb +0 -33
  140. data/generators/rspec_scaffold/templates/show_erb_spec.rb +0 -22
  141. data/init.rb +0 -9
  142. data/lib/autotest/discover.rb +0 -5
  143. data/lib/autotest/rails_rspec.rb +0 -76
  144. data/lib/spec/rails/example/assigns_hash_proxy.rb +0 -39
  145. data/lib/spec/rails/example/controller_example_group.rb +0 -285
  146. data/lib/spec/rails/example/cookies_proxy.rb +0 -29
  147. data/lib/spec/rails/example/functional_example_group.rb +0 -106
  148. data/lib/spec/rails/example/helper_example_group.rb +0 -153
  149. data/lib/spec/rails/example/integration_example_group.rb +0 -16
  150. data/lib/spec/rails/example/model_example_group.rb +0 -15
  151. data/lib/spec/rails/example/render_observer.rb +0 -80
  152. data/lib/spec/rails/example/routing_example_group.rb +0 -13
  153. data/lib/spec/rails/example/routing_helpers.rb +0 -66
  154. data/lib/spec/rails/example/view_example_group.rb +0 -199
  155. data/lib/spec/rails/example.rb +0 -48
  156. data/lib/spec/rails/extensions/action_controller/rescue.rb +0 -42
  157. data/lib/spec/rails/extensions/action_controller/test_case.rb +0 -16
  158. data/lib/spec/rails/extensions/action_controller/test_response.rb +0 -21
  159. data/lib/spec/rails/extensions/action_view/base.rb +0 -33
  160. data/lib/spec/rails/extensions/active_record/base.rb +0 -45
  161. data/lib/spec/rails/extensions/active_support/test_case.rb +0 -7
  162. data/lib/spec/rails/extensions/spec/matchers/have.rb +0 -23
  163. data/lib/spec/rails/extensions/spec/runner/configuration.rb +0 -44
  164. data/lib/spec/rails/extensions.rb +0 -11
  165. data/lib/spec/rails/interop/testcase.rb +0 -14
  166. data/lib/spec/rails/matchers/ar_be_valid.rb +0 -27
  167. data/lib/spec/rails/matchers/assert_select.rb +0 -180
  168. data/lib/spec/rails/matchers/change.rb +0 -13
  169. data/lib/spec/rails/matchers/have_text.rb +0 -57
  170. data/lib/spec/rails/matchers/include_text.rb +0 -54
  171. data/lib/spec/rails/matchers/redirect_to.rb +0 -126
  172. data/lib/spec/rails/matchers/render_template.rb +0 -129
  173. data/lib/spec/rails/matchers/route_to.rb +0 -149
  174. data/lib/spec/rails/matchers.rb +0 -32
  175. data/lib/spec/rails/mocks.rb +0 -136
  176. data/lib/spec/rails/version.rb +0 -16
  177. data/lib/spec/rails.rb +0 -26
  178. data/spec/autotest/mappings_spec.rb +0 -86
  179. data/spec/rails_suite.rb +0 -7
  180. data/spec/resources/controllers/action_view_base_spec_controller.rb +0 -2
  181. data/spec/resources/controllers/application.rb +0 -9
  182. data/spec/resources/controllers/controller_spec_controller.rb +0 -127
  183. data/spec/resources/controllers/example.txt +0 -1
  184. data/spec/resources/controllers/redirect_spec_controller.rb +0 -70
  185. data/spec/resources/controllers/render_spec_controller.rb +0 -34
  186. data/spec/resources/controllers/rjs_spec_controller.rb +0 -58
  187. data/spec/resources/helpers/addition_helper.rb +0 -5
  188. data/spec/resources/helpers/explicit_helper.rb +0 -46
  189. data/spec/resources/helpers/more_explicit_helper.rb +0 -5
  190. data/spec/resources/helpers/plugin_application_helper.rb +0 -6
  191. data/spec/resources/helpers/view_spec_helper.rb +0 -13
  192. data/spec/resources/models/animal.rb +0 -4
  193. data/spec/resources/models/person.rb +0 -18
  194. data/spec/resources/models/thing.rb +0 -3
  195. data/spec/resources/views/controller_spec/_partial.html.erb +0 -0
  196. data/spec/resources/views/controller_spec/action_setting_flash_after_session_reset.html.erb +0 -1
  197. data/spec/resources/views/controller_spec/action_setting_flash_before_session_reset.html.erb +0 -1
  198. data/spec/resources/views/controller_spec/action_setting_the_assigns_hash.html.erb +0 -0
  199. data/spec/resources/views/controller_spec/action_with_errors_in_template.html.erb +0 -1
  200. data/spec/resources/views/controller_spec/action_with_template.html.erb +0 -1
  201. data/spec/resources/views/layouts/application.html.erb +0 -0
  202. data/spec/resources/views/layouts/simple.html.erb +0 -0
  203. data/spec/resources/views/objects/_object.html.erb +0 -1
  204. data/spec/resources/views/render_spec/_a_partial.html.erb +0 -0
  205. data/spec/resources/views/render_spec/action_with_alternate_layout.html.erb +0 -0
  206. data/spec/resources/views/render_spec/some_action.html.erb +0 -0
  207. data/spec/resources/views/render_spec/some_action.js.rjs +0 -1
  208. data/spec/resources/views/rjs_spec/_replacement_partial.html.erb +0 -1
  209. data/spec/resources/views/rjs_spec/hide_div.js.rjs +0 -1
  210. data/spec/resources/views/rjs_spec/hide_page_element.js.rjs +0 -1
  211. data/spec/resources/views/rjs_spec/insert_html.js.rjs +0 -1
  212. data/spec/resources/views/rjs_spec/replace.js.rjs +0 -1
  213. data/spec/resources/views/rjs_spec/replace_html.js.rjs +0 -1
  214. data/spec/resources/views/rjs_spec/replace_html_with_partial.js.rjs +0 -1
  215. data/spec/resources/views/rjs_spec/visual_effect.js.rjs +0 -1
  216. data/spec/resources/views/rjs_spec/visual_toggle_effect.js.rjs +0 -1
  217. data/spec/resources/views/tag_spec/no_tags.html.erb +0 -1
  218. data/spec/resources/views/tag_spec/single_div_with_no_attributes.html.erb +0 -1
  219. data/spec/resources/views/tag_spec/single_div_with_one_attribute.html.erb +0 -1
  220. data/spec/resources/views/view_spec/_partial.html.erb +0 -2
  221. data/spec/resources/views/view_spec/_partial_used_twice.html.erb +0 -0
  222. data/spec/resources/views/view_spec/_partial_with_local_variable.html.erb +0 -1
  223. data/spec/resources/views/view_spec/_partial_with_sub_partial.html.erb +0 -1
  224. data/spec/resources/views/view_spec/_spacer.html.erb +0 -1
  225. data/spec/resources/views/view_spec/accessor.html.erb +0 -6
  226. data/spec/resources/views/view_spec/block_helper.html.erb +0 -3
  227. data/spec/resources/views/view_spec/entry_form.html.erb +0 -2
  228. data/spec/resources/views/view_spec/explicit_helper.html.erb +0 -2
  229. data/spec/resources/views/view_spec/foo/show.html.erb +0 -1
  230. data/spec/resources/views/view_spec/implicit_helper.html.erb +0 -2
  231. data/spec/resources/views/view_spec/multiple_helpers.html.erb +0 -3
  232. data/spec/resources/views/view_spec/path_params.html.erb +0 -1
  233. data/spec/resources/views/view_spec/should_not_receive.html.erb +0 -3
  234. data/spec/resources/views/view_spec/template_with_partial.html.erb +0 -5
  235. data/spec/resources/views/view_spec/template_with_partial_using_collection.html.erb +0 -3
  236. data/spec/resources/views/view_spec/template_with_partial_with_array.html.erb +0 -1
  237. data/spec/resources/views/view_spec/view_helpers.html.erb +0 -1
  238. data/spec/spec/rails/example/assigns_hash_proxy_spec.rb +0 -109
  239. data/spec/spec/rails/example/configuration_spec.rb +0 -65
  240. data/spec/spec/rails/example/controller_example_group_spec.rb +0 -307
  241. data/spec/spec/rails/example/controller_isolation_spec.rb +0 -75
  242. data/spec/spec/rails/example/cookies_proxy_spec.rb +0 -87
  243. data/spec/spec/rails/example/error_handling_spec.rb +0 -90
  244. data/spec/spec/rails/example/example_group_factory_spec.rb +0 -112
  245. data/spec/spec/rails/example/helper_example_group_spec.rb +0 -233
  246. data/spec/spec/rails/example/model_example_group_spec.rb +0 -32
  247. data/spec/spec/rails/example/routing_example_group_spec.rb +0 -10
  248. data/spec/spec/rails/example/shared_routing_example_group_examples.rb +0 -237
  249. data/spec/spec/rails/example/test_unit_assertion_accessibility_spec.rb +0 -33
  250. data/spec/spec/rails/example/view_example_group_spec.rb +0 -346
  251. data/spec/spec/rails/extensions/action_view_base_spec.rb +0 -74
  252. data/spec/spec/rails/extensions/active_record_spec.rb +0 -14
  253. data/spec/spec/rails/interop/testcase_spec.rb +0 -70
  254. data/spec/spec/rails/matchers/ar_be_valid_spec.rb +0 -19
  255. data/spec/spec/rails/matchers/assert_select_spec.rb +0 -835
  256. data/spec/spec/rails/matchers/errors_on_spec.rb +0 -37
  257. data/spec/spec/rails/matchers/have_text_spec.rb +0 -69
  258. data/spec/spec/rails/matchers/include_text_spec.rb +0 -62
  259. data/spec/spec/rails/matchers/redirect_to_spec.rb +0 -253
  260. data/spec/spec/rails/matchers/render_template_spec.rb +0 -208
  261. data/spec/spec/rails/matchers/should_change_spec.rb +0 -15
  262. data/spec/spec/rails/mocks/ar_classes.rb +0 -10
  263. data/spec/spec/rails/mocks/mock_model_spec.rb +0 -109
  264. data/spec/spec/rails/mocks/stub_model_spec.rb +0 -80
  265. data/spec/spec/rails/sample_modified_fixture.rb +0 -8
  266. data/spec/spec/rails/sample_spec.rb +0 -8
  267. data/spec/spec/rails/spec_spec.rb +0 -11
  268. data/spec/spec_helper.rb +0 -78
data/LICENSE.md ADDED
@@ -0,0 +1,25 @@
1
+ The MIT License (MIT)
2
+ =====================
3
+
4
+ * Copyright © 2015 David Chelimsky, Aaron Kromer
5
+ * Copyright © 2012 David Chelimsky, Andy Lindeman
6
+ * Copyright © 2006 David Chelimsky, The RSpec Development Team
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining
9
+ a copy of this software and associated documentation files (the
10
+ "Software"), to deal in the Software without restriction, including
11
+ without limitation the rights to use, copy, modify, merge, publish,
12
+ distribute, sublicense, and/or sell copies of the Software, and to
13
+ permit persons to whom the Software is furnished to do so, subject to
14
+ the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be
17
+ included in all copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
23
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,383 @@
1
+ # rspec-rails [![Code Climate][]][code-climate] [![Gem Version][]][gem-version]
2
+
3
+ `rspec-rails` brings the [RSpec][] testing framework to [Ruby on Rails][]
4
+ as a drop-in alternative to its default testing framework, Minitest.
5
+
6
+ In RSpec, tests are not just scripts that verify your application code.
7
+ They’re also specifications (or _specs,_ for short):
8
+ detailed explanations of how the application is supposed to behave,
9
+ expressed in plain English.
10
+
11
+ According to [RSpec Rails new versioning strategy][] use:
12
+ * **[`rspec-rails` 7.x][]** for Rails 7.x.
13
+ * **[`rspec-rails` 6.x][]** for Rails 6.1, 7.0 or 7.1.
14
+ * **[`rspec-rails` 5.x][]** for Rails 5.2 or 6.x.
15
+ * **[`rspec-rails` 4.x][]** for Rails from 5.x or 6.x.
16
+ * **[`rspec-rails` 3.x][]** for Rails earlier than 5.0.
17
+ * **[`rspec-rails` 1.x][]** for Rails 2.x.
18
+
19
+ [Code Climate]: https://codeclimate.com/github/rspec/rspec-rails.svg
20
+ [code-climate]: https://codeclimate.com/github/rspec/rspec-rails
21
+ [Gem Version]: https://badge.fury.io/rb/rspec-rails.svg
22
+ [gem-version]: https://badge.fury.io/rb/rspec-rails
23
+ [RSpec]: https://rspec.info/
24
+ [Ruby on Rails]: https://rubyonrails.org/
25
+ [`rspec-rails` 1.x]: https://github.com/dchelimsky/rspec-rails
26
+ [`rspec-rails` 3.x]: https://github.com/rspec/rspec-rails/tree/3-9-maintenance
27
+ [`rspec-rails` 4.x]: https://github.com/rspec/rspec-rails/tree/4-1-maintenance
28
+ [`rspec-rails` 5.x]: https://github.com/rspec/rspec-rails/tree/5-1-maintenance
29
+ [`rspec-rails` 6.x]: https://github.com/rspec/rspec-rails/tree/6-1-maintenance
30
+ [`rspec-rails` 7.x]: https://github.com/rspec/rspec-rails/tree/7-0-maintenance
31
+ [RSpec Rails new versioning strategy]: https://github.com/rspec/rspec-rails/blob/main/rfcs/versioning-strategy.md
32
+
33
+ ## Installation
34
+
35
+ **IMPORTANT** This README / branch refers to the 7.0.x stable release series, only bugfixes from this series will
36
+ be added here. See the [`main` branch on Github](https://github.com/rspec/rspec-rails/tree/main) if you want or
37
+ require the latest unstable features.
38
+
39
+ 1. Add `rspec-rails` to **both** the `:development` and `:test` groups
40
+ of your app’s `Gemfile`:
41
+
42
+ ```ruby
43
+ # Run against this stable release
44
+ group :development, :test do
45
+ gem 'rspec-rails', '~> 7.0.0'
46
+ end
47
+
48
+ # Or, run against the main branch
49
+ # (requires main-branch versions of all related RSpec libraries)
50
+ group :development, :test do
51
+ %w[rspec-core rspec-expectations rspec-mocks rspec-rails rspec-support].each do |lib|
52
+ gem lib, git: "https://github.com/rspec/#{lib}.git", branch: 'main'
53
+ end
54
+ end
55
+ ```
56
+
57
+ (Adding it to the `:development` group is not strictly necessary,
58
+ but without it, generators and rake tasks must be preceded by `RAILS_ENV=test`.)
59
+
60
+ 2. Then, in your project directory:
61
+
62
+ ```sh
63
+ # Download and install
64
+ $ bundle install
65
+
66
+ # Generate boilerplate configuration files
67
+ # (check the comments in each generated file for more information)
68
+ $ rails generate rspec:install
69
+ create .rspec
70
+ create spec
71
+ create spec/spec_helper.rb
72
+ create spec/rails_helper.rb
73
+ ```
74
+
75
+ ## Upgrading
76
+
77
+ If your project is already using an older version of `rspec-rails`,
78
+ upgrade to the latest version with:
79
+
80
+ ```sh
81
+ $ bundle update rspec-rails
82
+ ```
83
+
84
+ RSpec follows [semantic versioning](https://semver.org/),
85
+ which means that “major version” upgrades (_e.g.,_ 2.x → 3.x)
86
+ come with **breaking changes**.
87
+ If you’re upgrading from version 2.x or below,
88
+ read the [`rspec-rails` upgrade notes][] to find out what to watch out for.
89
+
90
+ Be sure to check the general [RSpec upgrade notes][] as well.
91
+
92
+ [`rspec-rails` upgrade notes]: https://rspec.info/features/7-0/rspec-rails/upgrade
93
+ [RSpec upgrade notes]: https://rspec.info/upgrading-from-rspec-2/
94
+
95
+ ## Usage
96
+
97
+ ### Creating boilerplate specs with `rails generate`
98
+
99
+ ```sh
100
+ # RSpec hooks into built-in generators
101
+ $ rails generate model user
102
+ invoke active_record
103
+ create db/migrate/20181017040312_create_users.rb
104
+ create app/models/user.rb
105
+ invoke rspec
106
+ create spec/models/user_spec.rb
107
+
108
+ # RSpec also provides its own spec file generators
109
+ $ rails generate rspec:model user
110
+ create spec/models/user_spec.rb
111
+
112
+ # List all RSpec generators
113
+ $ rails generate --help | grep rspec
114
+ ```
115
+
116
+ ### Running specs
117
+
118
+ ```sh
119
+ # Default: Run all spec files (i.e., those matching spec/**/*_spec.rb)
120
+ $ bundle exec rspec
121
+
122
+ # Run all spec files in a single directory (recursively)
123
+ $ bundle exec rspec spec/models
124
+
125
+ # Run a single spec file
126
+ $ bundle exec rspec spec/controllers/accounts_controller_spec.rb
127
+
128
+ # Run a single example from a spec file (by line number)
129
+ $ bundle exec rspec spec/controllers/accounts_controller_spec.rb:8
130
+
131
+ # See all options for running specs
132
+ $ bundle exec rspec --help
133
+ ```
134
+
135
+ **Optional:** If `bundle exec rspec` is too verbose for you,
136
+ you can generate a binstub at `bin/rspec` and use that instead:
137
+
138
+ ```sh
139
+ $ bundle binstubs rspec-core
140
+ ```
141
+
142
+ ## RSpec DSL Basics (or, how do I write a spec?)
143
+
144
+ In RSpec, application behavior is described
145
+ **first in (almost) plain English, then again in test code**, like so:
146
+
147
+ ```ruby
148
+ RSpec.describe 'Post' do #
149
+ context 'before publication' do # (almost) plain English
150
+ it 'cannot have comments' do #
151
+ expect { Post.create.comments.create! }.to raise_error(ActiveRecord::RecordInvalid) # test code
152
+ end
153
+ end
154
+ end
155
+ ```
156
+
157
+ Running `rspec` will execute this test code,
158
+ and then use the plain-English descriptions
159
+ to generate a report of where the application
160
+ conforms to (or fails to meet) the spec:
161
+
162
+ ```
163
+ $ rspec --format documentation spec/models/post_spec.rb
164
+
165
+ Post
166
+ before publication
167
+ cannot have comments
168
+
169
+ Failures:
170
+
171
+ 1) Post before publication cannot have comments
172
+ Failure/Error: expect { Post.create.comments.create! }.to raise_error(ActiveRecord::RecordInvalid)
173
+ expected ActiveRecord::RecordInvalid but nothing was raised
174
+ # ./spec/models/post.rb:4:in `block (3 levels) in <top (required)>'
175
+
176
+ Finished in 0.00527 seconds (files took 0.29657 seconds to load)
177
+ 1 example, 1 failure
178
+
179
+ Failed examples:
180
+
181
+ rspec ./spec/models/post_spec.rb:3 # Post before publication cannot have comments
182
+ ```
183
+
184
+ For an in-depth look at the RSpec DSL, including lots of examples,
185
+ read the official Cucumber documentation for [RSpec Core][].
186
+
187
+ [RSpec Core]: https://rspec.info/features/3-12/rspec-core
188
+
189
+ ### Helpful Rails Matchers
190
+
191
+ In RSpec, assertions are called _expectations,_
192
+ and every expectation is built around a _matcher._
193
+ When you `expect(a).to eq(b)`, you’re using the `eq` matcher.
194
+
195
+ In addition to [the matchers that come standard in RSpec][],
196
+ here are some extras that make it easier
197
+ to test the various parts of a Rails system:
198
+
199
+ | RSpec matcher | Delegates to | Available in | Notes |
200
+ | ------------------------ | ------------------- | ------------------------------- | -------------------------------------------------------- |
201
+ | [`be_a_new`][] | | all | primarily intended for controller specs |
202
+ | [`render_template`][] | `assert_template` | request / controller / view | use with `expect(response).to` |
203
+ | [`redirect_to`][] | `assert_redirect` | request / controller | use with `expect(response).to` |
204
+ | [`route_to`] | `assert_recognizes` | routing / controller | use with `expect(...).to route_to` |
205
+ | [`be_routable`] | | routing / controller | use with `expect(...).not_to be_routable` |
206
+ | [`have_http_status`][] | | request / controller / feature | |
207
+ | [`match_array`][] | | all | for comparing arrays of ActiveRecord objects |
208
+ | [`have_been_enqueued`][] | | all | requires config: `ActiveJob::Base.queue_adapter = :test` |
209
+ | [`have_enqueued_job`][] | | all | requires config: `ActiveJob::Base.queue_adapter = :test` |
210
+
211
+ Follow the links above for examples of how each matcher is used.
212
+
213
+ [the matchers that come standard in RSpec]: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers
214
+ [`be_a_new`]: https://rspec.info/features/7-0/rspec-rails/matchers/new-record-matcher
215
+ [`render_template`]: https://rspec.info/features/7-0/rspec-rails/matchers/render-template-matcher
216
+ [`redirect_to`]: https://rspec.info/features/7-0/rspec-rails/matchers/redirect-to-matcher
217
+ [`route_to`]: https://rspec.info/features/7-0/rspec-rails/routing-specs/route-to-matcher
218
+ [`be_routable`]: https://rspec.info/features/7-0/rspec-rails/routing-specs/be-routable-matcher
219
+ [`have_http_status`]: https://rspec.info/features/7-0/rspec-rails/matchers/have-http-status-matcher
220
+ [`match_array`]: https://rspec.info/features/7-0/rspec-rails/matchers/relation-match-array
221
+ [`have_been_enqueued`]: https://rspec.info/features/7-0/rspec-rails/matchers/have-been-enqueued-matcher
222
+ [`have_enqueued_job`]: https://rspec.info/features/7-0/rspec-rails/matchers/have-enqueued-job-matcher
223
+
224
+ ### What else does RSpec Rails add?
225
+
226
+ For a comprehensive look at RSpec Rails’ features,
227
+ read the [official Cucumber documentation][].
228
+
229
+ [official Cucumber documentation]: https://rspec.info/features/7-0/rspec-rails
230
+
231
+ ## What tests should I write?
232
+
233
+ RSpec Rails defines ten different _types_ of specs
234
+ for testing different parts of a typical Rails application.
235
+ Each one inherits from one of Rails’ built-in `TestCase` classes,
236
+ meaning the helper methods provided by default in Rails tests
237
+ are available in RSpec, as well.
238
+
239
+ | Spec type | Corresponding Rails test class |
240
+ | -------------- | -------------------------------- |
241
+ | [model][] | |
242
+ | [controller][] | [`ActionController::TestCase`][] |
243
+ | [mailer][] | `ActionMailer::TestCase` |
244
+ | [job][] | |
245
+ | [view][] | `ActionView::TestCase` |
246
+ | [routing][] | |
247
+ | [helper][] | `ActionView::TestCase` |
248
+ | [request][] | [`ActionDispatch::IntegrationTest`][] |
249
+ | [feature][] | |
250
+ | [system][] | [`ActionDispatch::SystemTestCase`][] |
251
+
252
+ Follow the links above to see examples of each spec type,
253
+ or for official Rails API documentation on the given `TestCase` class.
254
+
255
+ > **Note: This is not a checklist.**
256
+ >
257
+ > Ask a hundred developers how to test an application,
258
+ > and you’ll get a hundred different answers.
259
+ >
260
+ > RSpec Rails provides thoughtfully selected features
261
+ > to encourage good testing practices, but there’s no “right” way to do it.
262
+ > Ultimately, it’s up to you to decide how your test suite will be composed.
263
+
264
+ When creating a spec file,
265
+ assign it a type in the top-level `describe` block, like so:
266
+
267
+ ```ruby
268
+ # spec/models/user_spec.rb
269
+
270
+ RSpec.describe User, type: :model do
271
+ ...
272
+ ```
273
+
274
+ [request]: https://rspec.info/features/7-0/rspec-rails/request-specs/request-spec
275
+ [feature]: https://rspec.info/features/7-0/rspec-rails/feature-specs/feature-spec
276
+ [system]: https://rspec.info/features/7-0/rspec-rails/system-specs/system-specs
277
+ [model]: https://rspec.info/features/7-0/rspec-rails/model-specs
278
+ [controller]: https://rspec.info/features/7-0/rspec-rails/controller-specs
279
+ [mailer]: https://rspec.info/features/7-0/rspec-rails/mailer-specs
280
+ [job]: https://rspec.info/features/7-0/rspec-rails/job-specs/job-spec
281
+ [view]: https://rspec.info/features/7-0/rspec-rails/view-specs/view-spec
282
+ [routing]: https://rspec.info/features/7-0/rspec-rails/routing-specs
283
+ [helper]: https://rspec.info/features/7-0/rspec-rails/helper-specs/helper-spec
284
+ [`ActionDispatch::IntegrationTest`]: https://api.rubyonrails.org/classes/ActionDispatch/IntegrationTest.html
285
+ [`ActionDispatch::SystemTestCase`]: https://api.rubyonrails.org/classes/ActionDispatch/SystemTestCase.html
286
+ [`ActionController::TestCase`]: https://api.rubyonrails.org/classes/ActionController/TestCase.html
287
+ [in the appropriate folder]: https://rspec.info/features/7-0/rspec-rails/directory-structure
288
+
289
+ ### System specs, feature specs, request specs–what’s the difference?
290
+
291
+ RSpec Rails provides some end-to-end (entire application) testing capability
292
+ to specify the interaction with the client.
293
+
294
+ #### System specs
295
+
296
+ Also called **acceptance tests**, **browser tests**, or **end-to-end tests**,
297
+ system specs test the application from the perspective of a _human client._
298
+ The test code walks through a user’s browser interactions,
299
+
300
+ * `visit '/login'`
301
+ * `fill_in 'Name', with: 'jdoe'`
302
+
303
+ and the expectations revolve around page content.
304
+
305
+ * `expect(page).to have_text('Welcome')`
306
+
307
+ Because system specs are a wrapper around Rails’ built-in `SystemTestCase`,
308
+ they’re only available on Rails 5.1+.
309
+ (Feature specs serve the same purpose, but without this dependency.)
310
+
311
+ #### Feature specs
312
+
313
+ Before Rails introduced system testing facilities,
314
+ feature specs were the only spec type for end-to-end testing.
315
+ While the RSpec team now [officially recommends system specs][] instead,
316
+ feature specs are still fully supported, look basically identical,
317
+ and work on older versions of Rails.
318
+
319
+ On the other hand, feature specs require non-trivial configuration
320
+ to get some important features working,
321
+ like JavaScript testing or making sure each test runs with a fresh DB state.
322
+ With system specs, this configuration is provided out-of-the-box.
323
+
324
+ Like system specs, feature specs require the [Capybara][] gem.
325
+ Rails 5.1+ includes it by default as part of system tests,
326
+ but if you don’t have the luxury of upgrading,
327
+ be sure to add it to the `:test` group of your `Gemfile` first:
328
+
329
+ ```ruby
330
+ group :test do
331
+ gem "capybara"
332
+ end
333
+ ```
334
+
335
+ [officially recommends system specs]: https://rspec.info/blog/2017/10/rspec-3-7-has-been-released/#rails-actiondispatchsystemtest-integration-system-specs
336
+ [Capybara]: https://github.com/teamcapybara/capybara
337
+
338
+ #### Request specs
339
+
340
+ Request specs are for testing the application
341
+ from the perspective of a _machine client._
342
+ They begin with an HTTP request and end with the HTTP response,
343
+ so they’re faster than feature specs,
344
+ but do not examine your app’s UI or JavaScript.
345
+
346
+ Request specs provide a high-level alternative to controller specs.
347
+ In fact, as of RSpec 3.5, both the Rails and RSpec teams
348
+ [discourage directly testing controllers][]
349
+ in favor of functional tests like request specs.
350
+
351
+ When writing them, try to answer the question,
352
+ “For a given HTTP request (verb + path + parameters),
353
+ what HTTP response should the application return?”
354
+
355
+ [discourage directly testing controllers]: https://rspec.info/blog/2016/07/rspec-3-5-has-been-released/#rails-support-for-rails-5
356
+
357
+ ## Contributing
358
+
359
+ - [Build details](BUILD_DETAIL.md)
360
+ - [Code of Conduct](CODE_OF_CONDUCT.md)
361
+ - [Detailed contributing guide](CONTRIBUTING.md)
362
+
363
+ Once you’ve cloned the repo and [set up the environment](DEVELOPMENT.md),
364
+ you can run the specs and Cucumber features, or submit a pull request.
365
+
366
+ ## See Also
367
+
368
+ ### RSpec base libraries
369
+
370
+ * https://github.com/rspec/rspec
371
+ * https://github.com/rspec/rspec-core
372
+ * https://github.com/rspec/rspec-expectations
373
+ * https://github.com/rspec/rspec-mocks
374
+
375
+ ### Recommended third-party extensions
376
+
377
+ * [FactoryBot](https://github.com/thoughtbot/factory_bot)
378
+ * [Capybara](https://github.com/teamcapybara/capybara)
379
+ (Included by default in Rails 5.1+.
380
+ Note that [additional configuration is required][] to use the Capybara DSL
381
+ anywhere other than system specs and feature specs.)
382
+
383
+ [additional configuration is required]: https://rubydoc.info/gems/rspec-rails/file/Capybara.md
@@ -0,0 +1,12 @@
1
+ require 'generators/rspec'
2
+
3
+ module Rspec
4
+ module Generators
5
+ # @private
6
+ class ChannelGenerator < Base
7
+ def create_channel_spec
8
+ template 'channel_spec.rb.erb', target_path('channels', class_path, "#{file_name}_channel_spec.rb")
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,7 @@
1
+ require 'rails_helper'
2
+
3
+ <% module_namespacing do -%>
4
+ RSpec.describe <%= class_name %>Channel, <%= type_metatag(:channel) %> do
5
+ pending "add some examples to (or delete) #{__FILE__}"
6
+ end
7
+ <% end -%>
@@ -0,0 +1,51 @@
1
+ require 'generators/rspec'
2
+
3
+ module Rspec
4
+ module Generators
5
+ # @private
6
+ class ControllerGenerator < Base
7
+ argument :actions, type: :array, default: [], banner: "action action"
8
+
9
+ class_option :template_engine, desc: "Template engine to generate view files"
10
+ class_option :request_specs, type: :boolean, default: true, desc: "Generate request specs"
11
+ class_option :controller_specs, type: :boolean, default: false, desc: "Generate controller specs"
12
+ class_option :view_specs, type: :boolean, default: true, desc: "Generate view specs"
13
+ class_option :routing_specs, type: :boolean, default: false, desc: "Generate routing specs"
14
+
15
+ def generate_request_spec
16
+ return unless options[:request_specs]
17
+
18
+ template 'request_spec.rb',
19
+ target_path('requests', class_path, "#{file_name}_spec.rb")
20
+ end
21
+
22
+ def generate_controller_spec
23
+ return unless options[:controller_specs]
24
+
25
+ template 'controller_spec.rb',
26
+ target_path('controllers', class_path, "#{file_name}_controller_spec.rb")
27
+ end
28
+
29
+ def generate_view_specs
30
+ return if actions.empty? && behavior == :invoke
31
+ return unless options[:view_specs] && options[:template_engine]
32
+
33
+ empty_directory File.join("spec", "views", file_path)
34
+
35
+ actions.each do |action|
36
+ @action = action
37
+ template 'view_spec.rb',
38
+ target_path('views', file_path, "#{@action}.html.#{options[:template_engine]}_spec.rb")
39
+ end
40
+ end
41
+
42
+ def generate_routing_spec
43
+ return if actions.empty?
44
+ return unless options[:routing_specs]
45
+
46
+ template 'routing_spec.rb',
47
+ target_path('routing', class_path, "#{file_name}_routing_spec.rb")
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,16 @@
1
+ require 'rails_helper'
2
+
3
+ <% module_namespacing do -%>
4
+ RSpec.describe <%= class_name %>Controller, <%= type_metatag(:controller) %> do
5
+
6
+ <% for action in actions -%>
7
+ describe "GET #<%= action %>" do
8
+ it "returns http success" do
9
+ get :<%= action %>
10
+ expect(response).to have_http_status(:success)
11
+ end
12
+ end
13
+
14
+ <% end -%>
15
+ end
16
+ <% end -%>
@@ -0,0 +1,19 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe "<%= class_name.pluralize %>", <%= type_metatag(:request) %> do
4
+ <% namespaced_path = regular_class_path.join('/') -%>
5
+ <% if actions.empty? -%>
6
+ describe "GET /index" do
7
+ pending "add some examples (or delete) #{__FILE__}"
8
+ end
9
+ <% end -%>
10
+ <% for action in actions -%>
11
+ describe "GET /<%= action %>" do
12
+ it "returns http success" do
13
+ get "<%= "/#{namespaced_path}" if namespaced_path != '' %>/<%= file_name %>/<%= action %>"
14
+ expect(response).to have_http_status(:success)
15
+ end
16
+ end
17
+
18
+ <% end -%>
19
+ end
@@ -0,0 +1,13 @@
1
+ require 'rails_helper'
2
+
3
+ <% module_namespacing do -%>
4
+ RSpec.describe '<%= class_name %>Controller', <%= type_metatag(:routing) %> do
5
+ describe 'routing' do
6
+ <% for action in actions -%>
7
+ it 'routes to #<%= action %>' do
8
+ expect(get: "/<%= class_name.underscore %>/<%= action %>").to route_to("<%= class_name.underscore %>#<%= action %>")
9
+ end
10
+ <% end -%>
11
+ end
12
+ end
13
+ <% end -%>
@@ -0,0 +1,5 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe "<%= file_name %>/<%= @action %>.html.<%= options[:template_engine] %>", <%= type_metatag(:view) %> do
4
+ pending "add some examples to (or delete) #{__FILE__}"
5
+ end
@@ -0,0 +1,29 @@
1
+ require 'generators/rspec'
2
+
3
+ module Rspec
4
+ module Generators
5
+ # @private
6
+ class FeatureGenerator < Base
7
+ class_option :feature_specs, type: :boolean, default: true, desc: "Generate feature specs"
8
+ class_option :singularize, type: :boolean, default: false, desc: "Singularize the generated feature"
9
+
10
+ def generate_feature_spec
11
+ return unless options[:feature_specs]
12
+
13
+ template template_name, target_path('features', class_path, filename)
14
+ end
15
+
16
+ def template_name
17
+ options[:singularize] ? 'feature_singular_spec.rb' : 'feature_spec.rb'
18
+ end
19
+
20
+ def filename
21
+ if options[:singularize]
22
+ "#{file_name.singularize}_spec.rb"
23
+ else
24
+ "#{file_name}_spec.rb"
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,5 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.feature "<%= class_name.singularize %>", <%= type_metatag(:feature) %> do
4
+ pending "add some scenarios (or delete) #{__FILE__}"
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.feature "<%= class_name.pluralize %>", <%= type_metatag(:feature) %> do
4
+ pending "add some scenarios (or delete) #{__FILE__}"
5
+ end
@@ -0,0 +1,24 @@
1
+ require 'generators/rspec'
2
+
3
+ module Rspec
4
+ module Generators
5
+ # @private
6
+ class GeneratorGenerator < Base
7
+ class_option :generator_specs, type: :boolean, default: true, desc: 'Generate generator specs'
8
+
9
+ def generate_generator_spec
10
+ return unless options[:generator_specs]
11
+
12
+ template template_name, target_path('generator', class_path, filename)
13
+ end
14
+
15
+ def template_name
16
+ 'generator_spec.rb'
17
+ end
18
+
19
+ def filename
20
+ "#{file_name}_generator_spec.rb"
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,5 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe "<%= class_name %>Generator", <%= type_metatag(:generator) %> do
4
+ pending "add some scenarios (or delete) #{__FILE__}"
5
+ end
@@ -0,0 +1,16 @@
1
+ require 'generators/rspec'
2
+
3
+ module Rspec
4
+ module Generators
5
+ # @private
6
+ class HelperGenerator < Base
7
+ class_option :helper_specs, type: :boolean, default: true
8
+
9
+ def generate_helper_spec
10
+ return unless options[:helper_specs]
11
+
12
+ template 'helper_spec.rb', target_path('helpers', class_path, "#{file_name}_helper_spec.rb")
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,17 @@
1
+ require 'rails_helper'
2
+
3
+ # Specs in this file have access to a helper object that includes
4
+ # the <%= class_name %>Helper. For example:
5
+ #
6
+ # describe <%= class_name %>Helper do
7
+ # describe "string concat" do
8
+ # it "concats two strings with spaces" do
9
+ # expect(helper.concat_strings("this","that")).to eq("this that")
10
+ # end
11
+ # end
12
+ # end
13
+ <% module_namespacing do -%>
14
+ RSpec.describe <%= class_name %>Helper, <%= type_metatag(:helper) %> do
15
+ pending "add some examples to (or delete) #{__FILE__}"
16
+ end
17
+ <% end -%>