rspec-rails 4.0.0.beta3 → 4.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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/Capybara.md +5 -54
- data/Changelog.md +61 -7
- data/README.md +20 -19
- data/lib/generators/rspec.rb +0 -6
- data/lib/generators/rspec/controller/controller_generator.rb +13 -5
- data/lib/generators/rspec/controller/templates/request_spec.rb +14 -0
- data/lib/generators/rspec/controller/templates/routing_spec.rb +1 -1
- data/lib/generators/rspec/feature/feature_generator.rb +2 -2
- data/lib/generators/rspec/{generators → generator}/generator_generator.rb +2 -2
- data/lib/generators/rspec/{generators → generator}/templates/generator_spec.rb +0 -0
- data/lib/generators/rspec/helper/helper_generator.rb +1 -1
- data/lib/generators/rspec/install/install_generator.rb +4 -4
- data/lib/generators/rspec/install/templates/spec/rails_helper.rb +17 -16
- data/lib/generators/rspec/integration/integration_generator.rb +3 -3
- data/lib/generators/rspec/mailer/mailer_generator.rb +1 -1
- data/lib/generators/rspec/model/model_generator.rb +4 -4
- data/lib/generators/rspec/scaffold/scaffold_generator.rb +26 -18
- data/lib/generators/rspec/scaffold/templates/api_controller_spec.rb +0 -36
- data/lib/generators/rspec/scaffold/templates/api_request_spec.rb +131 -0
- data/lib/generators/rspec/scaffold/templates/controller_spec.rb +10 -10
- data/lib/generators/rspec/scaffold/templates/edit_spec.rb +1 -1
- data/lib/generators/rspec/scaffold/templates/index_spec.rb +2 -2
- data/lib/generators/rspec/scaffold/templates/new_spec.rb +1 -1
- data/lib/generators/rspec/scaffold/templates/request_spec.rb +133 -0
- data/lib/generators/rspec/scaffold/templates/routing_spec.rb +8 -10
- data/lib/generators/rspec/scaffold/templates/show_spec.rb +1 -1
- data/lib/generators/rspec/system/system_generator.rb +1 -1
- data/lib/generators/rspec/view/view_generator.rb +2 -2
- data/lib/rspec-rails.rb +6 -9
- data/lib/rspec/rails/adapters.rb +10 -76
- data/lib/rspec/rails/configuration.rb +72 -36
- data/lib/rspec/rails/example/channel_example_group.rb +2 -2
- data/lib/rspec/rails/example/controller_example_group.rb +4 -4
- data/lib/rspec/rails/example/feature_example_group.rb +6 -26
- data/lib/rspec/rails/example/helper_example_group.rb +2 -10
- data/lib/rspec/rails/example/mailbox_example_group.rb +1 -1
- data/lib/rspec/rails/example/mailer_example_group.rb +2 -2
- data/lib/rspec/rails/example/rails_example_group.rb +1 -1
- data/lib/rspec/rails/example/system_example_group.rb +14 -7
- data/lib/rspec/rails/example/view_example_group.rb +38 -48
- data/lib/rspec/rails/extensions/active_record/proxy.rb +5 -10
- data/lib/rspec/rails/feature_check.rb +1 -28
- data/lib/rspec/rails/fixture_file_upload_support.rb +8 -13
- data/lib/rspec/rails/fixture_support.rb +37 -31
- data/lib/rspec/rails/matchers/action_cable.rb +1 -1
- data/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb +3 -3
- data/lib/rspec/rails/matchers/active_job.rb +132 -18
- data/lib/rspec/rails/matchers/base_matcher.rb +4 -10
- data/lib/rspec/rails/matchers/have_enqueued_mail.rb +9 -6
- data/lib/rspec/rails/matchers/have_http_status.rb +7 -7
- data/lib/rspec/rails/matchers/relation_match_array.rb +1 -1
- data/lib/rspec/rails/matchers/routing_matchers.rb +11 -11
- data/lib/rspec/rails/tasks/rspec.rake +7 -17
- data/lib/rspec/rails/vendor/capybara.rb +10 -15
- data/lib/rspec/rails/version.rb +1 -1
- data/lib/rspec/rails/view_path_builder.rb +1 -1
- data/lib/rspec/rails/view_rendering.rb +3 -3
- metadata +34 -33
- metadata.gz.sig +0 -0
- data/lib/generators/rspec/observer/observer_generator.rb +0 -13
- data/lib/generators/rspec/observer/templates/observer_spec.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4fdfac614970485c2587ffc56aa4f4f5a79fc2bb2bd49045d607c61fb5bc510
|
4
|
+
data.tar.gz: 0b8dabeb32e7b2d9a18c50d722f6c8ebda39610d35e8b45d329e26ff59f9046b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '09c2ebd8e132d6b98f84265e5175a475cf47cd9ac6145324c722f70fa82d328ce7feb5fc8b14e06a44ca18eb22bd66c124e8694ea84965d80ada15884bee4ac5'
|
7
|
+
data.tar.gz: 7a58ee48a4f590fde7c376019e531371cd576d7301318f38f1cb53baf817e75b29766d61b10f56fc367d764622478b7baf81c053e72ed63a558726c5dc35eb0e
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/Capybara.md
CHANGED
@@ -1,58 +1,19 @@
|
|
1
1
|
rspec-rails supports integration with Capybara out of the box by adding
|
2
2
|
its Capybara::DSL (visit/page) and Capybara::RSpecMatchers to the
|
3
|
-
examples in the applicable directories
|
4
|
-
Capybara 1.x and Capybara >= 2.x.
|
3
|
+
examples in the applicable directories.
|
5
4
|
|
6
5
|
## Capybara::DSL
|
7
6
|
|
8
7
|
Adds the `visit` and `page` methods, which work together to simulate a
|
9
8
|
GET request and provide access to the result (via `page`).
|
10
9
|
|
11
|
-
## Capybara::RSpecMatchers
|
12
|
-
|
13
|
-
Exposes matchers used to specify expected HTML content (e.g. `should_not have_selector` will work correctly).
|
14
|
-
|
15
|
-
## Capybara 1.x
|
16
|
-
|
17
|
-
Capybara::DSL is added to examples in:
|
18
|
-
|
19
|
-
* spec/requests # included by Capybara
|
20
|
-
* spec/controllers
|
21
|
-
|
22
|
-
Capybara::RSpecMatchers is added to examples in:
|
23
|
-
|
24
|
-
* spec/requests # included by Capybara
|
25
|
-
* spec/controllers
|
26
|
-
* spec/views
|
27
|
-
* spec/helpers
|
28
|
-
* spec/mailers
|
29
|
-
|
30
|
-
## Capybara 2.0
|
31
|
-
|
32
|
-
To use Capybara 2.0, you need rspec-rails-2.11.1 or greater.
|
33
|
-
|
34
10
|
Capybara::DSL is added to examples in:
|
35
11
|
|
36
12
|
* spec/features
|
37
13
|
|
38
|
-
Capybara::RSpecMatchers
|
39
|
-
|
40
|
-
* spec/features
|
41
|
-
* spec/controllers
|
42
|
-
* spec/views
|
43
|
-
* spec/helpers
|
44
|
-
* spec/mailers
|
45
|
-
|
46
|
-
## Upgrading to Capybara-2.0
|
47
|
-
|
48
|
-
Many users have been confused by the co-existence of the the
|
49
|
-
Capybara::DSL (visit/page) alongside the rack-test DSL
|
50
|
-
(get|post|put|delete|head/response.body) in examples in spec/requests
|
51
|
-
and spec/controllers. As of rspec-rails-2.11.1 and capybara-2.0.0.beta2, these
|
52
|
-
are separated as follows:
|
14
|
+
## Capybara::RSpecMatchers
|
53
15
|
|
54
|
-
|
55
|
-
* rack-test DSL is included in `spec/requests` and `spec/controllers`
|
16
|
+
Exposes matchers used to specify expected HTML content (e.g. `should_not have_selector` will work correctly).
|
56
17
|
|
57
18
|
Capybara::RSpecMatchers is added to examples in:
|
58
19
|
|
@@ -62,16 +23,6 @@ Capybara::RSpecMatchers is added to examples in:
|
|
62
23
|
* spec/helpers
|
63
24
|
* spec/mailers
|
64
25
|
|
65
|
-
|
66
|
-
spec/requests you'll want to move those examples to spec/features and
|
67
|
-
they should just work.
|
68
|
-
|
69
|
-
If you want to leave those examples in spec/requests, you can include
|
70
|
-
Capybara::DSL in those examples yourself as follows, but this is
|
71
|
-
absolutely not recommended as you will be overriding the intended
|
72
|
-
behavior and accepting the risks associated with doing so:
|
26
|
+
## Upgrading to Capybara-3.x
|
73
27
|
|
74
|
-
|
75
|
-
RSpec.configure do |c|
|
76
|
-
c.include Capybara::DSL, :file_path => "spec/requests"
|
77
|
-
end
|
28
|
+
Consult the official [Upgrading from Capybara 2.x to 3.x](https://github.com/teamcapybara/capybara/blob/master/UPGRADING.md#upgrading-from-capybara-2x-to-3x) guide.
|
data/Changelog.md
CHANGED
@@ -1,5 +1,29 @@
|
|
1
|
-
###
|
2
|
-
[Full Changelog](https://github.com/rspec/rspec-rails/compare/
|
1
|
+
### 4.0.2 / 2020-12-26
|
2
|
+
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v4.0.1...v4.0.2)
|
3
|
+
|
4
|
+
Bug Fixes:
|
5
|
+
|
6
|
+
* Indent all extra failure lines output from system specs. (Alex Robbin, #2321)
|
7
|
+
* Generated request spec for update now uses the correct let. (Paul Hanyzewski, #2344)
|
8
|
+
* Return `true`/`false` from predicate methods in config rather than raw values.
|
9
|
+
(Phil Pirozhkov, Jon Rowe, #2353, #2354)
|
10
|
+
* Remove old #fixture_path feature detection code which broke under newer Rails.
|
11
|
+
(Koen Punt, Jon Rowe, #2370)
|
12
|
+
|
13
|
+
### 4.0.1 / 2020-05-16
|
14
|
+
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v4.0.0...v4.0.1)
|
15
|
+
|
16
|
+
Bug Fixes:
|
17
|
+
|
18
|
+
* Remove warning when calling `driven_by` in system specs. (Aubin Lorieux, #2302)
|
19
|
+
* Fix comparison of times for `#at` in job matchers. (Jon Rowe, Markus Doits, #2304)
|
20
|
+
* Allow `have_enqueued_mail` to match when a sub class of `ActionMailer::DeliveryJob`
|
21
|
+
is set using `<Class>.delivery_job=`. (Atsushi Yoshida #2305)
|
22
|
+
* Restore Ruby 2.2.x compatibility. (Jon Rowe, #2332)
|
23
|
+
* Add `required_ruby_version` to gem spec. (Marc-André Lafortune, #2319, #2338)
|
24
|
+
|
25
|
+
### 4.0.0 / 2020-03-24
|
26
|
+
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v3.9.1...v4.0.0)
|
3
27
|
|
4
28
|
Enhancements:
|
5
29
|
|
@@ -14,6 +38,18 @@ Enhancements:
|
|
14
38
|
* Improve path parsing in view specs render options. (John Hawthorn, #2115)
|
15
39
|
* Add routing spec template as an option for generating controller specs.
|
16
40
|
(David Revelo, #2134)
|
41
|
+
* Add argument matcher support to `have_enqueued_*` matchers. (Phil Pirozhkov, #2206)
|
42
|
+
* Switch generated templates to use ruby 1.9 hash keys. (Tanbir Hasan, #2224)
|
43
|
+
* Add `have_been_performed`/`have_performed_job`/`perform_job` ActiveJob
|
44
|
+
matchers (Isaac Seymour, #1785)
|
45
|
+
* Default to generating request specs rather than controller specs when
|
46
|
+
generating a controller (Luka Lüdicke, #2222)
|
47
|
+
* Allow `ActiveJob` matchers `#on_queue` modifier to take symbolic queue names. (Nils Sommer, #2283)
|
48
|
+
* The scaffold generator now generates request specs in preference to controller specs.
|
49
|
+
(Luka Lüdicke, #2288)
|
50
|
+
* Add configuration option to disable ActiveRecord. (Jon Rowe, Phil Pirozhkov, Hermann Mayer, #2266)
|
51
|
+
* Set `ActionDispatch::SystemTesting::Server.silence_puma = true` when running system specs.
|
52
|
+
(ta1kt0me, Benoit Tigeot, #2289)
|
17
53
|
|
18
54
|
Bug Fixes:
|
19
55
|
|
@@ -27,13 +63,31 @@ Bug Fixes:
|
|
27
63
|
are generated correctly. (Jon Rowe, #2164)
|
28
64
|
* `ActionView::FixtureResolver#hash` has been renamed to `ActionView::FixtureResolver#data`.
|
29
65
|
(Penelope Phippen, #2076)
|
30
|
-
*
|
66
|
+
* Prevent `driven_by(:selenium)` being called due to hook precedence.
|
67
|
+
(Takumi Shotoku, #2188)
|
68
|
+
* Prevent a `WrongScopeError` being thrown during loading fixtures on Rails
|
69
|
+
6.1 development version. (Edouard Chin, #2215)
|
70
|
+
* Fix Mocha mocking support with `should`. (Phil Pirozhkov, #2256)
|
71
|
+
* Restore previous conditional check for setting `default_url_options` in feature
|
72
|
+
specs, prevents a `NoMethodError` in some scenarios. (Eugene Kenny, #2277)
|
73
|
+
* Allow changing `ActiveJob::Base.queue_adapter` inside a system spec.
|
74
|
+
(Jonathan Rochkind, #2242)
|
75
|
+
* `rails generate generator` command now creates related spec file (Joel Azemar, #2217)
|
76
|
+
* Relax upper `capybara` version constraint to allow for Capybara 3.x (Phil Pirozhkov, #2281)
|
77
|
+
* Clear ActionMailer test mailbox after each example (Benoit Tigeot, #2293)
|
31
78
|
|
32
79
|
Breaking Changes:
|
33
80
|
|
34
81
|
* Drops support for Rails below 5.0
|
35
82
|
* Drops support for Ruby below 2.3
|
36
83
|
|
84
|
+
### 3.9.1 / 2020-03-10
|
85
|
+
[Full Changelog](http://github.com/rspec/rspec-rails/compare/v3.9.0...v3.9.1)
|
86
|
+
|
87
|
+
Bug Fixes:
|
88
|
+
|
89
|
+
* Add missing require for have_enqueued_mail matcher. (Ignatius Reza, #2117)
|
90
|
+
|
37
91
|
### 3.9.0 / 2019-10-08
|
38
92
|
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v3.8.3...v3.9.0)
|
39
93
|
|
@@ -341,10 +395,10 @@ Enhancements:
|
|
341
395
|
* Improve controller and routing spec calls to `routes` by using `yield`
|
342
396
|
instead of `call`. (Anton Davydov, #1308)
|
343
397
|
* Add support for `ActiveJob` specs as standard `RSpec::Rails::RailsExampleGoup`s
|
344
|
-
via both
|
398
|
+
via both `type: :job` and inferring type from spec directory `spec/jobs`.
|
345
399
|
(Gabe Martin-Dempesy, #1361)
|
346
400
|
* Include `RSpec::Rails::FixtureSupport` into example groups using metadata
|
347
|
-
|
401
|
+
`use_fixtures: true`. (Aaron Kromer, #1372)
|
348
402
|
* Include `rspec:request` generator for generating request specs; this is an
|
349
403
|
alias of `rspec:integration` (Aaron Kromer, #1378)
|
350
404
|
* Update `rails_helper` generator with a default check to abort the spec run
|
@@ -485,7 +539,7 @@ Enhancements:
|
|
485
539
|
Bug Fixes:
|
486
540
|
|
487
541
|
* Fix an inconsistency in the generated scaffold specs for a controller. (Andy Waite)
|
488
|
-
* Ensure `config.before(:all, :
|
542
|
+
* Ensure `config.before(:all, type: <type>)` hooks run before groups
|
489
543
|
of the given type, even when the type is inferred by the file
|
490
544
|
location. (Jon Rowe, Myron Marston)
|
491
545
|
* Switch to parsing params with `Rack::Utils::parse_nested_query` to match Rails.
|
@@ -935,7 +989,7 @@ This release is compatible with rails-3.1.0.rc1, but not rails-3.1.0.beta1
|
|
935
989
|
* Enhancements
|
936
990
|
* include ApplicationHelper in helper object in helper specs
|
937
991
|
* include request spec extensions in files in spec/integration
|
938
|
-
* include controller spec extensions in groups that use :
|
992
|
+
* include controller spec extensions in groups that use type: :controller
|
939
993
|
* same for :model, :view, :helper, :mailer, :request, :routing
|
940
994
|
|
941
995
|
* Bug fixes
|
data/README.md
CHANGED
@@ -8,9 +8,10 @@ They’re also specifications (or _specs,_ for short):
|
|
8
8
|
detailed explanations of how the application is supposed to behave,
|
9
9
|
expressed in plain English.
|
10
10
|
|
11
|
+
Use **[`rspec-rails` 3.x][]** for Rails earlier than 5.0.
|
11
12
|
Use **[`rspec-rails` 1.x][]** for Rails 2.x.
|
12
13
|
|
13
|
-
[Build Status]: https://secure.travis-ci.org/rspec/rspec-rails.svg?branch=
|
14
|
+
[Build Status]: https://secure.travis-ci.org/rspec/rspec-rails.svg?branch=main
|
14
15
|
[travis-ci]: https://travis-ci.org/rspec/rspec-rails
|
15
16
|
[Code Climate]: https://codeclimate.com/github/rspec/rspec-rails.svg
|
16
17
|
[code-climate]: https://codeclimate.com/github/rspec/rspec-rails
|
@@ -19,6 +20,7 @@ Use **[`rspec-rails` 1.x][]** for Rails 2.x.
|
|
19
20
|
[RSpec]: https://rspec.info/
|
20
21
|
[Ruby on Rails]: https://rubyonrails.org/
|
21
22
|
[`rspec-rails` 1.x]: https://github.com/dchelimsky/rspec-rails
|
23
|
+
[`rspec-rails` 3.x]: https://github.com/rspec/rspec-rails/tree/3-9-maintenance
|
22
24
|
|
23
25
|
## Installation
|
24
26
|
|
@@ -28,14 +30,14 @@ Use **[`rspec-rails` 1.x][]** for Rails 2.x.
|
|
28
30
|
```ruby
|
29
31
|
# Run against the latest stable release
|
30
32
|
group :development, :test do
|
31
|
-
gem 'rspec-rails', '~>
|
33
|
+
gem 'rspec-rails', '~> 4.0.1'
|
32
34
|
end
|
33
35
|
|
34
|
-
# Or, run against the
|
35
|
-
# (requires
|
36
|
+
# Or, run against the main branch
|
37
|
+
# (requires main-branch versions of all related RSpec libraries)
|
36
38
|
group :development, :test do
|
37
39
|
%w[rspec-core rspec-expectations rspec-mocks rspec-rails rspec-support].each do |lib|
|
38
|
-
gem lib, :
|
40
|
+
gem lib, git: "https://github.com/rspec/#{lib}.git", branch: 'main'
|
39
41
|
end
|
40
42
|
end
|
41
43
|
```
|
@@ -119,8 +121,7 @@ $ bundle exec rspec --help
|
|
119
121
|
```
|
120
122
|
|
121
123
|
**Optional:** If `bundle exec rspec` is too verbose for you,
|
122
|
-
you can generate a binstub at `bin/rspec`
|
123
|
-
and use that instead (Rails 4+ only):
|
124
|
+
you can generate a binstub at `bin/rspec` and use that instead:
|
124
125
|
|
125
126
|
```sh
|
126
127
|
$ bundle binstubs rspec-core
|
@@ -183,17 +184,17 @@ In addition to [the matchers that come standard in RSpec][],
|
|
183
184
|
here are some extras that make it easier
|
184
185
|
to test the various parts of a Rails system:
|
185
186
|
|
186
|
-
| RSpec matcher | Delegates to
|
187
|
-
| ------------------------ |
|
188
|
-
| [`be_a_new`][] |
|
189
|
-
| [`render_template`][] | `assert_template`
|
190
|
-
| [`redirect_to`][] | `assert_redirect`
|
191
|
-
| [`route_to`] | `
|
192
|
-
| [`be_routable`] |
|
193
|
-
| [`have_http_status`][] |
|
194
|
-
| [`match_array`][] |
|
195
|
-
| [`have_been_enqueued`][] |
|
196
|
-
| [`have_enqueued_job`][] |
|
187
|
+
| RSpec matcher | Delegates to | Available in | Notes |
|
188
|
+
| ------------------------ | ------------------- | ------------------------------- | -------------------------------------------------------- |
|
189
|
+
| [`be_a_new`][] | | all | primarily intended for controller specs |
|
190
|
+
| [`render_template`][] | `assert_template` | request / controller / view | use with `expect(response).to` |
|
191
|
+
| [`redirect_to`][] | `assert_redirect` | request / controller | use with `expect(response).to` |
|
192
|
+
| [`route_to`] | `assert_recognizes` | routing / controller | use with `expect(...).to route_to` |
|
193
|
+
| [`be_routable`] | | routing / controller | use with `expect(...).not_to be_routable` |
|
194
|
+
| [`have_http_status`][] | | request / controller / feature | |
|
195
|
+
| [`match_array`][] | | all | for comparing arrays of ActiveRecord objects |
|
196
|
+
| [`have_been_enqueued`][] | | all | requires config: `ActiveJob::Base.queue_adapter = :test` |
|
197
|
+
| [`have_enqueued_job`][] | | all | requires config: `ActiveJob::Base.queue_adapter = :test` |
|
197
198
|
|
198
199
|
Follow the links above for examples of how each matcher is used.
|
199
200
|
|
@@ -362,7 +363,7 @@ you can run the specs and Cucumber features, or submit a pull request.
|
|
362
363
|
### Recommended third-party extensions
|
363
364
|
|
364
365
|
* [FactoryBot](https://github.com/thoughtbot/factory_bot)
|
365
|
-
* [Capybara](https://github.com/
|
366
|
+
* [Capybara](https://github.com/teamcapybara/capybara)
|
366
367
|
(Included by default in Rails 5.1+.
|
367
368
|
Note that [additional configuration is required][] to use the Capybara DSL
|
368
369
|
anywhere other than system specs and feature specs.)
|
data/lib/generators/rspec.rb
CHANGED
@@ -18,12 +18,6 @@ module Rspec
|
|
18
18
|
@_rspec_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'rspec', generator_name, 'templates'))
|
19
19
|
end
|
20
20
|
end
|
21
|
-
|
22
|
-
if ::Rails::VERSION::STRING < '3.1'
|
23
|
-
def module_namespacing
|
24
|
-
yield if block_given?
|
25
|
-
end
|
26
|
-
end
|
27
21
|
end
|
28
22
|
end
|
29
23
|
end
|
@@ -4,12 +4,20 @@ module Rspec
|
|
4
4
|
module Generators
|
5
5
|
# @private
|
6
6
|
class ControllerGenerator < Base
|
7
|
-
argument :actions, :
|
7
|
+
argument :actions, type: :array, default: [], banner: "action action"
|
8
8
|
|
9
|
-
class_option :template_engine,
|
10
|
-
class_option :
|
11
|
-
class_option :
|
12
|
-
class_option :
|
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
|
+
File.join('spec/requests', class_path, "#{file_name}_request_spec.rb")
|
20
|
+
end
|
13
21
|
|
14
22
|
def generate_controller_spec
|
15
23
|
return unless options[:controller_specs]
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
RSpec.describe "<%= class_name.pluralize %>", <%= type_metatag(:request) %> do
|
4
|
+
<% namespaced_path = regular_class_path.join('/') %>
|
5
|
+
<% for action in actions -%>
|
6
|
+
describe "GET /<%= action %>" do
|
7
|
+
it "returns http success" do
|
8
|
+
get "<%= "/#{namespaced_path}" if namespaced_path != '' %>/<%= file_name %>/<%= action %>"
|
9
|
+
expect(response).to have_http_status(:success)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
<% end -%>
|
14
|
+
end
|
@@ -5,7 +5,7 @@ RSpec.describe '<%= class_name %>Controller', <%= type_metatag(:routing) %> do
|
|
5
5
|
describe 'routing' do
|
6
6
|
<% for action in actions -%>
|
7
7
|
it 'routes to #<%= action %>' do
|
8
|
-
expect(:
|
8
|
+
expect(get: "/<%= class_name.underscore %>/<%= action %>").to route_to("<%= class_name.underscore %>#<%= action %>")
|
9
9
|
end
|
10
10
|
<% end -%>
|
11
11
|
end
|
@@ -4,8 +4,8 @@ module Rspec
|
|
4
4
|
module Generators
|
5
5
|
# @private
|
6
6
|
class FeatureGenerator < Base
|
7
|
-
class_option :feature_specs, :
|
8
|
-
class_option :singularize, :
|
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
9
|
|
10
10
|
def generate_feature_spec
|
11
11
|
return unless options[:feature_specs]
|
@@ -3,8 +3,8 @@ require 'generators/rspec'
|
|
3
3
|
module Rspec
|
4
4
|
module Generators
|
5
5
|
# @private
|
6
|
-
class
|
7
|
-
class_option :generator_specs, :
|
6
|
+
class GeneratorGenerator < Base
|
7
|
+
class_option :generator_specs, type: :boolean, default: true, desc: "Generate generator specs"
|
8
8
|
|
9
9
|
def generate_generator_spec
|
10
10
|
return unless options[:generator_specs]
|
File without changes
|
@@ -4,7 +4,7 @@ module Rspec
|
|
4
4
|
module Generators
|
5
5
|
# @private
|
6
6
|
class HelperGenerator < Base
|
7
|
-
class_option :helper_specs, :
|
7
|
+
class_option :helper_specs, type: :boolean, default: true
|
8
8
|
|
9
9
|
def generate_helper_spec
|
10
10
|
return unless options[:helper_specs]
|
@@ -32,8 +32,8 @@ DESC
|
|
32
32
|
|
33
33
|
def generate_rspec_init(tmpdir)
|
34
34
|
initializer = ::RSpec::Core::ProjectInitializer.new(
|
35
|
-
:
|
36
|
-
:
|
35
|
+
destination: tmpdir,
|
36
|
+
report_stream: StringIO.new
|
37
37
|
)
|
38
38
|
initializer.run
|
39
39
|
|
@@ -47,7 +47,7 @@ DESC
|
|
47
47
|
gsub_file spec_helper_path,
|
48
48
|
'rspec --init',
|
49
49
|
'rails generate rspec:install',
|
50
|
-
:
|
50
|
+
verbose: false
|
51
51
|
end
|
52
52
|
|
53
53
|
def remove_warnings_configuration(spec_helper_path)
|
@@ -56,7 +56,7 @@ DESC
|
|
56
56
|
gsub_file spec_helper_path,
|
57
57
|
/#{empty_line}(#{comment_line})+\s+config\.warnings = true\n/,
|
58
58
|
'',
|
59
|
-
:
|
59
|
+
verbose: false
|
60
60
|
end
|
61
61
|
end
|
62
62
|
end
|
@@ -1,11 +1,7 @@
|
|
1
1
|
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
2
2
|
require 'spec_helper'
|
3
3
|
ENV['RAILS_ENV'] ||= 'test'
|
4
|
-
<% if RUBY_VERSION >= '2.0.0' %>
|
5
4
|
require File.expand_path('../config/environment', __dir__)
|
6
|
-
<% else %>
|
7
|
-
require File.expand_path('../../config/environment', __FILE__)
|
8
|
-
<% end %>
|
9
5
|
# Prevent database truncation if the environment is production
|
10
6
|
abort("The Rails environment is running in production mode!") if Rails.env.production?
|
11
7
|
require 'rspec/rails'
|
@@ -24,9 +20,9 @@ require 'rspec/rails'
|
|
24
20
|
# directory. Alternatively, in the individual `*_spec.rb` files, manually
|
25
21
|
# require only the support files necessary.
|
26
22
|
#
|
27
|
-
# Dir[Rails.root.join('spec', 'support', '**', '*.rb')].each { |f| require f }
|
23
|
+
# Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each { |f| require f }
|
28
24
|
|
29
|
-
<% if RSpec::Rails::FeatureCheck.
|
25
|
+
<% if RSpec::Rails::FeatureCheck.has_active_record_migration? -%>
|
30
26
|
# Checks for pending migrations and applies them before tests are run.
|
31
27
|
# If you are not using ActiveRecord, you can remove these lines.
|
32
28
|
begin
|
@@ -35,15 +31,6 @@ rescue ActiveRecord::PendingMigrationError => e
|
|
35
31
|
puts e.to_s.strip
|
36
32
|
exit 1
|
37
33
|
end
|
38
|
-
<% elsif RSpec::Rails::FeatureCheck.can_check_pending_migrations? -%>
|
39
|
-
# Checks for pending migrations before tests are run.
|
40
|
-
# If you are not using ActiveRecord, you can remove these lines.
|
41
|
-
begin
|
42
|
-
ActiveRecord::Migration.check_pending!
|
43
|
-
rescue ActiveRecord::PendingMigrationError => e
|
44
|
-
puts e.to_s.strip
|
45
|
-
exit 1
|
46
|
-
end
|
47
34
|
<% end -%>
|
48
35
|
RSpec.configure do |config|
|
49
36
|
<% if RSpec::Rails::FeatureCheck.has_active_record? -%>
|
@@ -55,6 +42,20 @@ RSpec.configure do |config|
|
|
55
42
|
# instead of true.
|
56
43
|
config.use_transactional_fixtures = true
|
57
44
|
|
45
|
+
# You can uncomment this line to turn off ActiveRecord support entirely.
|
46
|
+
# config.use_active_record = false
|
47
|
+
|
48
|
+
<% else -%>
|
49
|
+
# Remove this line to enable support for ActiveRecord
|
50
|
+
config.use_active_record = false
|
51
|
+
|
52
|
+
# If you enable ActiveRecord support you should unncomment these lines,
|
53
|
+
# note if you'd prefer not to run each example within a transaction, you
|
54
|
+
# should set use_transactional_fixtures to false.
|
55
|
+
#
|
56
|
+
# config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
57
|
+
# config.use_transactional_fixtures = true
|
58
|
+
|
58
59
|
<% end -%>
|
59
60
|
# RSpec Rails can automatically mix in different behaviours to your tests
|
60
61
|
# based on their file location, for example enabling you to call `get` and
|
@@ -63,7 +64,7 @@ RSpec.configure do |config|
|
|
63
64
|
# You can disable this behaviour by removing the line below, and instead
|
64
65
|
# explicitly tag your specs with their type, e.g.:
|
65
66
|
#
|
66
|
-
# RSpec.describe UsersController, :
|
67
|
+
# RSpec.describe UsersController, type: :controller do
|
67
68
|
# # ...
|
68
69
|
# end
|
69
70
|
#
|