rspec-rails 4.0.1 → 5.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/Changelog.md +91 -2
  4. data/README.md +41 -32
  5. data/lib/generators/rspec/controller/controller_generator.rb +2 -2
  6. data/lib/generators/rspec/controller/templates/request_spec.rb +6 -1
  7. data/lib/generators/rspec/install/templates/spec/rails_helper.rb +1 -1
  8. data/lib/generators/rspec/job/job_generator.rb +2 -1
  9. data/lib/generators/rspec/job/templates/job_spec.rb.erb +1 -1
  10. data/lib/generators/rspec/mailer/templates/mailer_spec.rb +2 -2
  11. data/lib/generators/rspec/mailer/templates/preview.rb +1 -1
  12. data/lib/generators/rspec/scaffold/scaffold_generator.rb +4 -0
  13. data/lib/generators/rspec/scaffold/templates/api_controller_spec.rb +13 -13
  14. data/lib/generators/rspec/scaffold/templates/api_request_spec.rb +20 -20
  15. data/lib/generators/rspec/scaffold/templates/controller_spec.rb +10 -58
  16. data/lib/generators/rspec/scaffold/templates/edit_spec.rb +0 -4
  17. data/lib/generators/rspec/scaffold/templates/new_spec.rb +0 -4
  18. data/lib/generators/rspec/scaffold/templates/request_spec.rb +23 -18
  19. data/lib/generators/rspec/system/system_generator.rb +14 -16
  20. data/lib/rspec/rails/configuration.rb +40 -6
  21. data/lib/rspec/rails/example/controller_example_group.rb +1 -0
  22. data/lib/rspec/rails/example/mailbox_example_group.rb +1 -1
  23. data/lib/rspec/rails/example/request_example_group.rb +1 -4
  24. data/lib/rspec/rails/example/system_example_group.rb +3 -2
  25. data/lib/rspec/rails/extensions/active_record/proxy.rb +4 -1
  26. data/lib/rspec/rails/file_fixture_support.rb +9 -11
  27. data/lib/rspec/rails/fixture_file_upload_support.rb +32 -16
  28. data/lib/rspec/rails/fixture_support.rb +9 -12
  29. data/lib/rspec/rails/matchers/action_mailbox.rb +14 -5
  30. data/lib/rspec/rails/matchers/active_job.rb +23 -1
  31. data/lib/rspec/rails/matchers/have_enqueued_mail.rb +30 -2
  32. data/lib/rspec/rails/matchers/have_http_status.rb +4 -4
  33. data/lib/rspec/rails/matchers/relation_match_array.rb +1 -1
  34. data/lib/rspec/rails/version.rb +1 -1
  35. data/lib/rspec-rails.rb +5 -7
  36. data.tar.gz.sig +0 -0
  37. metadata +39 -27
  38. metadata.gz.sig +0 -0
@@ -163,7 +163,29 @@ module RSpec
163
163
  return job[:at].nil? if @at == :no_wait
164
164
  return false unless job[:at]
165
165
 
166
- 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
167
189
  end
168
190
 
169
191
  def set_expected_number(relativity, count)
@@ -4,6 +4,7 @@
4
4
  require "rspec/mocks/argument_matchers"
5
5
  require "rspec/rails/matchers/active_job"
6
6
 
7
+ # rubocop: disable Metrics/ClassLength
7
8
  module RSpec
8
9
  module Rails
9
10
  module Matchers
@@ -119,9 +120,11 @@ module RSpec
119
120
  end
120
121
 
121
122
  def mail_job_message(job)
122
- mailer_method = job[:args][0..1].join('.')
123
+ job_args = deserialize_arguments(job)
124
+
125
+ mailer_method = job_args[0..1].join('.')
126
+ mailer_args = job_args[3..-1]
123
127
 
124
- mailer_args = job[:args][3..-1]
125
128
  msg_parts = []
126
129
  msg_parts << "with #{mailer_args}" if mailer_args.any?
127
130
  msg_parts << "on queue #{job[:queue]}" if job[:queue] && job[:queue] != 'mailers'
@@ -130,6 +133,30 @@ module RSpec
130
133
  "#{mailer_method} #{msg_parts.join(', ')}".strip
131
134
  end
132
135
 
136
+ # Ruby 3.1 changed how params were serialized on Rails 6.1
137
+ # so we override the active job implementation and customise it here.
138
+ def deserialize_arguments(job)
139
+ args = super
140
+
141
+ return args unless Hash === args.last
142
+
143
+ hash = args.pop
144
+
145
+ if hash.key?("_aj_ruby2_keywords")
146
+ keywords = hash["_aj_ruby2_keywords"]
147
+
148
+ original_hash = keywords.each_with_object({}) { |new_hash, keyword| new_hash[keyword.to_sym] = hash[keyword] }
149
+
150
+ args + [original_hash]
151
+ elsif hash.key?(:args) && hash.key?(:params)
152
+ args + [hash]
153
+ elsif hash.key?(:args)
154
+ args + hash[:args]
155
+ else
156
+ args + [hash]
157
+ end
158
+ end
159
+
133
160
  def legacy_mail?(job)
134
161
  job[:job] <= ActionMailer::DeliveryJob
135
162
  end
@@ -196,3 +223,4 @@ module RSpec
196
223
  end
197
224
  end
198
225
  end
226
+ # rubocop: enable Metrics/ClassLength
@@ -1,6 +1,6 @@
1
1
  # The following code inspired and modified from Rails' `assert_response`:
2
2
  #
3
- # https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/testing/assertions/response.rb#L22-L38
3
+ # https://github.com/rails/rails/blob/main/actionpack/lib/action_dispatch/testing/assertions/response.rb#L22-L38
4
4
  #
5
5
  # Thank you to all the Rails devs who did the heavy lifting on this!
6
6
 
@@ -243,7 +243,7 @@ module RSpec
243
243
 
244
244
  # @return [Array<Symbol>] of status codes which represent a HTTP status
245
245
  # code "group"
246
- # @see https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/testing/test_response.rb `ActionDispatch::TestResponse`
246
+ # @see https://github.com/rails/rails/blob/main/actionpack/lib/action_dispatch/testing/test_response.rb `ActionDispatch::TestResponse`
247
247
  def self.valid_statuses
248
248
  [
249
249
  :error, :success, :missing,
@@ -313,7 +313,7 @@ module RSpec
313
313
 
314
314
  # @return [String] formatting the associated code(s) for the various
315
315
  # status code "groups"
316
- # @see https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/testing/test_response.rb `ActionDispatch::TestResponse`
316
+ # @see https://github.com/rails/rails/blob/main/actionpack/lib/action_dispatch/testing/test_response.rb `ActionDispatch::TestResponse`
317
317
  # @see https://github.com/rack/rack/blob/master/lib/rack/response.rb `Rack::Response`
318
318
  def type_codes
319
319
  # At the time of this commit the most recent version of
@@ -373,7 +373,7 @@ module RSpec
373
373
  # expect(response).to have_http_status(404)
374
374
  # expect(page).to have_http_status(:created)
375
375
  #
376
- # @see https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/testing/test_response.rb `ActionDispatch::TestResponse`
376
+ # @see https://github.com/rails/rails/blob/main/actionpack/lib/action_dispatch/testing/test_response.rb `ActionDispatch::TestResponse`
377
377
  # @see https://github.com/rack/rack/blob/master/lib/rack/utils.rb `Rack::Utils::SYMBOL_TO_STATUS_CODE`
378
378
  def have_http_status(target)
379
379
  raise ArgumentError, "Invalid HTTP status: nil" unless target
@@ -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.1'
6
+ STRING = '5.1.0'
7
7
  end
8
8
  end
9
9
  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
data.tar.gz.sig CHANGED
Binary file
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.1
4
+ version: 5.1.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-05-16 00:00:00.000000000 Z
47
+ date: 2022-01-26 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
@@ -176,16 +176,28 @@ dependencies:
176
176
  name: cucumber
177
177
  requirement: !ruby/object:Gem::Requirement
178
178
  requirements:
179
- - - "~>"
179
+ - - ">="
180
+ - !ruby/object:Gem::Version
181
+ version: '3.2'
182
+ - - "!="
183
+ - !ruby/object:Gem::Version
184
+ version: 4.0.0
185
+ - - "<"
180
186
  - !ruby/object:Gem::Version
181
- version: 1.3.5
187
+ version: 8.0.0
182
188
  type: :development
183
189
  prerelease: false
184
190
  version_requirements: !ruby/object:Gem::Requirement
185
191
  requirements:
186
- - - "~>"
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '3.2'
195
+ - - "!="
196
+ - !ruby/object:Gem::Version
197
+ version: 4.0.0
198
+ - - "<"
187
199
  - !ruby/object:Gem::Version
188
- version: 1.3.5
200
+ version: 8.0.0
189
201
  description: rspec-rails is a testing framework for Rails 5+.
190
202
  email: rspec@googlegroups.com
191
203
  executables: []
@@ -296,11 +308,11 @@ licenses:
296
308
  - MIT
297
309
  metadata:
298
310
  bug_tracker_uri: https://github.com/rspec/rspec-rails/issues
299
- changelog_uri: https://github.com/rspec/rspec-rails/blob/v4.0.1/Changelog.md
311
+ changelog_uri: https://github.com/rspec/rspec-rails/blob/v5.1.0/Changelog.md
300
312
  documentation_uri: https://rspec.info/documentation/
301
313
  mailing_list_uri: https://groups.google.com/forum/#!forum/rspec
302
314
  source_code_uri: https://github.com/rspec/rspec-rails
303
- post_install_message:
315
+ post_install_message:
304
316
  rdoc_options:
305
317
  - "--charset=UTF-8"
306
318
  require_paths:
@@ -316,8 +328,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
316
328
  - !ruby/object:Gem::Version
317
329
  version: '0'
318
330
  requirements: []
319
- rubygems_version: 3.1.3
320
- signing_key:
331
+ rubygems_version: 3.3.3
332
+ signing_key:
321
333
  specification_version: 4
322
334
  summary: RSpec for Rails
323
335
  test_files: []
metadata.gz.sig CHANGED
Binary file