rspec-rails 4.0.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/Changelog.md +84 -52
  5. data/README.md +22 -17
  6. data/lib/generators/rspec/controller/controller_generator.rb +2 -2
  7. data/lib/generators/rspec/controller/templates/request_spec.rb +6 -1
  8. data/lib/generators/rspec/mailer/templates/mailer_spec.rb +2 -2
  9. data/lib/generators/rspec/mailer/templates/preview.rb +1 -1
  10. data/lib/generators/rspec/scaffold/templates/api_request_spec.rb +3 -3
  11. data/lib/generators/rspec/scaffold/templates/controller_spec.rb +0 -48
  12. data/lib/generators/rspec/scaffold/templates/edit_spec.rb +0 -4
  13. data/lib/generators/rspec/scaffold/templates/new_spec.rb +0 -4
  14. data/lib/generators/rspec/scaffold/templates/request_spec.rb +4 -0
  15. data/lib/generators/rspec/system/system_generator.rb +14 -16
  16. data/lib/rspec-rails.rb +5 -7
  17. data/lib/rspec/rails/configuration.rb +40 -6
  18. data/lib/rspec/rails/example/mailbox_example_group.rb +1 -1
  19. data/lib/rspec/rails/example/mailer_example_group.rb +2 -2
  20. data/lib/rspec/rails/example/request_example_group.rb +1 -4
  21. data/lib/rspec/rails/example/system_example_group.rb +4 -3
  22. data/lib/rspec/rails/extensions/active_record/proxy.rb +4 -1
  23. data/lib/rspec/rails/file_fixture_support.rb +9 -11
  24. data/lib/rspec/rails/fixture_file_upload_support.rb +32 -16
  25. data/lib/rspec/rails/fixture_support.rb +8 -12
  26. data/lib/rspec/rails/matchers/action_mailbox.rb +14 -5
  27. data/lib/rspec/rails/matchers/active_job.rb +29 -3
  28. data/lib/rspec/rails/matchers/have_enqueued_mail.rb +3 -3
  29. data/lib/rspec/rails/matchers/relation_match_array.rb +1 -1
  30. data/lib/rspec/rails/version.rb +1 -1
  31. metadata +24 -24
  32. metadata.gz.sig +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8e8f5dabd4f5335dc409c77670d7aef552636874486111f105613d54e4270375
4
- data.tar.gz: 72f211f8667a1d6faedaa8e02877958ccd742c5591107ed568a620fc38999c55
3
+ metadata.gz: 22120c08322db7d9470240c96bba31832d330976d195338eb507fad8fe2dc354
4
+ data.tar.gz: e48c5b5a155a865cf7b5fd2df8697ac3a2ae8378373921a6dea505add670e2a0
5
5
  SHA512:
6
- metadata.gz: a4125a040fcc9d7b1e9d8ee802f2d9ad75bc581a3e9263c329db8ddaccfd49988ccaab066c0aebad50e3b78a99d0ebe22e04a9648e44f6e1284325ea112e4c63
7
- data.tar.gz: e08c9439828c7f1b2f3ec543ea72d554f92d79adde6cb01e19d8486c3fc64887432239d1159d4aea7a6b8811cd4f3aaff811b777b3dff80569facfaa38ede625
6
+ metadata.gz: c15dd2809fa641a6eb1c67ec9928e6ca49f8c413328f3b4e1040a82b3cb32efb68a0606a77f3bd9be8b453fe37bd77ca6878bed166c87d549e7c8c6e4d4c3519
7
+ data.tar.gz: 7edcae51bcb43cbebef28d02aee76aeaf543d4df339ece8d962011e7138430ac950f55a367e71bb456e05425d86dddc30eef2d406d393d072b5317b4bc4905fa
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/Changelog.md CHANGED
@@ -1,50 +1,69 @@
1
- ### 4.0.0.rc1 / 2020-03-13
2
- [Full Changelog](https://github.com/rspec/rspec-rails/compare/v4.0.0.beta4...v4.0.0.rc1)
1
+ ### 5.0.0 / 2021-03-09
2
+ [Full Changelog](https://github.com/rspec/rspec-rails/compare/v4.1.1...main)
3
3
 
4
4
  Enhancements:
5
5
 
6
- * Allow `ActiveJob` matchers `#on_queue` modifier to take symbolic queue names. (Nils Sommer, #2283)
7
- * The scaffold generator now generates request specs in preference to controller specs.
8
- (Luka Lüdicke, #2288)
9
- * Add configuration option to disable ActiveRecord. (Jon Rowe, Phil Pirozhkov, Hermann Mayer, #2266)
10
- * Set `ActionDispatch::SystemTesting::Server.silence_puma = true` when running system specs.
11
- (ta1kt0me, Benoit Tigeot, #2289)
6
+ * Support new #file_fixture_path and new fixture test support code. (Jon Rowe, #2398)
7
+ * Support for Rails 6.1. (Benoit Tigeot, Jon Rowe, Phil Pirozhkov, and more #2398)
8
+
9
+ Breaking Changes:
10
+
11
+ * Drop support for Rails below 5.2.
12
+
13
+ ### 4.1.1 / 2021-03-09
12
14
 
13
15
  Bug Fixes:
14
16
 
15
- * Restore previous conditional check for setting `default_url_options` in feature
16
- specs, prevents a `NoMethodError` in some scenarios. (Eugene Kenny, #2277)
17
- * Allow changing `ActiveJob::Base.queue_adapter` inside a system spec.
18
- (Jonathan Rochkind, #2242)
19
- * `rails generate generator` command now creates related spec file (Joel Azemar, #2217)
20
- * Relax upper `capybara` version constraint to allow for Capybara 3.x (Phil Pirozhkov, #2281)
21
- * Clear ActionMailer test mailbox after each example (Benoit Tigeot, #2293)
17
+ * Remove generated specs when destroying a generated controller.
18
+ (@Naokimi, #2475)
22
19
 
23
- ### 4.0.0.beta4
24
- [Full Changelog](https://github.com/rspec/rspec-rails/compare/v4.0.0.beta3...v4.0.0.beta4)
20
+ ### 4.1.0 / 2021-03-06
25
21
 
26
22
  Enhancements:
27
23
 
28
- * Add argument matcher support to `have_enqueued_*` matchers. (Phil Pirozhkov, #2206)
29
- * Switch generated templates to use ruby 1.9 hash keys. (Tanbir Hasan, #2224)
30
- * Add `have_been_performed`/`have_performed_job`/`perform_job` ActiveJob
31
- matchers (Isaac Seymour, #1785)
32
- * Default to generating request specs rather than controller specs when
33
- generating a controller (Luka Lüdicke, #2222)
24
+ * Issue a warning when using job matchers with `#at` mis-match on `usec` precision.
25
+ (Jon Rowe, #2350)
26
+ * Generated request specs now have a bare `_spec` suffix instead of `request_spec`.
27
+ (Eloy Espinaco, Luka Lüdicke, #2355, #2356, #2378)
28
+ * Generated scaffold now includes engine route helpers when inside a mountable engine.
29
+ (Andrew W. Lee, #2372)
30
+ * Improve request spec "controller" scafold when no action is specified.
31
+ (Thomas Hareau, #2399)
32
+ * Introduce testing snippets concept (Phil Pirozhkov, Benoit Tigeot, #2423)
33
+ * Prevent collisions with `let(:name)` for Rails 6.1 and `let(:method_name)` on older
34
+ Rails. (Benoit Tigeot, #2461)
35
+
36
+ ### 4.0.2 / 2020-12-26
37
+ [Full Changelog](https://github.com/rspec/rspec-rails/compare/v4.0.1...v4.0.2)
34
38
 
35
39
  Bug Fixes:
36
40
 
37
- * Prevent `driven_by(:selenium)` being called due to hook precedence.
38
- (Takumi Shotoku, #2188)
39
- * Prevent a `WrongScopeError` being thrown during loading fixtures on Rails
40
- 6.1 development version. (Edouard Chin, #2215)
41
- * Fix Mocha mocking support with `should`. (Phil Pirozhkov, #2256)
41
+ * Indent all extra failure lines output from system specs. (Alex Robbin, #2321)
42
+ * Generated request spec for update now uses the correct let. (Paul Hanyzewski, #2344)
43
+ * Return `true`/`false` from predicate methods in config rather than raw values.
44
+ (Phil Pirozhkov, Jon Rowe, #2353, #2354)
45
+ * Remove old #fixture_path feature detection code which broke under newer Rails.
46
+ (Koen Punt, Jon Rowe, #2370)
47
+ * Fix an error when `use_active_record` is `false` (Phil Pirozhkov, #2423)
48
+
49
+ ### 4.0.1 / 2020-05-16
50
+ [Full Changelog](https://github.com/rspec/rspec-rails/compare/v4.0.0...v4.0.1)
51
+
52
+ Bug Fixes:
42
53
 
43
- ### 4.0.0.beta3
44
- [Full Changelog](https://github.com/rspec/rspec-rails/compare/v4.0.0.beta2...v4.0.0.beta3)
54
+ * Remove warning when calling `driven_by` in system specs. (Aubin Lorieux, #2302)
55
+ * Fix comparison of times for `#at` in job matchers. (Jon Rowe, Markus Doits, #2304)
56
+ * Allow `have_enqueued_mail` to match when a sub class of `ActionMailer::DeliveryJob`
57
+ is set using `<Class>.delivery_job=`. (Atsushi Yoshida #2305)
58
+ * Restore Ruby 2.2.x compatibility. (Jon Rowe, #2332)
59
+ * Add `required_ruby_version` to gem spec. (Marc-André Lafortune, #2319, #2338)
60
+
61
+ ### 4.0.0 / 2020-03-24
62
+ [Full Changelog](https://github.com/rspec/rspec-rails/compare/v3.9.1...v4.0.0)
45
63
 
46
64
  Enhancements:
47
65
 
66
+ * Adds support for Rails 6. (Penelope Phippen, Benoit Tigeot, Jon Rowe, #2071)
48
67
  * Adds support for JRuby on Rails 5.2 and 6
49
68
  * Add support for parameterised mailers (Ignatius Reza, #2125)
50
69
  * Add ActionMailbox spec helpers and test type (James Dabbs, #2119)
@@ -55,28 +74,18 @@ Enhancements:
55
74
  * Improve path parsing in view specs render options. (John Hawthorn, #2115)
56
75
  * Add routing spec template as an option for generating controller specs.
57
76
  (David Revelo, #2134)
58
-
59
- Bug Fixes:
60
-
61
- * Replace `before_teardown` as well as `after_teardown` to ensure screenshots
62
- are generated correctly. (Jon Rowe, #2164)
63
- * `ActionView::FixtureResolver#hash` has been renamed to `ActionView::FixtureResolver#data`.
64
- (Penelope Phippen, #2076)
65
- * Add missing require for `have_enqueued_mail` matcher. (Ignatius Reza, #2117)
66
-
67
- ### 4.0.0.beta2
68
- [Full Changelog](https://github.com/rspec/rspec-rails/compare/v4.0.0.beta1...v4.0.0.beta2)
69
-
70
- Bug Fixes:
71
-
72
- * Fix version dependencies in gemspec.
73
-
74
- ### 4.0.0.beta1
75
- [Full Changelog](https://github.com/rspec/rspec-rails/compare/v3.9.0...v4.0.0.beta1)
76
-
77
- Enhancements:
78
-
79
- * Adds support for Rails 6. (Penelope Phippen, Benoit Tigeot, Jon Rowe, #2071)
77
+ * Add argument matcher support to `have_enqueued_*` matchers. (Phil Pirozhkov, #2206)
78
+ * Switch generated templates to use ruby 1.9 hash keys. (Tanbir Hasan, #2224)
79
+ * Add `have_been_performed`/`have_performed_job`/`perform_job` ActiveJob
80
+ matchers (Isaac Seymour, #1785)
81
+ * Default to generating request specs rather than controller specs when
82
+ generating a controller (Luka Lüdicke, #2222)
83
+ * Allow `ActiveJob` matchers `#on_queue` modifier to take symbolic queue names. (Nils Sommer, #2283)
84
+ * The scaffold generator now generates request specs in preference to controller specs.
85
+ (Luka Lüdicke, #2288)
86
+ * Add configuration option to disable ActiveRecord. (Jon Rowe, Phil Pirozhkov, Hermann Mayer, #2266)
87
+ * Set `ActionDispatch::SystemTesting::Server.silence_puma = true` when running system specs.
88
+ (ta1kt0me, Benoit Tigeot, #2289)
80
89
 
81
90
  Bug Fixes:
82
91
 
@@ -86,12 +95,35 @@ Bug Fixes:
86
95
  deprecated. (Pavel Rosický, #2092)
87
96
  * `ActionView::Template#formats` has been deprecated and replaced by
88
97
  `ActionView::Template#format`(Seb Jacobs, #2100)
98
+ * Replace `before_teardown` as well as `after_teardown` to ensure screenshots
99
+ are generated correctly. (Jon Rowe, #2164)
100
+ * `ActionView::FixtureResolver#hash` has been renamed to `ActionView::FixtureResolver#data`.
101
+ (Penelope Phippen, #2076)
102
+ * Prevent `driven_by(:selenium)` being called due to hook precedence.
103
+ (Takumi Shotoku, #2188)
104
+ * Prevent a `WrongScopeError` being thrown during loading fixtures on Rails
105
+ 6.1 development version. (Edouard Chin, #2215)
106
+ * Fix Mocha mocking support with `should`. (Phil Pirozhkov, #2256)
107
+ * Restore previous conditional check for setting `default_url_options` in feature
108
+ specs, prevents a `NoMethodError` in some scenarios. (Eugene Kenny, #2277)
109
+ * Allow changing `ActiveJob::Base.queue_adapter` inside a system spec.
110
+ (Jonathan Rochkind, #2242)
111
+ * `rails generate generator` command now creates related spec file (Joel Azemar, #2217)
112
+ * Relax upper `capybara` version constraint to allow for Capybara 3.x (Phil Pirozhkov, #2281)
113
+ * Clear ActionMailer test mailbox after each example (Benoit Tigeot, #2293)
89
114
 
90
115
  Breaking Changes:
91
116
 
92
117
  * Drops support for Rails below 5.0
93
118
  * Drops support for Ruby below 2.3
94
119
 
120
+ ### 3.9.1 / 2020-03-10
121
+ [Full Changelog](http://github.com/rspec/rspec-rails/compare/v3.9.0...v3.9.1)
122
+
123
+ Bug Fixes:
124
+
125
+ * Add missing require for have_enqueued_mail matcher. (Ignatius Reza, #2117)
126
+
95
127
  ### 3.9.0 / 2019-10-08
96
128
  [Full Changelog](https://github.com/rspec/rspec-rails/compare/v3.8.3...v3.9.0)
97
129
 
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # rspec-rails [![Build Status][]][travis-ci] [![Code Climate][]][code-climate] [![Gem Version][]](gem-version)
1
+ # rspec-rails [![Code Climate][]][code-climate] [![Gem Version][]][gem-version]
2
2
 
3
3
  `rspec-rails` brings the [RSpec][] testing framework to [Ruby on Rails][]
4
4
  as a drop-in alternative to its default testing framework, Minitest.
@@ -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=master
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,23 +20,27 @@ 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
 
27
+ **IMPORTANT** This README / branch refers to the current development build.
28
+ See the [`4-1-maintenance` branch on Github](https://github.com/rspec/rspec-rails/tree/4-0-maintenance) if you want or require the latest stable release.
29
+
25
30
  1. Add `rspec-rails` to **both** the `:development` and `:test` groups
26
31
  of your app’s `Gemfile`:
27
32
 
28
33
  ```ruby
29
34
  # Run against the latest stable release
30
35
  group :development, :test do
31
- gem 'rspec-rails', '~> 4.0'
36
+ gem 'rspec-rails', '~> 4.1.0'
32
37
  end
33
38
 
34
- # Or, run against the master branch
35
- # (requires master-branch versions of all related RSpec libraries)
39
+ # Or, run against the main branch
40
+ # (requires main-branch versions of all related RSpec libraries)
36
41
  group :development, :test do
37
42
  %w[rspec-core rspec-expectations rspec-mocks rspec-rails rspec-support].each do |lib|
38
- gem lib, git: "https://github.com/rspec/#{lib}.git", branch: 'master'
43
+ gem lib, git: "https://github.com/rspec/#{lib}.git", branch: 'main'
39
44
  end
40
45
  end
41
46
  ```
@@ -182,17 +187,17 @@ In addition to [the matchers that come standard in RSpec][],
182
187
  here are some extras that make it easier
183
188
  to test the various parts of a Rails system:
184
189
 
185
- | RSpec matcher | Delegates to | Available in | Notes |
186
- | ------------------------ | ----------------- | ------------------------------- | -------------------------------------------------------- |
187
- | [`be_a_new`][] | | all | primarily intended for controller specs |
188
- | [`render_template`][] | `assert_template` | request / controller / view | use with `expect(response).to` |
189
- | [`redirect_to`][] | `assert_redirect` | request / controller | use with `expect(response).to` |
190
- | [`route_to`] | `assert_routing` | routing / controller | replaces `route_for` from version 1.x |
191
- | [`be_routable`] | | routing / controller | usu. for `expect(...).not_to be_routable` |
192
- | [`have_http_status`][] | | request / controller / feature | |
193
- | [`match_array`][] | | all | for comparing arrays of ActiveRecord objects |
194
- | [`have_been_enqueued`][] | | all | requires config: `ActiveJob::Base.queue_adapter = :test` |
195
- | [`have_enqueued_job`][] | | all | requires config: `ActiveJob::Base.queue_adapter = :test` |
190
+ | RSpec matcher | Delegates to | Available in | Notes |
191
+ | ------------------------ | ------------------- | ------------------------------- | -------------------------------------------------------- |
192
+ | [`be_a_new`][] | | all | primarily intended for controller specs |
193
+ | [`render_template`][] | `assert_template` | request / controller / view | use with `expect(response).to` |
194
+ | [`redirect_to`][] | `assert_redirect` | request / controller | use with `expect(response).to` |
195
+ | [`route_to`] | `assert_recognizes` | routing / controller | use with `expect(...).to route_to` |
196
+ | [`be_routable`] | | routing / controller | use with `expect(...).not_to be_routable` |
197
+ | [`have_http_status`][] | | request / controller / feature | |
198
+ | [`match_array`][] | | all | for comparing arrays of ActiveRecord objects |
199
+ | [`have_been_enqueued`][] | | all | requires config: `ActiveJob::Base.queue_adapter = :test` |
200
+ | [`have_enqueued_job`][] | | all | requires config: `ActiveJob::Base.queue_adapter = :test` |
196
201
 
197
202
  Follow the links above for examples of how each matcher is used.
198
203
 
@@ -16,7 +16,7 @@ module Rspec
16
16
  return unless options[:request_specs]
17
17
 
18
18
  template 'request_spec.rb',
19
- File.join('spec/requests', class_path, "#{file_name}_request_spec.rb")
19
+ File.join('spec/requests', class_path, "#{file_name}_spec.rb")
20
20
  end
21
21
 
22
22
  def generate_controller_spec
@@ -27,7 +27,7 @@ module Rspec
27
27
  end
28
28
 
29
29
  def generate_view_specs
30
- return if actions.empty?
30
+ return if actions.empty? && behavior == :invoke
31
31
  return unless options[:view_specs] && options[:template_engine]
32
32
 
33
33
  empty_directory File.join("spec", "views", file_path)
@@ -1,7 +1,12 @@
1
1
  require 'rails_helper'
2
2
 
3
3
  RSpec.describe "<%= class_name.pluralize %>", <%= type_metatag(:request) %> do
4
- <% namespaced_path = regular_class_path.join('/') %>
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 -%>
5
10
  <% for action in actions -%>
6
11
  describe "GET /<%= action %>" do
7
12
  it "returns http success" do
@@ -1,10 +1,10 @@
1
1
  require "rails_helper"
2
2
 
3
3
  <% module_namespacing do -%>
4
- RSpec.describe <%= Rails.version.to_f >= 5.0 ? class_name.sub(/(Mailer)?$/, 'Mailer') : class_name %>, <%= type_metatag(:mailer) %> do
4
+ RSpec.describe <%= class_name.sub(/(Mailer)?$/, 'Mailer') %>, <%= type_metatag(:mailer) %> do
5
5
  <% for action in actions -%>
6
6
  describe "<%= action %>" do
7
- let(:mail) { <%= Rails.version.to_f >= 5.0 ? class_name.sub(/(Mailer)?$/, 'Mailer') : class_name %>.<%= action %> }
7
+ let(:mail) { <%= class_name.sub(/(Mailer)?$/, 'Mailer') %>.<%= action %> }
8
8
 
9
9
  it "renders the headers" do
10
10
  expect(mail.subject).to eq(<%= action.to_s.humanize.inspect %>)
@@ -5,7 +5,7 @@ class <%= class_name %>Preview < ActionMailer::Preview
5
5
 
6
6
  # Preview this email at http://localhost:3000/rails/mailers/<%= file_path %>/<%= action %>
7
7
  def <%= action %>
8
- <%= Rails.version.to_f >= 5.0 ? class_name.sub(/(Mailer)?$/, 'Mailer') : class_name %>.<%= action %>
8
+ <%= class_name.sub(/(Mailer)?$/, 'Mailer') %>.<%= action %>
9
9
  end
10
10
  <% end -%>
11
11
 
@@ -94,7 +94,7 @@ RSpec.describe "/<%= name.underscore.pluralize %>", <%= type_metatag(:request) %
94
94
  it "updates the requested <%= ns_file_name %>" do
95
95
  <%= file_name %> = <%= class_name %>.create! valid_attributes
96
96
  patch <%= show_helper.tr('@', '') %>,
97
- params: { <%= singular_table_name %>: invalid_attributes }, headers: valid_headers, as: :json
97
+ params: { <%= singular_table_name %>: new_attributes }, headers: valid_headers, as: :json
98
98
  <%= file_name %>.reload
99
99
  skip("Add assertions for updated state")
100
100
  end
@@ -102,9 +102,9 @@ RSpec.describe "/<%= name.underscore.pluralize %>", <%= type_metatag(:request) %
102
102
  it "renders a JSON response with the <%= ns_file_name %>" do
103
103
  <%= file_name %> = <%= class_name %>.create! valid_attributes
104
104
  patch <%= show_helper.tr('@', '') %>,
105
- params: { <%= singular_table_name %>: invalid_attributes }, headers: valid_headers, as: :json
105
+ params: { <%= singular_table_name %>: new_attributes }, headers: valid_headers, as: :json
106
106
  expect(response).to have_http_status(:ok)
107
- expect(response.content_type).to eq("application/json")
107
+ expect(response.content_type).to match(a_string_including("application/json"))
108
108
  end
109
109
  end
110
110
 
@@ -46,11 +46,7 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
46
46
  describe "GET #index" do
47
47
  it "returns a success response" do
48
48
  <%= class_name %>.create! valid_attributes
49
- <% if Rails::VERSION::STRING < '5.0' -%>
50
- get :index, {}, valid_session
51
- <% else -%>
52
49
  get :index, params: {}, session: valid_session
53
- <% end -%>
54
50
  expect(response).to be_successful
55
51
  end
56
52
  end
@@ -59,22 +55,14 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
59
55
  describe "GET #show" do
60
56
  it "returns a success response" do
61
57
  <%= file_name %> = <%= class_name %>.create! valid_attributes
62
- <% if Rails::VERSION::STRING < '5.0' -%>
63
- get :show, {id: <%= file_name %>.to_param}, valid_session
64
- <% else -%>
65
58
  get :show, params: {id: <%= file_name %>.to_param}, session: valid_session
66
- <% end -%>
67
59
  expect(response).to be_successful
68
60
  end
69
61
  end
70
62
 
71
63
  describe "GET #new" do
72
64
  it "returns a success response" do
73
- <% if Rails::VERSION::STRING < '5.0' -%>
74
- get :new, {}, valid_session
75
- <% else -%>
76
65
  get :new, params: {}, session: valid_session
77
- <% end -%>
78
66
  expect(response).to be_successful
79
67
  end
80
68
  end
@@ -82,11 +70,7 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
82
70
  describe "GET #edit" do
83
71
  it "returns a success response" do
84
72
  <%= file_name %> = <%= class_name %>.create! valid_attributes
85
- <% if Rails::VERSION::STRING < '5.0' -%>
86
- get :edit, {id: <%= file_name %>.to_param}, valid_session
87
- <% else -%>
88
73
  get :edit, params: {id: <%= file_name %>.to_param}, session: valid_session
89
- <% end -%>
90
74
  expect(response).to be_successful
91
75
  end
92
76
  end
@@ -95,31 +79,19 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
95
79
  context "with valid params" do
96
80
  it "creates a new <%= class_name %>" do
97
81
  expect {
98
- <% if Rails::VERSION::STRING < '5.0' -%>
99
- post :create, {<%= ns_file_name %>: valid_attributes}, valid_session
100
- <% else -%>
101
82
  post :create, params: {<%= ns_file_name %>: valid_attributes}, session: valid_session
102
- <% end -%>
103
83
  }.to change(<%= class_name %>, :count).by(1)
104
84
  end
105
85
 
106
86
  it "redirects to the created <%= ns_file_name %>" do
107
- <% if Rails::VERSION::STRING < '5.0' -%>
108
- post :create, {<%= ns_file_name %>: valid_attributes}, valid_session
109
- <% else -%>
110
87
  post :create, params: {<%= ns_file_name %>: valid_attributes}, session: valid_session
111
- <% end -%>
112
88
  expect(response).to redirect_to(<%= class_name %>.last)
113
89
  end
114
90
  end
115
91
 
116
92
  context "with invalid params" do
117
93
  it "returns a success response (i.e. to display the 'new' template)" do
118
- <% if Rails::VERSION::STRING < '5.0' -%>
119
- post :create, {<%= ns_file_name %>: invalid_attributes}, valid_session
120
- <% else -%>
121
94
  post :create, params: {<%= ns_file_name %>: invalid_attributes}, session: valid_session
122
- <% end -%>
123
95
  expect(response).to be_successful
124
96
  end
125
97
  end
@@ -133,22 +105,14 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
133
105
 
134
106
  it "updates the requested <%= ns_file_name %>" do
135
107
  <%= file_name %> = <%= class_name %>.create! valid_attributes
136
- <% if Rails::VERSION::STRING < '5.0' -%>
137
- put :update, {id: <%= file_name %>.to_param, <%= ns_file_name %>: new_attributes}, valid_session
138
- <% else -%>
139
108
  put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: new_attributes}, session: valid_session
140
- <% end -%>
141
109
  <%= file_name %>.reload
142
110
  skip("Add assertions for updated state")
143
111
  end
144
112
 
145
113
  it "redirects to the <%= ns_file_name %>" do
146
114
  <%= file_name %> = <%= class_name %>.create! valid_attributes
147
- <% if Rails::VERSION::STRING < '5.0' -%>
148
- put :update, {id: <%= file_name %>.to_param, <%= ns_file_name %>: valid_attributes}, valid_session
149
- <% else -%>
150
115
  put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: valid_attributes}, session: valid_session
151
- <% end -%>
152
116
  expect(response).to redirect_to(<%= file_name %>)
153
117
  end
154
118
  end
@@ -156,11 +120,7 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
156
120
  context "with invalid params" do
157
121
  it "returns a success response (i.e. to display the 'edit' template)" do
158
122
  <%= file_name %> = <%= class_name %>.create! valid_attributes
159
- <% if Rails::VERSION::STRING < '5.0' -%>
160
- put :update, {id: <%= file_name %>.to_param, <%= ns_file_name %>: invalid_attributes}, valid_session
161
- <% else -%>
162
123
  put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: invalid_attributes}, session: valid_session
163
- <% end -%>
164
124
  expect(response).to be_successful
165
125
  end
166
126
  end
@@ -170,21 +130,13 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
170
130
  it "destroys the requested <%= ns_file_name %>" do
171
131
  <%= file_name %> = <%= class_name %>.create! valid_attributes
172
132
  expect {
173
- <% if Rails::VERSION::STRING < '5.0' -%>
174
- delete :destroy, {id: <%= file_name %>.to_param}, valid_session
175
- <% else -%>
176
133
  delete :destroy, params: {id: <%= file_name %>.to_param}, session: valid_session
177
- <% end -%>
178
134
  }.to change(<%= class_name %>, :count).by(-1)
179
135
  end
180
136
 
181
137
  it "redirects to the <%= table_name %> list" do
182
138
  <%= file_name %> = <%= class_name %>.create! valid_attributes
183
- <% if Rails::VERSION::STRING < '5.0' -%>
184
- delete :destroy, {id: <%= file_name %>.to_param}, valid_session
185
- <% else -%>
186
139
  delete :destroy, params: {id: <%= file_name %>.to_param}, session: valid_session
187
- <% end -%>
188
140
  expect(response).to redirect_to(<%= index_helper %>_url)
189
141
  end
190
142
  end
@@ -16,11 +16,7 @@ RSpec.describe "<%= ns_table_name %>/edit", <%= type_metatag(:view) %> do
16
16
  assert_select "form[action=?][method=?]", <%= ns_file_name %>_path(@<%= ns_file_name %>), "post" do
17
17
  <% for attribute in output_attributes -%>
18
18
  <%- name = attribute.respond_to?(:column_name) ? attribute.column_name : attribute.name %>
19
- <% if Rails.version.to_f >= 5.1 -%>
20
19
  assert_select "<%= attribute.input_type -%>[name=?]", "<%= ns_file_name %>[<%= name %>]"
21
- <% else -%>
22
- assert_select "<%= attribute.input_type -%>#<%= ns_file_name %>_<%= name %>[name=?]", "<%= ns_file_name %>[<%= name %>]"
23
- <% end -%>
24
20
  <% end -%>
25
21
  end
26
22
  end
@@ -15,11 +15,7 @@ RSpec.describe "<%= ns_table_name %>/new", <%= type_metatag(:view) %> do
15
15
  assert_select "form[action=?][method=?]", <%= index_helper %>_path, "post" do
16
16
  <% for attribute in output_attributes -%>
17
17
  <%- name = attribute.respond_to?(:column_name) ? attribute.column_name : attribute.name %>
18
- <% if Rails.version.to_f >= 5.1 -%>
19
18
  assert_select "<%= attribute.input_type -%>[name=?]", "<%= ns_file_name %>[<%= name %>]"
20
- <% else -%>
21
- assert_select "<%= attribute.input_type -%>#<%= ns_file_name %>_<%= name %>[name=?]", "<%= ns_file_name %>[<%= name %>]"
22
- <% end -%>
23
19
  <% end -%>
24
20
  end
25
21
  end
@@ -14,6 +14,10 @@
14
14
 
15
15
  <% module_namespacing do -%>
16
16
  RSpec.describe "/<%= name.underscore.pluralize %>", <%= type_metatag(:request) %> do
17
+ <% if mountable_engine? -%>
18
+ include Engine.routes.url_helpers
19
+ <% end -%>
20
+
17
21
  # <%= class_name %>. As you add validations to <%= class_name %>, be sure to
18
22
  # adjust the attributes here as well.
19
23
  let(:valid_attributes) {
@@ -1,25 +1,23 @@
1
1
  require 'generators/rspec'
2
2
 
3
- if ::Rails::VERSION::STRING >= '5.1'
4
- module Rspec
5
- module Generators
6
- # @private
7
- class SystemGenerator < Base
8
- class_option :system_specs, type: :boolean, default: true, desc: "Generate system specs"
3
+ module Rspec
4
+ module Generators
5
+ # @private
6
+ class SystemGenerator < Base
7
+ class_option :system_specs, type: :boolean, default: true, desc: "Generate system specs"
9
8
 
10
- def generate_system_spec
11
- return unless options[:system_specs]
9
+ def generate_system_spec
10
+ return unless options[:system_specs]
12
11
 
13
- template template_name, File.join('spec/system', class_path, filename)
14
- end
12
+ template template_name, File.join('spec/system', class_path, filename)
13
+ end
15
14
 
16
- def template_name
17
- 'system_spec.rb'
18
- end
15
+ def template_name
16
+ 'system_spec.rb'
17
+ end
19
18
 
20
- def filename
21
- "#{table_name}_spec.rb"
22
- end
19
+ def filename
20
+ "#{table_name}_spec.rb"
23
21
  end
24
22
  end
25
23
  end
data/lib/rspec-rails.rb CHANGED
@@ -7,13 +7,11 @@ module RSpec
7
7
  # Railtie to hook into Rails.
8
8
  class Railtie < ::Rails::Railtie
9
9
  # As of Rails 5.1.0 you can register directories to work with `rake notes`
10
- if ::Rails::VERSION::STRING >= '5.1'
11
- require 'rails/source_annotation_extractor'
12
- if ::Rails::VERSION::STRING >= '6.0'
13
- ::Rails::SourceAnnotationExtractor::Annotation.register_directories("spec")
14
- else
15
- SourceAnnotationExtractor::Annotation.register_directories("spec")
16
- end
10
+ require 'rails/source_annotation_extractor'
11
+ if ::Rails::VERSION::STRING >= '6.0'
12
+ ::Rails::SourceAnnotationExtractor::Annotation.register_directories("spec")
13
+ else
14
+ SourceAnnotationExtractor::Annotation.register_directories("spec")
17
15
  end
18
16
  generators = config.app_generators
19
17
  generators.integration_tool :rspec
@@ -1,3 +1,4 @@
1
+ # rubocop: disable Metrics/ModuleLength
1
2
  module RSpec
2
3
  module Rails
3
4
  # Fake class to document RSpec Rails configuration options. In practice,
@@ -55,7 +56,7 @@ module RSpec
55
56
  end
56
57
 
57
58
  # @private
58
- def self.initialize_configuration(config) # rubocop:disable Metrics/MethodLength
59
+ def self.initialize_configuration(config) # rubocop:disable Metrics/MethodLength,Metrics/CyclomaticComplexity
59
60
  config.backtrace_exclusion_patterns << /vendor\//
60
61
  config.backtrace_exclusion_patterns << %r{lib/rspec/rails}
61
62
 
@@ -79,10 +80,8 @@ module RSpec
79
80
  # `RSpec::Rails::FixtureSupport` directly instead
80
81
  config.include RSpec::Rails::FixtureSupport
81
82
 
82
- if ::Rails::VERSION::STRING > '5'
83
- config.add_setting :file_fixture_path, default: 'spec/fixtures/files'
84
- config.include RSpec::Rails::FileFixtureSupport
85
- end
83
+ config.add_setting :file_fixture_path, default: 'spec/fixtures/files'
84
+ config.include RSpec::Rails::FileFixtureSupport
86
85
 
87
86
  # Add support for fixture_path on fixture_file_upload
88
87
  config.include RSpec::Rails::FixtureFileUploadSupport
@@ -105,7 +104,41 @@ module RSpec
105
104
  end
106
105
 
107
106
  def render_views?
108
- rendering_views
107
+ rendering_views?
108
+ end
109
+
110
+ undef :rendering_views? if respond_to?(:rendering_views?)
111
+ def rendering_views?
112
+ !!rendering_views
113
+ end
114
+
115
+ # Define boolean predicates rather than relying on rspec-core due
116
+ # to the bug fix in rspec/rspec-core#2736, note some of these
117
+ # predicates are a bit nonsensical, but they exist for backwards
118
+ # compatibility, we can tidy these up in `rspec-rails` 5.
119
+ undef :fixture_path? if respond_to?(:fixture_path?)
120
+ def fixture_path?
121
+ !!fixture_path
122
+ end
123
+
124
+ undef :global_fixtures? if respond_to?(:global_fixtures?)
125
+ def global_fixtures?
126
+ !!global_fixtures
127
+ end
128
+
129
+ undef :infer_base_class_for_anonymous_controllers? if respond_to?(:infer_base_class_for_anonymous_controllers?)
130
+ def infer_base_class_for_anonymous_controllers?
131
+ !!infer_base_class_for_anonymous_controllers
132
+ end
133
+
134
+ undef :use_instantiated_fixtures? if respond_to?(:use_instantiated_fixtures?)
135
+ def use_instantiated_fixtures?
136
+ !!use_instantiated_fixtures
137
+ end
138
+
139
+ undef :use_transactional_fixtures? if respond_to?(:use_transactional_fixtures?)
140
+ def use_transactional_fixtures?
141
+ !!use_transactional_fixtures
109
142
  end
110
143
 
111
144
  def infer_spec_type_from_file_location!
@@ -156,3 +189,4 @@ module RSpec
156
189
  initialize_configuration RSpec.configuration
157
190
  end
158
191
  end
192
+ # rubocop: enable Metrics/ModuleLength
@@ -13,7 +13,7 @@ module RSpec
13
13
  def self.create_inbound_email(arg)
14
14
  case arg
15
15
  when Hash
16
- create_inbound_email_from_mail(arg)
16
+ create_inbound_email_from_mail(**arg)
17
17
  else
18
18
  create_inbound_email_from_source(arg.to_s)
19
19
  end
@@ -21,8 +21,8 @@ if defined?(ActionMailer)
21
21
 
22
22
  included do
23
23
  include ::Rails.application.routes.url_helpers
24
- options = ::Rails.configuration.action_mailer.default_url_options
25
- options&.each { |key, value| default_url_options[key] = value }
24
+ options = ::Rails.configuration.action_mailer.default_url_options || {}
25
+ options.each { |key, value| default_url_options[key] = value }
26
26
  end
27
27
 
28
28
  # Class-level DSL for mailer specs.
@@ -10,10 +10,7 @@ module RSpec
10
10
  include RSpec::Rails::Matchers::RedirectTo
11
11
  include RSpec::Rails::Matchers::RenderTemplate
12
12
  include ActionController::TemplateAssertions
13
-
14
- if ActionPack::VERSION::MAJOR >= 5
15
- include ActionDispatch::IntegrationTest::Behavior
16
- end
13
+ include ActionDispatch::IntegrationTest::Behavior
17
14
 
18
15
  # Delegates to `Rails.application`.
19
16
  def app
@@ -96,8 +96,8 @@ module RSpec
96
96
  end
97
97
  end
98
98
 
99
- def driven_by(*args, &blk)
100
- @driver = ::ActionDispatch::SystemTestCase.driven_by(*args, &blk).tap(&:use)
99
+ def driven_by(driver, **driver_options, &blk)
100
+ @driver = ::ActionDispatch::SystemTestCase.driven_by(driver, **driver_options, &blk).tap(&:use)
101
101
  end
102
102
 
103
103
  before do
@@ -114,7 +114,8 @@ module RSpec
114
114
  original_after_teardown.bind(self).call
115
115
  ensure
116
116
  myio = $stdout
117
- RSpec.current_example.metadata[:extra_failure_lines] = myio.string
117
+ myio.rewind
118
+ RSpec.current_example.metadata[:extra_failure_lines] = myio.readlines
118
119
  $stdout = orig_stdout
119
120
  end
120
121
  end
@@ -1,7 +1,10 @@
1
1
  RSpec.configure do |rspec|
2
2
  # Delay this in order to give users a chance to configure `expect_with`...
3
3
  rspec.before(:suite) do
4
- if defined?(RSpec::Matchers) && RSpec::Matchers.configuration.syntax.include?(:should) && defined?(ActiveRecord::Associations)
4
+ if defined?(RSpec::Matchers) &&
5
+ RSpec::Matchers.configuration.respond_to?(:syntax) && # RSpec 4 dropped support for monkey-patching `should` syntax
6
+ RSpec::Matchers.configuration.syntax.include?(:should) &&
7
+ defined?(ActiveRecord::Associations)
5
8
  RSpec::Matchers.configuration.add_should_and_should_not_to ActiveRecord::Associations::CollectionProxy
6
9
  end
7
10
  end
@@ -1,16 +1,14 @@
1
- if ::Rails::VERSION::STRING > '5'
2
- require 'active_support/testing/file_fixtures'
1
+ require 'active_support/testing/file_fixtures'
3
2
 
4
- module RSpec
5
- module Rails
6
- # @private
7
- module FileFixtureSupport
8
- extend ActiveSupport::Concern
9
- include ActiveSupport::Testing::FileFixtures
3
+ module RSpec
4
+ module Rails
5
+ # @private
6
+ module FileFixtureSupport
7
+ extend ActiveSupport::Concern
8
+ include ActiveSupport::Testing::FileFixtures
10
9
 
11
- included do
12
- self.file_fixture_path = RSpec.configuration.file_fixture_path
13
- end
10
+ included do
11
+ self.file_fixture_path = RSpec.configuration.file_fixture_path
14
12
  end
15
13
  end
16
14
  end
@@ -6,33 +6,49 @@ module RSpec
6
6
 
7
7
  private
8
8
 
9
- def rails_fixture_file_wrapper
10
- RailsFixtureFileWrapper.fixture_path = nil
11
- resolved_fixture_path = (fixture_path || RSpec.configuration.fixture_path || '').to_s
12
- RailsFixtureFileWrapper.fixture_path = File.join(resolved_fixture_path, '') unless resolved_fixture_path.strip.empty?
13
- RailsFixtureFileWrapper.instance
9
+ # In Rails 6.2 fixture file path needs to be relative to `file_fixture_path` instead, this change
10
+ # was brought in with a deprecation warning on 6.1. In Rails 6.2 expect to rework this to remove
11
+ # the old accessor.
12
+ if ::Rails.version.to_f >= 6.1
13
+ def rails_fixture_file_wrapper
14
+ RailsFixtureFileWrapper.file_fixture_path = nil
15
+ resolved_fixture_path =
16
+ if respond_to?(:file_fixture_path) && !file_fixture_path.nil?
17
+ file_fixture_path.to_s
18
+ else
19
+ (RSpec.configuration.fixture_path || '').to_s
20
+ end
21
+ RailsFixtureFileWrapper.file_fixture_path = File.join(resolved_fixture_path, '') unless resolved_fixture_path.strip.empty?
22
+ RailsFixtureFileWrapper.instance
23
+ end
24
+ else
25
+ def rails_fixture_file_wrapper
26
+ RailsFixtureFileWrapper.fixture_path = nil
27
+ resolved_fixture_path =
28
+ if respond_to?(:fixture_path) && !fixture_path.nil?
29
+ fixture_path.to_s
30
+ else
31
+ (RSpec.configuration.fixture_path || '').to_s
32
+ end
33
+ RailsFixtureFileWrapper.fixture_path = File.join(resolved_fixture_path, '') unless resolved_fixture_path.strip.empty?
34
+ RailsFixtureFileWrapper.instance
35
+ end
14
36
  end
15
37
 
16
38
  class RailsFixtureFileWrapper
17
39
  include ActionDispatch::TestProcess if defined?(ActionDispatch::TestProcess)
18
40
 
41
+ if ::Rails.version.to_f >= 6.1
42
+ include ActiveSupport::Testing::FileFixtures
43
+ end
44
+
19
45
  class << self
20
- attr_reader :fixture_path
46
+ attr_accessor :fixture_path
21
47
 
22
48
  # Get instance of wrapper
23
49
  def instance
24
50
  @instance ||= new
25
51
  end
26
-
27
- # Override fixture_path set
28
- # to support Rails 3.0->3.1 using ActionController::TestCase class to resolve fixture_path
29
- # see https://apidock.com/rails/v3.0.0/ActionDispatch/TestProcess/fixture_file_upload
30
- def fixture_path=(value)
31
- if ActionController::TestCase.respond_to?(:fixture_path)
32
- ActionController::TestCase.fixture_path = value
33
- end
34
- @fixture_path = value
35
- end
36
52
  end
37
53
  end
38
54
  end
@@ -9,16 +9,19 @@ module RSpec
9
9
  include RSpec::Rails::MinitestAssertionAdapter
10
10
  include ActiveRecord::TestFixtures
11
11
 
12
+ # @private prevent ActiveSupport::TestFixtures to start a DB transaction.
13
+ # Monkey patched to avoid collisions with 'let(:name)' in Rails 6.1 and after
14
+ # and let(:method_name) before Rails 6.1.
15
+ def run_in_transaction?
16
+ use_transactional_tests && !self.class.uses_transaction?(self)
17
+ end
18
+
12
19
  included do
13
20
  if RSpec.configuration.use_active_record?
14
21
  include Fixtures
15
22
 
16
23
  self.fixture_path = RSpec.configuration.fixture_path
17
- if ::Rails::VERSION::STRING > '5'
18
- self.use_transactional_tests = RSpec.configuration.use_transactional_fixtures
19
- else
20
- self.use_transactional_fixtures = RSpec.configuration.use_transactional_fixtures
21
- end
24
+ self.use_transactional_tests = RSpec.configuration.use_transactional_fixtures
22
25
  self.use_instantiated_fixtures = RSpec.configuration.use_instantiated_fixtures
23
26
 
24
27
  fixtures RSpec.configuration.global_fixtures if RSpec.configuration.global_fixtures
@@ -50,13 +53,6 @@ module RSpec
50
53
  end
51
54
  end
52
55
  end
53
-
54
- if ::Rails.version.to_f >= 6.1
55
- # @private return the example name for TestFixtures
56
- def name
57
- @example
58
- end
59
- end
60
56
  end
61
57
  end
62
58
  end
@@ -22,11 +22,20 @@ module RSpec
22
22
  @inbound_email = create_inbound_email(message)
23
23
  end
24
24
 
25
- def matches?(mailbox)
26
- @mailbox = mailbox
27
- @receiver = ApplicationMailbox.router.send(:match_to_mailbox, inbound_email)
25
+ if defined?(::ApplicationMailbox) && ::ApplicationMailbox.router.respond_to?(:mailbox_for)
26
+ def matches?(mailbox)
27
+ @mailbox = mailbox
28
+ @receiver = ApplicationMailbox.router.mailbox_for(inbound_email)
28
29
 
29
- @receiver == @mailbox
30
+ @receiver == @mailbox
31
+ end
32
+ else
33
+ def matches?(mailbox)
34
+ @mailbox = mailbox
35
+ @receiver = ApplicationMailbox.router.send(:match_to_mailbox, inbound_email)
36
+
37
+ @receiver == @mailbox
38
+ end
30
39
  end
31
40
 
32
41
  def failure_message
@@ -41,7 +50,7 @@ module RSpec
41
50
  "expected #{describe_inbound_email} not to route to #{mailbox}"
42
51
  end
43
52
 
44
- private
53
+ private
45
54
 
46
55
  attr_reader :inbound_email, :mailbox, :receiver
47
56
 
@@ -30,8 +30,12 @@ module RSpec
30
30
  self
31
31
  end
32
32
 
33
- def at(date)
34
- @at = date
33
+ def at(time_or_date)
34
+ case time_or_date
35
+ when Time then @at = Time.at(time_or_date.to_f)
36
+ else
37
+ @at = time_or_date
38
+ end
35
39
  self
36
40
  end
37
41
 
@@ -159,7 +163,29 @@ module RSpec
159
163
  return job[:at].nil? if @at == :no_wait
160
164
  return false unless job[:at]
161
165
 
162
- values_match?(@at, Time.at(job[:at]))
166
+ scheduled_at = Time.at(job[:at])
167
+ values_match?(@at, scheduled_at) || check_for_inprecise_value(scheduled_at)
168
+ end
169
+
170
+ def check_for_inprecise_value(scheduled_at)
171
+ return unless Time === @at && values_match?(@at.change(usec: 0), scheduled_at)
172
+
173
+ RSpec.warn_with((<<-WARNING).gsub(/^\s+\|/, '').chomp)
174
+ |[WARNING] Your expected `at(...)` value does not match the job scheduled_at value
175
+ |unless microseconds are removed. This precision error often occurs when checking
176
+ |values against `Time.current` / `Time.now` which have usec precision, but Rails
177
+ |uses `n.seconds.from_now` internally which has a usec count of `0`.
178
+ |
179
+ |Use `change(usec: 0)` to correct these values. For example:
180
+ |
181
+ |`Time.current.change(usec: 0)`
182
+ |
183
+ |Note: RSpec cannot do this for you because jobs can be scheduled with usec
184
+ |precision and we do not know wether it is on purpose or not.
185
+ |
186
+ |
187
+ WARNING
188
+ false
163
189
  end
164
190
 
165
191
  def set_expected_number(relativity, count)
@@ -131,15 +131,15 @@ module RSpec
131
131
  end
132
132
 
133
133
  def legacy_mail?(job)
134
- job[:job] == ActionMailer::DeliveryJob
134
+ job[:job] <= ActionMailer::DeliveryJob
135
135
  end
136
136
 
137
137
  def parameterized_mail?(job)
138
- RSpec::Rails::FeatureCheck.has_action_mailer_parameterized? && job[:job] == ActionMailer::Parameterized::DeliveryJob
138
+ RSpec::Rails::FeatureCheck.has_action_mailer_parameterized? && job[:job] <= ActionMailer::Parameterized::DeliveryJob
139
139
  end
140
140
 
141
141
  def unified_mail?(job)
142
- RSpec::Rails::FeatureCheck.has_action_mailer_unified_delivery? && job[:job] == ActionMailer::MailDeliveryJob
142
+ RSpec::Rails::FeatureCheck.has_action_mailer_unified_delivery? && job[:job] <= ActionMailer::MailDeliveryJob
143
143
  end
144
144
  end
145
145
  # @api public
@@ -1,3 +1,3 @@
1
- if defined?(ActiveRecord::Relation)
1
+ if defined?(ActiveRecord::Relation) && defined?(RSpec::Matchers::BuiltIn::OperatorMatcher) # RSpec 4 removed OperatorMatcher
2
2
  RSpec::Matchers::BuiltIn::OperatorMatcher.register(ActiveRecord::Relation, '=~', RSpec::Matchers::BuiltIn::ContainExactly)
3
3
  end
@@ -3,7 +3,7 @@ module RSpec
3
3
  # Version information for RSpec Rails.
4
4
  module Version
5
5
  # Current version of RSpec Rails, in semantic versioning format.
6
- STRING = '4.0.0'
6
+ STRING = '5.0.0'
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 5.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Chelimsky
8
8
  - Andy Lindeman
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain:
12
12
  - |
@@ -44,7 +44,7 @@ cert_chain:
44
44
  ZsVDj6a7lH3cNqtWXZxrb2wO38qV5AkYj8SQK7Hj3/Yui9myUX3crr+PdetazSqQ
45
45
  F3MdtaDehhjC
46
46
  -----END CERTIFICATE-----
47
- date: 2020-03-24 00:00:00.000000000 Z
47
+ date: 2021-03-09 00:00:00.000000000 Z
48
48
  dependencies:
49
49
  - !ruby/object:Gem::Dependency
50
50
  name: actionpack
@@ -52,112 +52,112 @@ dependencies:
52
52
  requirements:
53
53
  - - ">="
54
54
  - !ruby/object:Gem::Version
55
- version: '4.2'
55
+ version: '5.2'
56
56
  type: :runtime
57
57
  prerelease: false
58
58
  version_requirements: !ruby/object:Gem::Requirement
59
59
  requirements:
60
60
  - - ">="
61
61
  - !ruby/object:Gem::Version
62
- version: '4.2'
62
+ version: '5.2'
63
63
  - !ruby/object:Gem::Dependency
64
64
  name: activesupport
65
65
  requirement: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - ">="
68
68
  - !ruby/object:Gem::Version
69
- version: '4.2'
69
+ version: '5.2'
70
70
  type: :runtime
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
73
73
  requirements:
74
74
  - - ">="
75
75
  - !ruby/object:Gem::Version
76
- version: '4.2'
76
+ version: '5.2'
77
77
  - !ruby/object:Gem::Dependency
78
78
  name: railties
79
79
  requirement: !ruby/object:Gem::Requirement
80
80
  requirements:
81
81
  - - ">="
82
82
  - !ruby/object:Gem::Version
83
- version: '4.2'
83
+ version: '5.2'
84
84
  type: :runtime
85
85
  prerelease: false
86
86
  version_requirements: !ruby/object:Gem::Requirement
87
87
  requirements:
88
88
  - - ">="
89
89
  - !ruby/object:Gem::Version
90
- version: '4.2'
90
+ version: '5.2'
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: rspec-core
93
93
  requirement: !ruby/object:Gem::Requirement
94
94
  requirements:
95
95
  - - "~>"
96
96
  - !ruby/object:Gem::Version
97
- version: '3.9'
97
+ version: '3.10'
98
98
  type: :runtime
99
99
  prerelease: false
100
100
  version_requirements: !ruby/object:Gem::Requirement
101
101
  requirements:
102
102
  - - "~>"
103
103
  - !ruby/object:Gem::Version
104
- version: '3.9'
104
+ version: '3.10'
105
105
  - !ruby/object:Gem::Dependency
106
106
  name: rspec-expectations
107
107
  requirement: !ruby/object:Gem::Requirement
108
108
  requirements:
109
109
  - - "~>"
110
110
  - !ruby/object:Gem::Version
111
- version: '3.9'
111
+ version: '3.10'
112
112
  type: :runtime
113
113
  prerelease: false
114
114
  version_requirements: !ruby/object:Gem::Requirement
115
115
  requirements:
116
116
  - - "~>"
117
117
  - !ruby/object:Gem::Version
118
- version: '3.9'
118
+ version: '3.10'
119
119
  - !ruby/object:Gem::Dependency
120
120
  name: rspec-mocks
121
121
  requirement: !ruby/object:Gem::Requirement
122
122
  requirements:
123
123
  - - "~>"
124
124
  - !ruby/object:Gem::Version
125
- version: '3.9'
125
+ version: '3.10'
126
126
  type: :runtime
127
127
  prerelease: false
128
128
  version_requirements: !ruby/object:Gem::Requirement
129
129
  requirements:
130
130
  - - "~>"
131
131
  - !ruby/object:Gem::Version
132
- version: '3.9'
132
+ version: '3.10'
133
133
  - !ruby/object:Gem::Dependency
134
134
  name: rspec-support
135
135
  requirement: !ruby/object:Gem::Requirement
136
136
  requirements:
137
137
  - - "~>"
138
138
  - !ruby/object:Gem::Version
139
- version: '3.9'
139
+ version: '3.10'
140
140
  type: :runtime
141
141
  prerelease: false
142
142
  version_requirements: !ruby/object:Gem::Requirement
143
143
  requirements:
144
144
  - - "~>"
145
145
  - !ruby/object:Gem::Version
146
- version: '3.9'
146
+ version: '3.10'
147
147
  - !ruby/object:Gem::Dependency
148
148
  name: ammeter
149
149
  requirement: !ruby/object:Gem::Requirement
150
150
  requirements:
151
151
  - - "~>"
152
152
  - !ruby/object:Gem::Version
153
- version: 1.1.2
153
+ version: 1.1.5
154
154
  type: :development
155
155
  prerelease: false
156
156
  version_requirements: !ruby/object:Gem::Requirement
157
157
  requirements:
158
158
  - - "~>"
159
159
  - !ruby/object:Gem::Version
160
- version: 1.1.2
160
+ version: 1.1.5
161
161
  - !ruby/object:Gem::Dependency
162
162
  name: aruba
163
163
  requirement: !ruby/object:Gem::Requirement
@@ -296,11 +296,11 @@ licenses:
296
296
  - MIT
297
297
  metadata:
298
298
  bug_tracker_uri: https://github.com/rspec/rspec-rails/issues
299
- changelog_uri: https://github.com/rspec/rspec-rails/blob/v4.0.0/Changelog.md
299
+ changelog_uri: https://github.com/rspec/rspec-rails/blob/v5.0.0/Changelog.md
300
300
  documentation_uri: https://rspec.info/documentation/
301
301
  mailing_list_uri: https://groups.google.com/forum/#!forum/rspec
302
302
  source_code_uri: https://github.com/rspec/rspec-rails
303
- post_install_message:
303
+ post_install_message:
304
304
  rdoc_options:
305
305
  - "--charset=UTF-8"
306
306
  require_paths:
@@ -309,15 +309,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
309
309
  requirements:
310
310
  - - ">="
311
311
  - !ruby/object:Gem::Version
312
- version: '0'
312
+ version: 2.2.0
313
313
  required_rubygems_version: !ruby/object:Gem::Requirement
314
314
  requirements:
315
315
  - - ">="
316
316
  - !ruby/object:Gem::Version
317
317
  version: '0'
318
318
  requirements: []
319
- rubygems_version: 3.1.2
320
- signing_key:
319
+ rubygems_version: 3.2.4
320
+ signing_key:
321
321
  specification_version: 4
322
322
  summary: RSpec for Rails
323
323
  test_files: []
metadata.gz.sig CHANGED
Binary file