From 0e3d6894cd626a8bc6f73823ce7c955866b28888 Mon Sep 17 00:00:00 2001 From: Benoit Tigeot Date: Thu, 6 Jun 2019 00:03:37 +0200 Subject: [PATCH] Previously expected content_type has been moved to media_type method See: https://github.com/rails/rails/pull/36034 --- Rakefile | 4 ++ .../controller_specs/controller_spec.feature | 48 ++++++++++++++++++- features/request_specs/request_spec.feature | 21 +++++++- 3 files changed, 71 insertions(+), 2 deletions(-) diff --git a/Rakefile b/Rakefile index bacbbc3b28..d7d4f3c2d0 100644 --- a/Rakefile +++ b/Rakefile @@ -50,6 +50,10 @@ Cucumber::Rake::Task.new(:cucumber) do |t| tags << "~@system_test" end + if version.to_f >= 6.0 + tags << "~@rails_pre_6" + end + if version.to_f < 6.0 tags << "~@rails_post_6" end diff --git a/features/controller_specs/controller_spec.feature b/features/controller_specs/controller_spec.feature index 52c2908dc1..8d61e85346 100644 --- a/features/controller_specs/controller_spec.feature +++ b/features/controller_specs/controller_spec.feature @@ -57,7 +57,7 @@ Feature: controller spec When I run `rspec spec` Then the example should pass - @rails_post_5 + @rails_post_5 @rails_pre_6 Scenario: setting a different content type for example json (request type) Given a file named "spec/controllers/widgets_controller_spec.rb" with: """ruby @@ -79,3 +79,49 @@ Feature: controller spec """ When I run `rspec spec` Then the example should pass + + @rails_post_6 + Scenario: setting a different content type for example json (request type) + Given a file named "spec/controllers/widgets_controller_spec.rb" with: + """ruby + require "rails_helper" + + RSpec.describe WidgetsController, :type => :controller do + describe "responds to" do + it "responds to html by default" do + post :create, :params => { :widget => { :name => "Any Name" } } + expect(response.content_type).to eq "text/html; charset=utf-8" + end + + it "responds to custom formats when provided in the params" do + post :create, :params => { :widget => { :name => "Any Name" }, :format => :json } + expect(response.content_type).to eq "application/json; charset=utf-8" + end + end + end + """ + When I run `rspec spec` + Then the example should pass + + @rails_post_6 + Scenario: setting a different media type for example json (request type) + Given a file named "spec/controllers/widgets_controller_spec.rb" with: + """ruby + require "rails_helper" + + RSpec.describe WidgetsController, :type => :controller do + describe "responds to" do + it "responds to html by default" do + post :create, :params => { :widget => { :name => "Any Name" } } + expect(response.media_type).to eq "text/html" + end + + it "responds to custom formats when provided in the params" do + post :create, :params => { :widget => { :name => "Any Name" }, :format => :json } + expect(response.media_type).to eq "application/json" + end + end + end + """ + When I run `rspec spec` + Then the example should pass diff --git a/features/request_specs/request_spec.feature b/features/request_specs/request_spec.feature index 06d0b76fd0..61abffc7a6 100644 --- a/features/request_specs/request_spec.feature +++ b/features/request_specs/request_spec.feature @@ -110,7 +110,7 @@ Feature: request spec When I run `rspec spec/requests/widget_management_spec.rb` Then the example should pass - @rails_post_5 + @rails_post_5 @rails_pre_6 Scenario: requesting a JSON response Given a file named "spec/requests/widget_management_spec.rb" with: """ruby @@ -134,6 +134,25 @@ Feature: request spec When I run `rspec spec/requests/widget_management_spec.rb` Then the example should pass + @rails_post_6 + Scenario: requesting a JSON response + Given a file named "spec/requests/widget_management_spec.rb" with: + """ruby + require "rails_helper" + + RSpec.describe "Widget management", :type => :request do + it "creates a Widget" do + headers = { "ACCEPT" => "application/json" } + post "/widgets", :params => { :widget => {:name => "My Widget"} }, :headers => headers + + expect(response.content_type).to eq("application/json; charset=utf-8") + expect(response).to have_http_status(:created) + end + end + """ + When I run `rspec spec/requests/widget_management_spec.rb` + Then the example should pass + @rails_pre_5 Scenario: providing JSON data Given a file named "spec/requests/widget_management_spec.rb" with: