Skip to content

Commit 0e3d689

Browse files
committed
Previously expected content_type has been moved to media_type method
See: rails/rails#36034
1 parent 799a1ac commit 0e3d689

File tree

3 files changed

+71
-2
lines changed

3 files changed

+71
-2
lines changed

Rakefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ Cucumber::Rake::Task.new(:cucumber) do |t|
5050
tags << "~@system_test"
5151
end
5252

53+
if version.to_f >= 6.0
54+
tags << "~@rails_pre_6"
55+
end
56+
5357
if version.to_f < 6.0
5458
tags << "~@rails_post_6"
5559
end

features/controller_specs/controller_spec.feature

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Feature: controller spec
5757
When I run `rspec spec`
5858
Then the example should pass
5959

60-
@rails_post_5
60+
@rails_post_5 @rails_pre_6
6161
Scenario: setting a different content type for example json (request type)
6262
Given a file named "spec/controllers/widgets_controller_spec.rb" with:
6363
"""ruby
@@ -79,3 +79,49 @@ Feature: controller spec
7979
"""
8080
When I run `rspec spec`
8181
Then the example should pass
82+
83+
@rails_post_6
84+
Scenario: setting a different content type for example json (request type)
85+
Given a file named "spec/controllers/widgets_controller_spec.rb" with:
86+
"""ruby
87+
require "rails_helper"
88+
89+
RSpec.describe WidgetsController, :type => :controller do
90+
describe "responds to" do
91+
it "responds to html by default" do
92+
post :create, :params => { :widget => { :name => "Any Name" } }
93+
expect(response.content_type).to eq "text/html; charset=utf-8"
94+
end
95+
96+
it "responds to custom formats when provided in the params" do
97+
post :create, :params => { :widget => { :name => "Any Name" }, :format => :json }
98+
expect(response.content_type).to eq "application/json; charset=utf-8"
99+
end
100+
end
101+
end
102+
"""
103+
When I run `rspec spec`
104+
Then the example should pass
105+
106+
@rails_post_6
107+
Scenario: setting a different media type for example json (request type)
108+
Given a file named "spec/controllers/widgets_controller_spec.rb" with:
109+
"""ruby
110+
require "rails_helper"
111+
112+
RSpec.describe WidgetsController, :type => :controller do
113+
describe "responds to" do
114+
it "responds to html by default" do
115+
post :create, :params => { :widget => { :name => "Any Name" } }
116+
expect(response.media_type).to eq "text/html"
117+
end
118+
119+
it "responds to custom formats when provided in the params" do
120+
post :create, :params => { :widget => { :name => "Any Name" }, :format => :json }
121+
expect(response.media_type).to eq "application/json"
122+
end
123+
end
124+
end
125+
"""
126+
When I run `rspec spec`
127+
Then the example should pass

features/request_specs/request_spec.feature

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ Feature: request spec
110110
When I run `rspec spec/requests/widget_management_spec.rb`
111111
Then the example should pass
112112

113-
@rails_post_5
113+
@rails_post_5 @rails_pre_6
114114
Scenario: requesting a JSON response
115115
Given a file named "spec/requests/widget_management_spec.rb" with:
116116
"""ruby
@@ -134,6 +134,25 @@ Feature: request spec
134134
When I run `rspec spec/requests/widget_management_spec.rb`
135135
Then the example should pass
136136

137+
@rails_post_6
138+
Scenario: requesting a JSON response
139+
Given a file named "spec/requests/widget_management_spec.rb" with:
140+
"""ruby
141+
require "rails_helper"
142+
143+
RSpec.describe "Widget management", :type => :request do
144+
it "creates a Widget" do
145+
headers = { "ACCEPT" => "application/json" }
146+
post "/widgets", :params => { :widget => {:name => "My Widget"} }, :headers => headers
147+
148+
expect(response.content_type).to eq("application/json; charset=utf-8")
149+
expect(response).to have_http_status(:created)
150+
end
151+
end
152+
"""
153+
When I run `rspec spec/requests/widget_management_spec.rb`
154+
Then the example should pass
155+
137156
@rails_pre_5
138157
Scenario: providing JSON data
139158
Given a file named "spec/requests/widget_management_spec.rb" with:

0 commit comments

Comments
 (0)