Navigation Menu

Skip to content

Commit

Permalink
Previously expected content_type has been moved to media_type method
Browse files Browse the repository at this point in the history
  • Loading branch information
benoittgt committed Jun 7, 2019
1 parent 799a1ac commit 0e3d689
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Rakefile
Expand Up @@ -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
Expand Down
48 changes: 47 additions & 1 deletion features/controller_specs/controller_spec.feature
Expand Up @@ -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
Expand All @@ -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
21 changes: 20 additions & 1 deletion features/request_specs/request_spec.feature
Expand Up @@ -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
Expand All @@ -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:
Expand Down

0 comments on commit 0e3d689

Please sign in to comment.