Skip to content

Commit ab96e8a

Browse files
committed
Tidy up rack status in spec
1 parent 2d5eaea commit ab96e8a

File tree

1 file changed

+8
-19
lines changed

1 file changed

+8
-19
lines changed

spec/generators/rspec/scaffold/scaffold_generator_spec.rb

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
include RSpec::Support::InSubProcess
88
setup_default_destination
99

10+
if Rack::RELEASE < "3.1.0"
11+
let(:unprocessable_status) { ":unprocessable_entity" }
12+
else
13+
let(:unprocessable_status) { ":unprocessable_content" }
14+
end
15+
1016
describe 'standard request specs' do
1117
subject(:filename) { file('spec/requests/posts_spec.rb') }
1218

@@ -33,15 +39,7 @@
3339
.and(contain(/renders a response with 422 status \(i.e. to display the 'edit' template\)/))
3440
)
3541

36-
expect(
37-
filename
38-
).to(
39-
if Gem::Version.new(Rack::RELEASE) < Gem::Version.new("3.1")
40-
contain(/expect\(response\).to have_http_status\(:unprocessable_entity\)/)
41-
else
42-
contain(/expect\(response\).to have_http_status\(:unprocessable_content\)/)
43-
end
44-
)
42+
expect(filename).to contain(/expect\(response\).to have_http_status\(#{unprocessable_status}\)/)
4543
end
4644
end
4745

@@ -109,16 +107,7 @@
109107
expect(filename).to contain(/renders a response with 422 status \(i.e. to display the 'new' template\)/)
110108
.and(contain(/renders a response with 422 status \(i.e. to display the 'edit' template\)/))
111109

112-
expect(
113-
filename
114-
).to(
115-
if Gem::Version.new(Rack::RELEASE) < Gem::Version.new("3.1")
116-
contain(/expect\(response\).to have_http_status\(:unprocessable_entity\)/)
117-
else
118-
contain(/expect\(response\).to have_http_status\(:unprocessable_content\)/)
119-
end
120-
)
121-
110+
expect(filename).to contain(/expect\(response\).to have_http_status\(#{unprocessable_status}\)/)
122111
expect(filename).not_to contain(/"renders a JSON response with the new \w+"/)
123112
expect(filename).not_to contain(/"renders a JSON response with errors for the new \w+"/)
124113
expect(filename).not_to contain(/"renders a JSON response with the \w+"/)

0 commit comments

Comments
 (0)