rspec-rails 3.7.2 → 3.8.0
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/Changelog.md +25 -2
- data/README.md +11 -9
- data/lib/generators/rspec/install/templates/spec/rails_helper.rb +15 -7
- data/lib/generators/rspec/scaffold/scaffold_generator.rb +14 -4
- data/lib/generators/rspec/scaffold/templates/api_controller_spec.rb +2 -2
- data/lib/generators/rspec/scaffold/templates/controller_spec.rb +7 -7
- data/lib/generators/rspec/scaffold/templates/routing_spec.rb +2 -3
- data/lib/rspec-rails.rb +5 -1
- data/lib/rspec/rails/example/system_example_group.rb +7 -4
- data/lib/rspec/rails/example/view_example_group.rb +9 -1
- data/lib/rspec/rails/fixture_file_upload_support.rb +3 -2
- data/lib/rspec/rails/matchers/active_job.rb +20 -2
- data/lib/rspec/rails/matchers/have_http_status.rb +32 -6
- data/lib/rspec/rails/version.rb +1 -1
- data/lib/rspec/rails/view_rendering.rb +1 -1
- metadata +11 -11
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea2d87e6ff8e297370262b9b24149098c96ce7e1
|
4
|
+
data.tar.gz: 628aaf29946b0d609e2f7312a0135a11e20a54bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dfb6ef6e01a98df778f5d44e165a1222e3ba7edc9b00ca095f11efe3d17336e6f9fa2ee73b3587527bb51453efafb480372acbfdac4b031f186fb0106aa39218
|
7
|
+
data.tar.gz: 43a37b04ca888383a5a648597b0daade6b456b4e10a2a69838eaf9fedfb535934853020945a1df54d785e1e478fbd1eb7423a2168f3bb76b37c49c9fa02c351a
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/Changelog.md
CHANGED
@@ -1,5 +1,28 @@
|
|
1
|
-
###
|
2
|
-
[Full Changelog](http://github.com/rspec/rspec-rails/compare/v3.7.2...
|
1
|
+
### 3.8.0 / 2018-08-04
|
2
|
+
[Full Changelog](http://github.com/rspec/rspec-rails/compare/v3.7.2...v3.8.0)
|
3
|
+
|
4
|
+
Enhancements:
|
5
|
+
|
6
|
+
* Improved message when migrations are pending in the default `rails_helper.rb`
|
7
|
+
(Koichi ITO, #1924)
|
8
|
+
* `have_http_status` matcher now supports Rails 5.2 style response symbols
|
9
|
+
(Douglas Lovell, #1951)
|
10
|
+
* Change generated Rails helper to match Rails standards for Rails.root
|
11
|
+
(Alessandro Rodi, #1960)
|
12
|
+
* At support for asserting enqueued jobs have no wait period attached.
|
13
|
+
(Brad Charna, #1977)
|
14
|
+
* Cache instances of `ActionView::Template` used in `stub_template` resulting
|
15
|
+
in increased performance due to less allocations and setup. (Simon Coffey, #1979)
|
16
|
+
* Rails scaffold generator now respects longer namespaces (e.g. api/v1/\<thing\>).
|
17
|
+
(Laura Paakkinen, #1958)
|
18
|
+
|
19
|
+
Bug Fixes:
|
20
|
+
|
21
|
+
* Escape quotation characters when producing method names for system spec
|
22
|
+
screenshots. (Shane Cavanaugh, #1955)
|
23
|
+
* Use relative path for resolving fixtures when `fixture_path` is not set.
|
24
|
+
(Laurent Cobos, #1943)
|
25
|
+
* Allow custom template resolvers in view specs. (@ahorek, #1941)
|
3
26
|
|
4
27
|
### 3.7.2 / 2017-11-20
|
5
28
|
[Full Changelog](http://github.com/rspec/rspec-rails/compare/v3.7.1...v3.7.2)
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# rspec-rails [](http://travis-ci.org/rspec/rspec-rails) [](https://codeclimate.com/github/rspec/rspec-rails)
|
2
|
-
**rspec-rails** is a testing framework for Rails 3.x, 4.x and 5.
|
2
|
+
**rspec-rails** is a testing framework for Rails 3.x, 4.x and 5.x.
|
3
3
|
|
4
4
|
Use **[rspec-rails 1.x](http://github.com/dchelimsky/rspec-rails)** for Rails
|
5
5
|
2.x.
|
@@ -11,7 +11,7 @@ Add `rspec-rails` to **both** the `:development` and `:test` groups in the
|
|
11
11
|
|
12
12
|
```ruby
|
13
13
|
group :development, :test do
|
14
|
-
gem 'rspec-rails', '~> 3.
|
14
|
+
gem 'rspec-rails', '~> 3.7'
|
15
15
|
end
|
16
16
|
```
|
17
17
|
|
@@ -70,7 +70,7 @@ bundle exec rspec spec/controllers/accounts_controller_spec.rb:8
|
|
70
70
|
Specs can also be run via `rake spec`, though this command may be slower to
|
71
71
|
start than the `rspec` command.
|
72
72
|
|
73
|
-
In Rails 4
|
73
|
+
In Rails 4/5+, you may want to create a binstub for the `rspec` command so it can
|
74
74
|
be run via `bin/rspec`:
|
75
75
|
|
76
76
|
```
|
@@ -147,12 +147,14 @@ For example:
|
|
147
147
|
```ruby
|
148
148
|
require "rails_helper"
|
149
149
|
|
150
|
-
RSpec.describe
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
150
|
+
RSpec.describe Post, :type => :model do
|
151
|
+
context "with 2 or more comments" do
|
152
|
+
it "orders them in reverse chronologically" do
|
153
|
+
post = Post.create!
|
154
|
+
comment1 = post.comments.create!(:body => "first comment")
|
155
|
+
comment2 = post.comments.create!(:body => "second comment")
|
156
|
+
expect(post.reload.comments).to eq([comment2, comment1])
|
157
|
+
end
|
156
158
|
end
|
157
159
|
end
|
158
160
|
```
|
@@ -20,18 +20,26 @@ require 'rspec/rails'
|
|
20
20
|
# directory. Alternatively, in the individual `*_spec.rb` files, manually
|
21
21
|
# require only the support files necessary.
|
22
22
|
#
|
23
|
-
# Dir[Rails.root.join('spec
|
23
|
+
# Dir[Rails.root.join('spec', 'support', '**', '*.rb')].each { |f| require f }
|
24
24
|
|
25
25
|
<% if RSpec::Rails::FeatureCheck.can_maintain_test_schema? -%>
|
26
26
|
# Checks for pending migrations and applies them before tests are run.
|
27
|
-
# If you are not using ActiveRecord, you can remove
|
28
|
-
|
29
|
-
|
27
|
+
# If you are not using ActiveRecord, you can remove these lines.
|
28
|
+
begin
|
29
|
+
ActiveRecord::Migration.maintain_test_schema!
|
30
|
+
rescue ActiveRecord::PendingMigrationError => e
|
31
|
+
puts e.to_s.strip
|
32
|
+
exit 1
|
33
|
+
end
|
30
34
|
<% elsif RSpec::Rails::FeatureCheck.can_check_pending_migrations? -%>
|
31
35
|
# Checks for pending migrations before tests are run.
|
32
|
-
# If you are not using ActiveRecord, you can remove
|
33
|
-
|
34
|
-
|
36
|
+
# If you are not using ActiveRecord, you can remove these lines.
|
37
|
+
begin
|
38
|
+
ActiveRecord::Migration.check_pending!
|
39
|
+
rescue ActiveRecord::PendingMigrationError => e
|
40
|
+
puts e.to_s.strip
|
41
|
+
exit 1
|
42
|
+
end
|
35
43
|
<% end -%>
|
36
44
|
RSpec.configure do |config|
|
37
45
|
<% if RSpec::Rails::FeatureCheck.has_active_record? -%>
|
@@ -73,21 +73,31 @@ module Rspec
|
|
73
73
|
|
74
74
|
# support for namespaced-resources
|
75
75
|
def ns_file_name
|
76
|
-
|
76
|
+
return file_name if ns_parts.empty?
|
77
|
+
"#{ns_prefix.map(&:underscore).join('/')}_#{ns_suffix.singularize.underscore}"
|
77
78
|
end
|
78
79
|
|
79
80
|
# support for namespaced-resources
|
80
81
|
def ns_table_name
|
81
|
-
|
82
|
+
return table_name if ns_parts.empty?
|
83
|
+
"#{ns_prefix.map(&:underscore).join('/')}/#{ns_suffix.tableize}"
|
82
84
|
end
|
83
85
|
|
84
86
|
def ns_parts
|
85
87
|
@ns_parts ||= begin
|
86
|
-
|
87
|
-
|
88
|
+
parts = generator_args[0].split(/\/|::/)
|
89
|
+
parts.size > 1 ? parts : []
|
88
90
|
end
|
89
91
|
end
|
90
92
|
|
93
|
+
def ns_prefix
|
94
|
+
@ns_prefix ||= ns_parts[0..-2]
|
95
|
+
end
|
96
|
+
|
97
|
+
def ns_suffix
|
98
|
+
@ns_suffix ||= ns_parts[-1]
|
99
|
+
end
|
100
|
+
|
91
101
|
def value_for(attribute)
|
92
102
|
raw_value_for(attribute).inspect
|
93
103
|
end
|
@@ -51,7 +51,7 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
51
51
|
<% else -%>
|
52
52
|
get :index, params: {}, session: valid_session
|
53
53
|
<% end -%>
|
54
|
-
expect(response).to
|
54
|
+
expect(response).to be_successful
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
@@ -64,7 +64,7 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
64
64
|
<% else -%>
|
65
65
|
get :show, params: {id: <%= file_name %>.to_param}, session: valid_session
|
66
66
|
<% end -%>
|
67
|
-
expect(response).to
|
67
|
+
expect(response).to be_successful
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
@@ -45,13 +45,13 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
45
45
|
<% unless options[:singleton] -%>
|
46
46
|
describe "GET #index" do
|
47
47
|
it "returns a success response" do
|
48
|
-
<%=
|
48
|
+
<%= class_name %>.create! valid_attributes
|
49
49
|
<% if Rails::VERSION::STRING < '5.0' -%>
|
50
50
|
get :index, {}, valid_session
|
51
51
|
<% else -%>
|
52
52
|
get :index, params: {}, session: valid_session
|
53
53
|
<% end -%>
|
54
|
-
expect(response).to
|
54
|
+
expect(response).to be_successful
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
@@ -64,7 +64,7 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
64
64
|
<% else -%>
|
65
65
|
get :show, params: {id: <%= file_name %>.to_param}, session: valid_session
|
66
66
|
<% end -%>
|
67
|
-
expect(response).to
|
67
|
+
expect(response).to be_successful
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
@@ -75,7 +75,7 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
75
75
|
<% else -%>
|
76
76
|
get :new, params: {}, session: valid_session
|
77
77
|
<% end -%>
|
78
|
-
expect(response).to
|
78
|
+
expect(response).to be_successful
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
@@ -87,7 +87,7 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
87
87
|
<% else -%>
|
88
88
|
get :edit, params: {id: <%= file_name %>.to_param}, session: valid_session
|
89
89
|
<% end -%>
|
90
|
-
expect(response).to
|
90
|
+
expect(response).to be_successful
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
@@ -120,7 +120,7 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
120
120
|
<% else -%>
|
121
121
|
post :create, params: {<%= ns_file_name %>: invalid_attributes}, session: valid_session
|
122
122
|
<% end -%>
|
123
|
-
expect(response).to
|
123
|
+
expect(response).to be_successful
|
124
124
|
end
|
125
125
|
end
|
126
126
|
end
|
@@ -161,7 +161,7 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
161
161
|
<% else -%>
|
162
162
|
put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: invalid_attributes}, session: valid_session
|
163
163
|
<% end -%>
|
164
|
-
expect(response).to
|
164
|
+
expect(response).to be_successful
|
165
165
|
end
|
166
166
|
end
|
167
167
|
end
|
@@ -3,7 +3,6 @@ require "rails_helper"
|
|
3
3
|
<% module_namespacing do -%>
|
4
4
|
RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:routing) %> do
|
5
5
|
describe "routing" do
|
6
|
-
|
7
6
|
<% unless options[:singleton] -%>
|
8
7
|
it "routes to #index" do
|
9
8
|
expect(:get => "/<%= ns_table_name %>").to route_to("<%= ns_table_name %>#index")
|
@@ -14,8 +13,8 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:routing
|
|
14
13
|
it "routes to #new" do
|
15
14
|
expect(:get => "/<%= ns_table_name %>/new").to route_to("<%= ns_table_name %>#new")
|
16
15
|
end
|
17
|
-
<% end -%>
|
18
16
|
|
17
|
+
<% end -%>
|
19
18
|
it "routes to #show" do
|
20
19
|
expect(:get => "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#show", :id => "1")
|
21
20
|
end
|
@@ -24,6 +23,7 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:routing
|
|
24
23
|
it "routes to #edit" do
|
25
24
|
expect(:get => "/<%= ns_table_name %>/1/edit").to route_to("<%= ns_table_name %>#edit", :id => "1")
|
26
25
|
end
|
26
|
+
|
27
27
|
<% end -%>
|
28
28
|
|
29
29
|
it "routes to #create" do
|
@@ -43,7 +43,6 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:routing
|
|
43
43
|
it "routes to #destroy" do
|
44
44
|
expect(:delete => "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#destroy", :id => "1")
|
45
45
|
end
|
46
|
-
|
47
46
|
end
|
48
47
|
end
|
49
48
|
<% end -%>
|
data/lib/rspec-rails.rb
CHANGED
@@ -9,7 +9,11 @@ module RSpec
|
|
9
9
|
# As of Rails 5.1.0 you can register directories to work with `rake notes`
|
10
10
|
if ::Rails::VERSION::STRING >= '5.1'
|
11
11
|
require 'rails/source_annotation_extractor'
|
12
|
-
|
12
|
+
if ::Rails::VERSION::STRING >= '6.0'
|
13
|
+
::Rails::SourceAnnotationExtractor::Annotation.register_directories("spec")
|
14
|
+
else
|
15
|
+
SourceAnnotationExtractor::Annotation.register_directories("spec")
|
16
|
+
end
|
13
17
|
end
|
14
18
|
# Rails-3.0.1 requires config.app_generators instead of 3.0.0's config.generators
|
15
19
|
generators = config.respond_to?(:app_generators) ? config.app_generators : config.generators
|
@@ -11,6 +11,9 @@ module RSpec
|
|
11
11
|
include ActionDispatch::Assertions
|
12
12
|
include ActionController::TemplateAssertions
|
13
13
|
|
14
|
+
# Special characters to translate into underscores for #method_name
|
15
|
+
CHARS_TO_TRANSLATE = ['/', '.', ':', ',', "'", '"', " "].freeze
|
16
|
+
|
14
17
|
# @private
|
15
18
|
module BlowAwayAfterTeardownHook
|
16
19
|
# @private
|
@@ -33,9 +36,8 @@ module RSpec
|
|
33
36
|
def method_name
|
34
37
|
@method_name ||= [
|
35
38
|
self.class.name.underscore,
|
36
|
-
RSpec.current_example.description.underscore
|
37
|
-
|
38
|
-
].join("_").gsub(/[\/\.:, ]/, "_")
|
39
|
+
RSpec.current_example.description.underscore
|
40
|
+
].join("_").tr(CHARS_TO_TRANSLATE.join, "_")[0...251] + "_#{rand(1000)}"
|
39
41
|
end
|
40
42
|
|
41
43
|
# Delegates to `Rails.application`.
|
@@ -48,9 +50,10 @@ module RSpec
|
|
48
50
|
require 'capybara'
|
49
51
|
require 'action_dispatch/system_test_case'
|
50
52
|
# rubocop:disable Lint/HandleExceptions
|
51
|
-
rescue LoadError
|
53
|
+
rescue LoadError => e
|
52
54
|
# rubocop:enable Lint/HandleExceptions
|
53
55
|
abort """
|
56
|
+
LoadError: #{e.message}
|
54
57
|
System test integration requires Rails >= 5.1 and has a hard
|
55
58
|
dependency on a webserver and `capybara`, please add capybara to
|
56
59
|
your Gemfile and configure a webserver (e.g. `Capybara.server =
|
@@ -13,6 +13,14 @@ module RSpec
|
|
13
13
|
include RSpec::Rails::ViewAssigns
|
14
14
|
include RSpec::Rails::Matchers::RenderTemplate
|
15
15
|
|
16
|
+
# @private
|
17
|
+
module StubResolverCache
|
18
|
+
def self.resolver_for(hash)
|
19
|
+
@resolvers ||= {}
|
20
|
+
@resolvers[hash] ||= ActionView::FixtureResolver.new(hash)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
16
24
|
# @private
|
17
25
|
module ClassMethods
|
18
26
|
def _default_helper
|
@@ -84,7 +92,7 @@ module RSpec
|
|
84
92
|
#
|
85
93
|
# stub_template("widgets/_widget.html.erb" => "This content.")
|
86
94
|
def stub_template(hash)
|
87
|
-
view.view_paths.unshift(
|
95
|
+
view.view_paths.unshift(StubResolverCache.resolver_for(hash))
|
88
96
|
end
|
89
97
|
|
90
98
|
# Provides access to the params hash that will be available within the
|
@@ -7,8 +7,9 @@ module RSpec
|
|
7
7
|
private
|
8
8
|
|
9
9
|
def rails_fixture_file_wrapper
|
10
|
+
RailsFixtureFileWrapper.fixture_path = nil
|
10
11
|
resolved_fixture_path = (fixture_path || RSpec.configuration.fixture_path || '')
|
11
|
-
RailsFixtureFileWrapper.fixture_path = File.join(resolved_fixture_path, '')
|
12
|
+
RailsFixtureFileWrapper.fixture_path = File.join(resolved_fixture_path, '') unless resolved_fixture_path.strip.empty?
|
12
13
|
RailsFixtureFileWrapper.instance
|
13
14
|
end
|
14
15
|
|
@@ -18,7 +19,7 @@ module RSpec
|
|
18
19
|
class << self
|
19
20
|
attr_reader :fixture_path
|
20
21
|
|
21
|
-
# Get
|
22
|
+
# Get instance of wrapper
|
22
23
|
def instance
|
23
24
|
@instance ||= new
|
24
25
|
end
|
@@ -118,7 +118,7 @@ module RSpec
|
|
118
118
|
"#{message_expectation_modifier} #{@expected_number} jobs,".tap do |msg|
|
119
119
|
msg << " with #{@args}," if @args.any?
|
120
120
|
msg << " on queue #{@queue}," if @queue
|
121
|
-
msg << " at #{@at}," if @at
|
121
|
+
msg << " at #{@at.inspect}," if @at
|
122
122
|
msg << " but enqueued #{@matching_jobs_count}"
|
123
123
|
end
|
124
124
|
end
|
@@ -149,12 +149,16 @@ module RSpec
|
|
149
149
|
|
150
150
|
def serialized_attributes
|
151
151
|
{}.tap do |attributes|
|
152
|
-
attributes[:at] =
|
152
|
+
attributes[:at] = serialized_at if @at
|
153
153
|
attributes[:queue] = @queue if @queue
|
154
154
|
attributes[:job] = @job if @job
|
155
155
|
end
|
156
156
|
end
|
157
157
|
|
158
|
+
def serialized_at
|
159
|
+
@at == :no_wait ? nil : @at.to_f
|
160
|
+
end
|
161
|
+
|
158
162
|
def set_expected_number(relativity, count)
|
159
163
|
@expectation_type = relativity
|
160
164
|
@expected_number = case count
|
@@ -232,6 +236,17 @@ module RSpec
|
|
232
236
|
# expect {
|
233
237
|
# HelloJob.set(wait_until: Date.tomorrow.noon, queue: "low").perform_later(42)
|
234
238
|
# }.to have_enqueued_job.with(42).on_queue("low").at(Date.tomorrow.noon)
|
239
|
+
#
|
240
|
+
# expect {
|
241
|
+
# HelloJob.set(queue: "low").perform_later(42)
|
242
|
+
# }.to have_enqueued_job.with(42).on_queue("low").at(:no_wait)
|
243
|
+
#
|
244
|
+
# expect {
|
245
|
+
# HelloJob.perform_later('rspec_rails', 'rails', 42)
|
246
|
+
# }.to have_enqueued_job.with { |from, to, times|
|
247
|
+
# # Perform more complex argument matching using dynamic arguments
|
248
|
+
# expect(from).to include "_#{to}"
|
249
|
+
# }
|
235
250
|
def have_enqueued_job(job = nil)
|
236
251
|
check_active_job_adapter
|
237
252
|
ActiveJob::HaveEnqueuedJob.new(job)
|
@@ -264,6 +279,9 @@ module RSpec
|
|
264
279
|
#
|
265
280
|
# HelloJob.set(wait_until: Date.tomorrow.noon, queue: "low").perform_later(42)
|
266
281
|
# expect(HelloJob).to have_been_enqueued.with(42).on_queue("low").at(Date.tomorrow.noon)
|
282
|
+
#
|
283
|
+
# HelloJob.set(queue: "low").perform_later(42)
|
284
|
+
# expect(HelloJob).to have_been_enqueued.with(42).on_queue("low").at(:no_wait)
|
267
285
|
def have_been_enqueued
|
268
286
|
check_active_job_adapter
|
269
287
|
ActiveJob::HaveBeenEnqueued.new
|
@@ -243,7 +243,11 @@ module RSpec
|
|
243
243
|
# code "group"
|
244
244
|
# @see https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/testing/test_response.rb `ActionDispatch::TestResponse`
|
245
245
|
def self.valid_statuses
|
246
|
-
[
|
246
|
+
[
|
247
|
+
:error, :success, :missing,
|
248
|
+
:server_error, :successful, :not_found,
|
249
|
+
:redirect
|
250
|
+
]
|
247
251
|
end
|
248
252
|
|
249
253
|
def initialize(type)
|
@@ -256,11 +260,11 @@ module RSpec
|
|
256
260
|
end
|
257
261
|
|
258
262
|
# @return [Boolean] `true` if Rack's associated numeric HTTP code matched
|
259
|
-
# the `response` code
|
263
|
+
# the `response` code or the named response status
|
260
264
|
def matches?(response)
|
261
265
|
test_response = as_test_response(response)
|
262
266
|
@actual = test_response.response_code
|
263
|
-
test_response
|
267
|
+
check_expected_status(test_response, expected)
|
264
268
|
rescue TypeError => _ignored
|
265
269
|
@invalid_response = response
|
266
270
|
false
|
@@ -283,6 +287,28 @@ module RSpec
|
|
283
287
|
"expected the response not to have #{type_message} but it was #{actual}"
|
284
288
|
end
|
285
289
|
|
290
|
+
protected
|
291
|
+
|
292
|
+
if 5 < ::Rails::VERSION::MAJOR ||
|
293
|
+
(::Rails::VERSION::MAJOR == 5 && 2 <= ::Rails::VERSION::MINOR)
|
294
|
+
RESPONSE_METHODS = {
|
295
|
+
:success => 'successful',
|
296
|
+
:error => 'server_error',
|
297
|
+
:missing => 'not_found'
|
298
|
+
}.freeze
|
299
|
+
else
|
300
|
+
RESPONSE_METHODS = {
|
301
|
+
:successful => 'success',
|
302
|
+
:server_error => 'error',
|
303
|
+
:not_found => 'missing'
|
304
|
+
}.freeze
|
305
|
+
end
|
306
|
+
|
307
|
+
def check_expected_status(test_response, expected)
|
308
|
+
test_response.send(
|
309
|
+
"#{RESPONSE_METHODS.fetch(expected, expected)}?")
|
310
|
+
end
|
311
|
+
|
286
312
|
private
|
287
313
|
|
288
314
|
# @return [String] formating the expected status and associated code(s)
|
@@ -316,11 +342,11 @@ module RSpec
|
|
316
342
|
# @see https://github.com/rails/rails/blob/ca200378/actionpack/lib/action_dispatch/http/response.rb#L74
|
317
343
|
# @see https://github.com/rack/rack/blob/ce4a3959/lib/rack/response.rb#L119-L122
|
318
344
|
@type_codes ||= case expected
|
319
|
-
when :error
|
345
|
+
when :error, :server_error
|
320
346
|
"5xx"
|
321
|
-
when :success
|
347
|
+
when :success, :successful
|
322
348
|
"2xx"
|
323
|
-
when :missing
|
349
|
+
when :missing, :not_found
|
324
350
|
"404"
|
325
351
|
when :redirect
|
326
352
|
"3xx"
|
data/lib/rspec/rails/version.rb
CHANGED
@@ -137,7 +137,7 @@ module RSpec
|
|
137
137
|
before do
|
138
138
|
unless render_views?
|
139
139
|
@_original_path_set = controller.class.view_paths
|
140
|
-
path_set = @_original_path_set.map { |resolver| RESOLVER_CACHE[resolver
|
140
|
+
path_set = @_original_path_set.map { |resolver| RESOLVER_CACHE[resolver] }
|
141
141
|
|
142
142
|
controller.class.view_paths = path_set
|
143
143
|
controller.extend(EmptyTemplates)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Chelimsky
|
@@ -44,7 +44,7 @@ cert_chain:
|
|
44
44
|
ZsVDj6a7lH3cNqtWXZxrb2wO38qV5AkYj8SQK7Hj3/Yui9myUX3crr+PdetazSqQ
|
45
45
|
F3MdtaDehhjC
|
46
46
|
-----END CERTIFICATE-----
|
47
|
-
date:
|
47
|
+
date: 2018-08-04 00:00:00.000000000 Z
|
48
48
|
dependencies:
|
49
49
|
- !ruby/object:Gem::Dependency
|
50
50
|
name: activesupport
|
@@ -94,56 +94,56 @@ dependencies:
|
|
94
94
|
requirements:
|
95
95
|
- - "~>"
|
96
96
|
- !ruby/object:Gem::Version
|
97
|
-
version: 3.
|
97
|
+
version: 3.8.0
|
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.
|
104
|
+
version: 3.8.0
|
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.
|
111
|
+
version: 3.8.0
|
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.
|
118
|
+
version: 3.8.0
|
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.
|
125
|
+
version: 3.8.0
|
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.
|
132
|
+
version: 3.8.0
|
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.
|
139
|
+
version: 3.8.0
|
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.
|
146
|
+
version: 3.8.0
|
147
147
|
- !ruby/object:Gem::Dependency
|
148
148
|
name: cucumber
|
149
149
|
requirement: !ruby/object:Gem::Requirement
|
@@ -294,7 +294,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
294
294
|
version: '0'
|
295
295
|
requirements: []
|
296
296
|
rubyforge_project:
|
297
|
-
rubygems_version: 2.6.
|
297
|
+
rubygems_version: 2.6.13
|
298
298
|
signing_key:
|
299
299
|
specification_version: 4
|
300
300
|
summary: RSpec for Rails
|
metadata.gz.sig
CHANGED
Binary file
|