mini-quick-sys 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. checksums.yaml +7 -0
  2. data/mini-quick-sys.gemspec +12 -0
  3. data/rspec-rails-8.0.4/Capybara.md +28 -0
  4. data/rspec-rails-8.0.4/Changelog.md +1408 -0
  5. data/rspec-rails-8.0.4/LICENSE.md +25 -0
  6. data/rspec-rails-8.0.4/README.md +386 -0
  7. data/rspec-rails-8.0.4/lib/generators/rspec/authentication/authentication_generator.rb +25 -0
  8. data/rspec-rails-8.0.4/lib/generators/rspec/authentication/templates/user_spec.rb +5 -0
  9. data/rspec-rails-8.0.4/lib/generators/rspec/authentication/templates/users.yml +11 -0
  10. data/rspec-rails-8.0.4/lib/generators/rspec/channel/channel_generator.rb +12 -0
  11. data/rspec-rails-8.0.4/lib/generators/rspec/channel/templates/channel_spec.rb.erb +7 -0
  12. data/rspec-rails-8.0.4/lib/generators/rspec/controller/controller_generator.rb +51 -0
  13. data/rspec-rails-8.0.4/lib/generators/rspec/controller/templates/controller_spec.rb +16 -0
  14. data/rspec-rails-8.0.4/lib/generators/rspec/controller/templates/request_spec.rb +19 -0
  15. data/rspec-rails-8.0.4/lib/generators/rspec/controller/templates/routing_spec.rb +13 -0
  16. data/rspec-rails-8.0.4/lib/generators/rspec/controller/templates/view_spec.rb +5 -0
  17. data/rspec-rails-8.0.4/lib/generators/rspec/feature/feature_generator.rb +29 -0
  18. data/rspec-rails-8.0.4/lib/generators/rspec/feature/templates/feature_singular_spec.rb +5 -0
  19. data/rspec-rails-8.0.4/lib/generators/rspec/feature/templates/feature_spec.rb +5 -0
  20. data/rspec-rails-8.0.4/lib/generators/rspec/generator/generator_generator.rb +24 -0
  21. data/rspec-rails-8.0.4/lib/generators/rspec/generator/templates/generator_spec.rb +5 -0
  22. data/rspec-rails-8.0.4/lib/generators/rspec/helper/helper_generator.rb +16 -0
  23. data/rspec-rails-8.0.4/lib/generators/rspec/helper/templates/helper_spec.rb +17 -0
  24. data/rspec-rails-8.0.4/lib/generators/rspec/install/install_generator.rb +80 -0
  25. data/rspec-rails-8.0.4/lib/generators/rspec/install/templates/spec/rails_helper.rb +91 -0
  26. data/rspec-rails-8.0.4/lib/generators/rspec/job/job_generator.rb +13 -0
  27. data/rspec-rails-8.0.4/lib/generators/rspec/job/templates/job_spec.rb.erb +7 -0
  28. data/rspec-rails-8.0.4/lib/generators/rspec/mailbox/mailbox_generator.rb +14 -0
  29. data/rspec-rails-8.0.4/lib/generators/rspec/mailbox/templates/mailbox_spec.rb.erb +7 -0
  30. data/rspec-rails-8.0.4/lib/generators/rspec/mailer/mailer_generator.rb +30 -0
  31. data/rspec-rails-8.0.4/lib/generators/rspec/mailer/templates/fixture +3 -0
  32. data/rspec-rails-8.0.4/lib/generators/rspec/mailer/templates/mailer_spec.rb +25 -0
  33. data/rspec-rails-8.0.4/lib/generators/rspec/mailer/templates/preview.rb +13 -0
  34. data/rspec-rails-8.0.4/lib/generators/rspec/model/model_generator.rb +37 -0
  35. data/rspec-rails-8.0.4/lib/generators/rspec/model/templates/fixtures.yml +19 -0
  36. data/rspec-rails-8.0.4/lib/generators/rspec/model/templates/model_spec.rb +7 -0
  37. data/rspec-rails-8.0.4/lib/generators/rspec/request/request_generator.rb +17 -0
  38. data/rspec-rails-8.0.4/lib/generators/rspec/request/templates/request_spec.rb +10 -0
  39. data/rspec-rails-8.0.4/lib/generators/rspec/scaffold/scaffold_generator.rb +136 -0
  40. data/rspec-rails-8.0.4/lib/generators/rspec/scaffold/templates/api_controller_spec.rb +129 -0
  41. data/rspec-rails-8.0.4/lib/generators/rspec/scaffold/templates/api_request_spec.rb +131 -0
  42. data/rspec-rails-8.0.4/lib/generators/rspec/scaffold/templates/controller_spec.rb +145 -0
  43. data/rspec-rails-8.0.4/lib/generators/rspec/scaffold/templates/edit_spec.rb +27 -0
  44. data/rspec-rails-8.0.4/lib/generators/rspec/scaffold/templates/index_spec.rb +26 -0
  45. data/rspec-rails-8.0.4/lib/generators/rspec/scaffold/templates/new_spec.rb +22 -0
  46. data/rspec-rails-8.0.4/lib/generators/rspec/scaffold/templates/request_spec.rb +138 -0
  47. data/rspec-rails-8.0.4/lib/generators/rspec/scaffold/templates/routing_spec.rb +46 -0
  48. data/rspec-rails-8.0.4/lib/generators/rspec/scaffold/templates/show_spec.rb +21 -0
  49. data/rspec-rails-8.0.4/lib/generators/rspec/system/system_generator.rb +24 -0
  50. data/rspec-rails-8.0.4/lib/generators/rspec/system/templates/system_spec.rb +9 -0
  51. data/rspec-rails-8.0.4/lib/generators/rspec/view/templates/view_spec.rb +5 -0
  52. data/rspec-rails-8.0.4/lib/generators/rspec/view/view_generator.rb +22 -0
  53. data/rspec-rails-8.0.4/lib/generators/rspec.rb +56 -0
  54. data/rspec-rails-8.0.4/lib/rspec/rails/active_record.rb +25 -0
  55. data/rspec-rails-8.0.4/lib/rspec/rails/adapters.rb +196 -0
  56. data/rspec-rails-8.0.4/lib/rspec/rails/configuration.rb +158 -0
  57. data/rspec-rails-8.0.4/lib/rspec/rails/example/channel_example_group.rb +93 -0
  58. data/rspec-rails-8.0.4/lib/rspec/rails/example/controller_example_group.rb +217 -0
  59. data/rspec-rails-8.0.4/lib/rspec/rails/example/feature_example_group.rb +53 -0
  60. data/rspec-rails-8.0.4/lib/rspec/rails/example/helper_example_group.rb +42 -0
  61. data/rspec-rails-8.0.4/lib/rspec/rails/example/job_example_group.rb +23 -0
  62. data/rspec-rails-8.0.4/lib/rspec/rails/example/mailbox_example_group.rb +80 -0
  63. data/rspec-rails-8.0.4/lib/rspec/rails/example/mailer_example_group.rb +38 -0
  64. data/rspec-rails-8.0.4/lib/rspec/rails/example/model_example_group.rb +11 -0
  65. data/rspec-rails-8.0.4/lib/rspec/rails/example/rails_example_group.rb +23 -0
  66. data/rspec-rails-8.0.4/lib/rspec/rails/example/request_example_group.rb +27 -0
  67. data/rspec-rails-8.0.4/lib/rspec/rails/example/routing_example_group.rb +61 -0
  68. data/rspec-rails-8.0.4/lib/rspec/rails/example/system_example_group.rb +177 -0
  69. data/rspec-rails-8.0.4/lib/rspec/rails/example/view_example_group.rb +214 -0
  70. data/rspec-rails-8.0.4/lib/rspec/rails/example.rb +13 -0
  71. data/rspec-rails-8.0.4/lib/rspec/rails/extensions/active_record/proxy.rb +11 -0
  72. data/rspec-rails-8.0.4/lib/rspec/rails/extensions.rb +1 -0
  73. data/rspec-rails-8.0.4/lib/rspec/rails/feature_check.rb +51 -0
  74. data/rspec-rails-8.0.4/lib/rspec/rails/file_fixture_support.rb +18 -0
  75. data/rspec-rails-8.0.4/lib/rspec/rails/fixture_file_upload_support.rb +39 -0
  76. data/rspec-rails-8.0.4/lib/rspec/rails/fixture_support.rb +58 -0
  77. data/rspec-rails-8.0.4/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb +180 -0
  78. data/rspec-rails-8.0.4/lib/rspec/rails/matchers/action_cable/have_streams.rb +58 -0
  79. data/rspec-rails-8.0.4/lib/rspec/rails/matchers/action_cable.rb +70 -0
  80. data/rspec-rails-8.0.4/lib/rspec/rails/matchers/action_mailbox.rb +73 -0
  81. data/rspec-rails-8.0.4/lib/rspec/rails/matchers/active_job.rb +534 -0
  82. data/rspec-rails-8.0.4/lib/rspec/rails/matchers/base_matcher.rb +179 -0
  83. data/rspec-rails-8.0.4/lib/rspec/rails/matchers/be_a_new.rb +83 -0
  84. data/rspec-rails-8.0.4/lib/rspec/rails/matchers/be_new_record.rb +30 -0
  85. data/rspec-rails-8.0.4/lib/rspec/rails/matchers/be_valid.rb +49 -0
  86. data/rspec-rails-8.0.4/lib/rspec/rails/matchers/have_enqueued_mail.rb +259 -0
  87. data/rspec-rails-8.0.4/lib/rspec/rails/matchers/have_http_status.rb +381 -0
  88. data/rspec-rails-8.0.4/lib/rspec/rails/matchers/have_rendered.rb +64 -0
  89. data/rspec-rails-8.0.4/lib/rspec/rails/matchers/redirect_to.rb +38 -0
  90. data/rspec-rails-8.0.4/lib/rspec/rails/matchers/relation_match_array.rb +3 -0
  91. data/rspec-rails-8.0.4/lib/rspec/rails/matchers/routing_matchers.rb +125 -0
  92. data/rspec-rails-8.0.4/lib/rspec/rails/matchers/send_email.rb +122 -0
  93. data/rspec-rails-8.0.4/lib/rspec/rails/matchers.rb +36 -0
  94. data/rspec-rails-8.0.4/lib/rspec/rails/tasks/rspec.rake +49 -0
  95. data/rspec-rails-8.0.4/lib/rspec/rails/vendor/capybara.rb +32 -0
  96. data/rspec-rails-8.0.4/lib/rspec/rails/version.rb +9 -0
  97. data/rspec-rails-8.0.4/lib/rspec/rails/view_assigns.rb +27 -0
  98. data/rspec-rails-8.0.4/lib/rspec/rails/view_path_builder.rb +29 -0
  99. data/rspec-rails-8.0.4/lib/rspec/rails/view_rendering.rb +166 -0
  100. data/rspec-rails-8.0.4/lib/rspec/rails/view_spec_methods.rb +56 -0
  101. data/rspec-rails-8.0.4/lib/rspec/rails.rb +18 -0
  102. data/rspec-rails-8.0.4/lib/rspec-rails.rb +91 -0
  103. metadata +142 -0
@@ -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.
@@ -0,0 +1,386 @@
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
+ ## Supported Versions
12
+
13
+ We follow a versioning strategy as defined by [RSpec Rails versioning strategy][] the
14
+ TL;DR of which is that we support currently supported versions of Rails, and will
15
+ issue a major version change when removing older versions from support.
16
+
17
+ Accordingly you should use:
18
+
19
+ * **[`rspec-rails` 8.x][]** for Rails 8.0 or 7.2.
20
+ * **[`rspec-rails` 7.x][]** for Rails 7.x.
21
+ * **[`rspec-rails` 6.x][]** for Rails 6.1, 7.0 or 7.1.
22
+ * **[`rspec-rails` 5.x][]** for Rails 5.2 or 6.x.
23
+ * **[`rspec-rails` 4.x][]** for Rails from 5.x or 6.x.
24
+ * **[`rspec-rails` 3.x][]** for Rails earlier than 5.0.
25
+ * **[`rspec-rails` 1.x][]** for Rails 2.x.
26
+
27
+ [Code Climate]: https://codeclimate.com/github/rspec/rspec-rails.svg
28
+ [code-climate]: https://codeclimate.com/github/rspec/rspec-rails
29
+ [Gem Version]: https://badge.fury.io/rb/rspec-rails.svg
30
+ [gem-version]: https://badge.fury.io/rb/rspec-rails
31
+ [RSpec]: https://rspec.info/
32
+ [Ruby on Rails]: https://rubyonrails.org/
33
+ [`rspec-rails` 1.x]: https://github.com/dchelimsky/rspec-rails
34
+ [`rspec-rails` 3.x]: https://github.com/rspec/rspec-rails/tree/3-9-maintenance
35
+ [`rspec-rails` 4.x]: https://github.com/rspec/rspec-rails/tree/4-1-maintenance
36
+ [`rspec-rails` 5.x]: https://github.com/rspec/rspec-rails/tree/5-1-maintenance
37
+ [`rspec-rails` 6.x]: https://github.com/rspec/rspec-rails/tree/6-1-maintenance
38
+ [`rspec-rails` 7.x]: https://github.com/rspec/rspec-rails/tree/7-1-maintenance
39
+ [`rspec-rails` 8.x]: https://github.com/rspec/rspec-rails/tree/8-0-maintenance
40
+ [RSpec Rails versioning strategy]: https://github.com/rspec/rspec-rails/blob/main/rfcs/versioning-strategy.md
41
+
42
+ ## Installation
43
+
44
+ **IMPORTANT** This README / branch refers to the 8.0.x stable release series, only bugfixes from this series will
45
+ be added here. See the [`main` branch on Github](https://github.com/rspec/rspec-rails/tree/main) if you want or
46
+ require the latest unstable features.https://github.com/rspec/rspec-rails/tree/8-0-maintenance) if you want or require the latest stable release.
47
+
48
+ 1. Add `rspec-rails` to **both** the `:development` and `:test` groups
49
+ of your app’s `Gemfile`:
50
+
51
+ ```ruby
52
+ # Run against this stable release
53
+ group :development, :test do
54
+ gem 'rspec-rails', '~> 8.0.0'
55
+ end
56
+
57
+ # Or, run against the main branch
58
+ group :development, :test do
59
+ gem 'rspec-rails', git: 'https://github.com/rspec/rspec-rails'
60
+ end
61
+ ```
62
+
63
+ (Adding it to the `:development` group is not strictly necessary,
64
+ but without it, generators and rake tasks must be preceded by `RAILS_ENV=test`.)
65
+
66
+ 2. Then, in your project directory:
67
+
68
+ ```sh
69
+ # Download and install
70
+ $ bundle install
71
+
72
+ # Generate boilerplate configuration files
73
+ # (check the comments in each generated file for more information)
74
+ $ rails generate rspec:install
75
+ create .rspec
76
+ create spec
77
+ create spec/spec_helper.rb
78
+ create spec/rails_helper.rb
79
+ ```
80
+
81
+ ## Upgrading
82
+
83
+ If your project is already using an older version of `rspec-rails`,
84
+ upgrade to the latest version with:
85
+
86
+ ```sh
87
+ $ bundle update rspec-rails
88
+ ```
89
+
90
+ RSpec follows [semantic versioning](https://semver.org/),
91
+ which means that “major version” upgrades (_e.g.,_ 2.x → 3.x)
92
+ come with **breaking changes**.
93
+ If you’re upgrading from version 2.x or below,
94
+ read the [`rspec-rails` upgrade notes][] to find out what to watch out for.
95
+
96
+ Be sure to check the general [RSpec upgrade notes][] as well.
97
+
98
+ [`rspec-rails` upgrade notes]: https://rspec.info/features/8-0/rspec-rails/upgrade
99
+ [RSpec upgrade notes]: https://rspec.info/upgrading-from-rspec-2/
100
+
101
+ ## Usage
102
+
103
+ ### Creating boilerplate specs with `rails generate`
104
+
105
+ ```sh
106
+ # RSpec hooks into built-in generators
107
+ $ rails generate model user
108
+ invoke active_record
109
+ create db/migrate/20181017040312_create_users.rb
110
+ create app/models/user.rb
111
+ invoke rspec
112
+ create spec/models/user_spec.rb
113
+
114
+ # RSpec also provides its own spec file generators
115
+ $ rails generate rspec:model user
116
+ create spec/models/user_spec.rb
117
+
118
+ # List all RSpec generators
119
+ $ rails generate --help | grep rspec
120
+ ```
121
+
122
+ ### Running specs
123
+
124
+ ```sh
125
+ # Default: Run all spec files (i.e., those matching spec/**/*_spec.rb)
126
+ $ bundle exec rspec
127
+
128
+ # Run all spec files in a single directory (recursively)
129
+ $ bundle exec rspec spec/models
130
+
131
+ # Run a single spec file
132
+ $ bundle exec rspec spec/controllers/accounts_controller_spec.rb
133
+
134
+ # Run a single example from a spec file (by line number)
135
+ $ bundle exec rspec spec/controllers/accounts_controller_spec.rb:8
136
+
137
+ # See all options for running specs
138
+ $ bundle exec rspec --help
139
+ ```
140
+
141
+ **Optional:** If `bundle exec rspec` is too verbose for you,
142
+ you can generate a binstub at `bin/rspec` and use that instead:
143
+
144
+ ```sh
145
+ $ bundle binstubs rspec-core
146
+ ```
147
+
148
+ ## RSpec DSL Basics (or, how do I write a spec?)
149
+
150
+ In RSpec, application behavior is described
151
+ **first in (almost) plain English, then again in test code**, like so:
152
+
153
+ ```ruby
154
+ RSpec.describe 'Post' do #
155
+ context 'before publication' do # (almost) plain English
156
+ it 'cannot have comments' do #
157
+ expect { Post.create.comments.create! }.to raise_error(ActiveRecord::RecordInvalid) # test code
158
+ end
159
+ end
160
+ end
161
+ ```
162
+
163
+ Running `rspec` will execute this test code,
164
+ and then use the plain-English descriptions
165
+ to generate a report of where the application
166
+ conforms to (or fails to meet) the spec:
167
+
168
+ ```
169
+ $ rspec --format documentation spec/models/post_spec.rb
170
+
171
+ Post
172
+ before publication
173
+ cannot have comments
174
+
175
+ Failures:
176
+
177
+ 1) Post before publication cannot have comments
178
+ Failure/Error: expect { Post.create.comments.create! }.to raise_error(ActiveRecord::RecordInvalid)
179
+ expected ActiveRecord::RecordInvalid but nothing was raised
180
+ # ./spec/models/post.rb:4:in `block (3 levels) in <top (required)>'
181
+
182
+ Finished in 0.00527 seconds (files took 0.29657 seconds to load)
183
+ 1 example, 1 failure
184
+
185
+ Failed examples:
186
+
187
+ rspec ./spec/models/post_spec.rb:3 # Post before publication cannot have comments
188
+ ```
189
+
190
+ For an in-depth look at the RSpec DSL, including lots of examples,
191
+ read the official Cucumber documentation for [RSpec Core][].
192
+
193
+ [RSpec Core]: https://rspec.info/features/3-12/rspec-core
194
+
195
+ ### Helpful Rails Matchers
196
+
197
+ In RSpec, assertions are called _expectations,_
198
+ and every expectation is built around a _matcher._
199
+ When you `expect(a).to eq(b)`, you’re using the `eq` matcher.
200
+
201
+ In addition to [the matchers that come standard in RSpec][],
202
+ here are some extras that make it easier
203
+ to test the various parts of a Rails system:
204
+
205
+ | RSpec matcher | Delegates to | Available in | Notes |
206
+ | ------------------------ | ------------------- | ------------------------------- | -------------------------------------------------------- |
207
+ | [`be_a_new`][] | | all | primarily intended for controller specs |
208
+ | [`render_template`][] | `assert_template` | request / controller / view | use with `expect(response).to` |
209
+ | [`redirect_to`][] | `assert_redirect` | request / controller | use with `expect(response).to` |
210
+ | [`route_to`] | `assert_recognizes` | routing / controller | use with `expect(...).to route_to` |
211
+ | [`be_routable`] | | routing / controller | use with `expect(...).not_to be_routable` |
212
+ | [`have_http_status`][] | | request / controller / feature | |
213
+ | [`match_array`][] | | all | for comparing arrays of ActiveRecord objects |
214
+ | [`have_been_enqueued`][] | | all | requires config: `ActiveJob::Base.queue_adapter = :test` |
215
+ | [`have_enqueued_job`][] | | all | requires config: `ActiveJob::Base.queue_adapter = :test` |
216
+
217
+ Follow the links above for examples of how each matcher is used.
218
+
219
+ [the matchers that come standard in RSpec]: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers
220
+ [`be_a_new`]: https://rspec.info/features/8-0/rspec-rails/matchers/new-record-matcher
221
+ [`render_template`]: https://rspec.info/features/8-0/rspec-rails/matchers/render-template-matcher
222
+ [`redirect_to`]: https://rspec.info/features/8-0/rspec-rails/matchers/redirect-to-matcher
223
+ [`route_to`]: https://rspec.info/features/8-0/rspec-rails/routing-specs/route-to-matcher
224
+ [`be_routable`]: https://rspec.info/features/8-0/rspec-rails/routing-specs/be-routable-matcher
225
+ [`have_http_status`]: https://rspec.info/features/8-0/rspec-rails/matchers/have-http-status-matcher
226
+ [`match_array`]: https://rspec.info/features/8-0/rspec-rails/matchers/relation-match-array
227
+ [`have_been_enqueued`]: https://rspec.info/features/8-0/rspec-rails/matchers/have-been-enqueued-matcher
228
+ [`have_enqueued_job`]: https://rspec.info/features/8-0/rspec-rails/matchers/have-enqueued-job-matcher
229
+
230
+ ### What else does RSpec Rails add?
231
+
232
+ For a comprehensive look at RSpec Rails’ features,
233
+ read the [official Cucumber documentation][].
234
+
235
+ [official Cucumber documentation]: https://rspec.info/features/8-0/rspec-rails
236
+
237
+ ## What tests should I write?
238
+
239
+ RSpec Rails defines ten different _types_ of specs
240
+ for testing different parts of a typical Rails application.
241
+ Each one inherits from one of Rails’ built-in `TestCase` classes,
242
+ meaning the helper methods provided by default in Rails tests
243
+ are available in RSpec, as well.
244
+
245
+ | Spec type | Corresponding Rails test class |
246
+ | -------------- | -------------------------------- |
247
+ | [model][] | |
248
+ | [controller][] | [`ActionController::TestCase`][] |
249
+ | [mailer][] | `ActionMailer::TestCase` |
250
+ | [job][] | |
251
+ | [view][] | `ActionView::TestCase` |
252
+ | [routing][] | |
253
+ | [helper][] | `ActionView::TestCase` |
254
+ | [request][] | [`ActionDispatch::IntegrationTest`][] |
255
+ | [feature][] | |
256
+ | [system][] | [`ActionDispatch::SystemTestCase`][] |
257
+
258
+ Follow the links above to see examples of each spec type,
259
+ or for official Rails API documentation on the given `TestCase` class.
260
+
261
+ > **Note: This is not a checklist.**
262
+ >
263
+ > Ask a hundred developers how to test an application,
264
+ > and you’ll get a hundred different answers.
265
+ >
266
+ > RSpec Rails provides thoughtfully selected features
267
+ > to encourage good testing practices, but there’s no “right” way to do it.
268
+ > Ultimately, it’s up to you to decide how your test suite will be composed.
269
+
270
+ When creating a spec file,
271
+ assign it a type in the top-level `describe` block, like so:
272
+
273
+ ```ruby
274
+ # spec/models/user_spec.rb
275
+
276
+ RSpec.describe User, type: :model do
277
+ ...
278
+ ```
279
+
280
+ [request]: https://rspec.info/features/8-0/rspec-rails/request-specs/request-spec
281
+ [feature]: https://rspec.info/features/8-0/rspec-rails/feature-specs/feature-spec
282
+ [system]: https://rspec.info/features/8-0/rspec-rails/system-specs/system-specs
283
+ [model]: https://rspec.info/features/8-0/rspec-rails/model-specs
284
+ [controller]: https://rspec.info/features/8-0/rspec-rails/controller-specs
285
+ [mailer]: https://rspec.info/features/8-0/rspec-rails/mailer-specs
286
+ [job]: https://rspec.info/features/8-0/rspec-rails/job-specs/job-spec
287
+ [view]: https://rspec.info/features/8-0/rspec-rails/view-specs/view-spec
288
+ [routing]: https://rspec.info/features/8-0/rspec-rails/routing-specs
289
+ [helper]: https://rspec.info/features/8-0/rspec-rails/helper-specs/helper-spec
290
+ [`ActionDispatch::IntegrationTest`]: https://api.rubyonrails.org/classes/ActionDispatch/IntegrationTest.html
291
+ [`ActionDispatch::SystemTestCase`]: https://api.rubyonrails.org/classes/ActionDispatch/SystemTestCase.html
292
+ [`ActionController::TestCase`]: https://api.rubyonrails.org/classes/ActionController/TestCase.html
293
+ [in the appropriate folder]: https://rspec.info/features/8-0/rspec-rails/directory-structure
294
+
295
+ ### System specs, feature specs, request specs–what’s the difference?
296
+
297
+ RSpec Rails provides some end-to-end (entire application) testing capability
298
+ to specify the interaction with the client.
299
+
300
+ #### System specs
301
+
302
+ Also called **acceptance tests**, **browser tests**, or **end-to-end tests**,
303
+ system specs test the application from the perspective of a _human client._
304
+ The test code walks through a user’s browser interactions,
305
+
306
+ * `visit '/login'`
307
+ * `fill_in 'Name', with: 'jdoe'`
308
+
309
+ and the expectations revolve around page content.
310
+
311
+ * `expect(page).to have_text('Welcome')`
312
+
313
+ Because system specs are a wrapper around Rails’ built-in `SystemTestCase`,
314
+ they’re only available on Rails 5.1+.
315
+ (Feature specs serve the same purpose, but without this dependency.)
316
+
317
+ #### Feature specs
318
+
319
+ Before Rails introduced system testing facilities,
320
+ feature specs were the only spec type for end-to-end testing.
321
+ While the RSpec team now [officially recommends system specs][] instead,
322
+ feature specs are still fully supported, look basically identical,
323
+ and work on older versions of Rails.
324
+
325
+ On the other hand, feature specs require non-trivial configuration
326
+ to get some important features working,
327
+ like JavaScript testing or making sure each test runs with a fresh DB state.
328
+ With system specs, this configuration is provided out-of-the-box.
329
+
330
+ Like system specs, feature specs require the [Capybara][] gem.
331
+ Rails 5.1+ includes it by default as part of system tests,
332
+ but if you don’t have the luxury of upgrading,
333
+ be sure to add it to the `:test` group of your `Gemfile` first:
334
+
335
+ ```ruby
336
+ group :test do
337
+ gem "capybara"
338
+ end
339
+ ```
340
+
341
+ [officially recommends system specs]: https://rspec.info/blog/2017/10/rspec-3-7-has-been-released/#rails-actiondispatchsystemtest-integration-system-specs
342
+ [Capybara]: https://github.com/teamcapybara/capybara
343
+
344
+ #### Request specs
345
+
346
+ Request specs are for testing the application
347
+ from the perspective of a _machine client._
348
+ They begin with an HTTP request and end with the HTTP response,
349
+ so they’re faster than feature specs,
350
+ but do not examine your app’s UI or JavaScript.
351
+
352
+ Request specs provide a high-level alternative to controller specs.
353
+ In fact, as of RSpec 3.5, both the Rails and RSpec teams
354
+ [discourage directly testing controllers][]
355
+ in favor of functional tests like request specs.
356
+
357
+ When writing them, try to answer the question,
358
+ “For a given HTTP request (verb + path + parameters),
359
+ what HTTP response should the application return?”
360
+
361
+ [discourage directly testing controllers]: https://rspec.info/blog/2016/07/rspec-3-5-has-been-released/#rails-support-for-rails-5
362
+
363
+ ## Contributing
364
+
365
+ - [Build details](BUILD_DETAIL.md)
366
+ - [Code of Conduct](CODE_OF_CONDUCT.md)
367
+ - [Detailed contributing guide](CONTRIBUTING.md)
368
+
369
+ Once you’ve cloned the repo and [set up the environment](DEVELOPMENT.md),
370
+ you can run the specs and Cucumber features, or submit a pull request.
371
+
372
+ ## See Also
373
+
374
+ ### RSpec base libraries
375
+
376
+ * https://github.com/rspec/rspec
377
+
378
+ ### Recommended third-party extensions
379
+
380
+ * [FactoryBot](https://github.com/thoughtbot/factory_bot)
381
+ * [Capybara](https://github.com/teamcapybara/capybara)
382
+ (Included by default in Rails 5.1+.
383
+ Note that [additional configuration is required][] to use the Capybara DSL
384
+ anywhere other than system specs and feature specs.)
385
+
386
+ [additional configuration is required]: https://rubydoc.info/gems/rspec-rails/file/Capybara.md
@@ -0,0 +1,25 @@
1
+ require 'generators/rspec'
2
+
3
+ module Rspec
4
+ module Generators
5
+ # @private
6
+ class AuthenticationGenerator < Base
7
+ def initialize(args, *options)
8
+ args.replace(['User'])
9
+ super
10
+ end
11
+
12
+ def create_user_spec
13
+ template 'user_spec.rb', target_path('models', 'user_spec.rb')
14
+ end
15
+
16
+ hook_for :fixture_replacement
17
+
18
+ def create_fixture_file
19
+ return if options[:fixture_replacement]
20
+
21
+ template 'users.yml', target_path('fixtures', 'users.yml')
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,5 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe User, <%= type_metatag(:model) %> do
4
+ pending "add some examples to (or delete) #{__FILE__}"
5
+ end
@@ -0,0 +1,11 @@
1
+ # Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2
+
3
+ <%% password_digest = BCrypt::Password.create("password") %>
4
+
5
+ one:
6
+ email_address: one@example.com
7
+ password_digest: <%%= password_digest %>
8
+
9
+ two:
10
+ email_address: two@example.com
11
+ password_digest: <%%= password_digest %>
@@ -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