From f493536ea499e0c8d2517341a6cd9ac17959f474 Mon Sep 17 00:00:00 2001 From: Joel AZEMAR Date: Thu, 8 Mar 2018 16:23:52 +0100 Subject: [PATCH 1/7] Fix API blueprint documentation Wrong Format - Fix FORMAT metadata value (https://github.com/apiaryio/api-blueprint/blob/format-1A/API%20Blueprint%20Specification.md#41-metadata-section) --- features/api_blueprint_documentation.feature | 2 +- templates/rspec_api_documentation/api_blueprint_index.mustache | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/features/api_blueprint_documentation.feature b/features/api_blueprint_documentation.feature index 2ac78462..4ae09405 100644 --- a/features/api_blueprint_documentation.feature +++ b/features/api_blueprint_documentation.feature @@ -248,7 +248,7 @@ Feature: Generate API Blueprint documentation from test examples Scenario: Index file should look like we expect Then the file "doc/api/index.apib" should contain exactly: """ - FORMAT: A1 + FORMAT: 1A # Group Instructions diff --git a/templates/rspec_api_documentation/api_blueprint_index.mustache b/templates/rspec_api_documentation/api_blueprint_index.mustache index 2955a22d..20c359aa 100644 --- a/templates/rspec_api_documentation/api_blueprint_index.mustache +++ b/templates/rspec_api_documentation/api_blueprint_index.mustache @@ -1,4 +1,4 @@ -FORMAT: A1 +FORMAT: 1A {{# sections }} # Group {{ resource_name }} From a4acfcc54cef5942c4804070f875af608c44ac07 Mon Sep 17 00:00:00 2001 From: Joel AZEMAR Date: Thu, 8 Mar 2018 17:11:45 +0100 Subject: [PATCH 2/7] Fix Indentation - Headers and Body sections were indented with 8 spaces instead of 12 (https://github.com/apiaryio/api-blueprint/blob/format-1A/API%20Blueprint%20Specification.md#ActionResponseSection) - The API name was not present (https://github.com/apiaryio/api-blueprint/blob/format-1A/API%20Blueprint%20Specification.md#42-api-name--overview-section) --- features/api_blueprint_documentation.feature | 160 +++++++++--------- .../views/api_blueprint_example.rb | 2 +- spec/views/api_blueprint_example_spec.rb | 8 +- .../api_blueprint_index.mustache | 8 +- 4 files changed, 89 insertions(+), 89 deletions(-) diff --git a/features/api_blueprint_documentation.feature b/features/api_blueprint_documentation.feature index 4ae09405..4a9fe390 100644 --- a/features/api_blueprint_documentation.feature +++ b/features/api_blueprint_documentation.feature @@ -262,18 +262,18 @@ Feature: Generate API Blueprint documentation from test examples + Headers - Host: example.org + Host: example.org + Response 200 (text/html;charset=utf-8) + Headers - Content-Type: text/html;charset=utf-8 - Content-Length: 57 + Content-Type: text/html;charset=utf-8 + Content-Length: 57 + Body - {"data":{"id":"1","type":"instructions","attributes":{}}} + {"data":{"id":"1","type":"instructions","attributes":{}}} # Group Orders @@ -287,38 +287,38 @@ Feature: Generate API Blueprint documentation from test examples + Headers - Content-Type: application/json - Host: example.org + Content-Type: application/json + Host: example.org + Body - { - "data": { - "type": "order", - "attributes": { - "name": "Order 1", - "amount": 100.0, - "description": "A description" + { + "data": { + "type": "order", + "attributes": { + "name": "Order 1", + "amount": 100.0, + "description": "A description" + } + } } - } - } + Response 201 (application/json) + Headers - Content-Type: application/json - Content-Length: 73 + Content-Type: application/json + Content-Length: 73 + Body - { - "order": { - "name": "Order 1", - "amount": 100.0, - "description": "A great order" - } - } + { + "order": { + "name": "Order 1", + "amount": 100.0, + "description": "A great order" + } + } ### Return all orders [GET] @@ -326,32 +326,32 @@ Feature: Generate API Blueprint documentation from test examples + Headers - Host: example.org + Host: example.org + Response 200 (application/vnd.api+json) + Headers - Content-Type: application/vnd.api+json - Content-Length: 137 + Content-Type: application/vnd.api+json + Content-Length: 137 + Body - { - "page": 1, - "orders": [ - { - "name": "Order 1", - "amount": 9.99, - "description": null - }, { - "name": "Order 2", - "amount": 100.0, - "description": "A great order" + "page": 1, + "orders": [ + { + "name": "Order 1", + "amount": 9.99, + "description": null + }, + { + "name": "Order 2", + "amount": 100.0, + "description": "A great order" + } + ] } - ] - } ## Single Order [/orders/:id{?optional=:optional}] @@ -370,15 +370,15 @@ Feature: Generate API Blueprint documentation from test examples + Headers - Host: example.org - Content-Type: application/x-www-form-urlencoded + Host: example.org + Content-Type: application/x-www-form-urlencoded + Response 200 (text/html;charset=utf-8) + Headers - Content-Type: text/html;charset=utf-8 - Content-Length: 0 + Content-Type: text/html;charset=utf-8 + Content-Length: 0 ### Returns a single order [GET] @@ -386,24 +386,24 @@ Feature: Generate API Blueprint documentation from test examples + Headers - Host: example.org + Host: example.org + Response 200 (application/json) + Headers - Content-Type: application/json - Content-Length: 73 + Content-Type: application/json + Content-Length: 73 + Body - { - "order": { - "name": "Order 1", - "amount": 100.0, - "description": "A great order" - } - } + { + "order": { + "name": "Order 1", + "amount": 100.0, + "description": "A great order" + } + } ### Updates a single order [PUT] @@ -411,55 +411,55 @@ Feature: Generate API Blueprint documentation from test examples + Headers - Content-Type: application/json; charset=utf-16 - Host: example.org + Content-Type: application/json; charset=utf-16 + Host: example.org + Response 400 (application/json) + Headers - Content-Type: application/json - Content-Length: 0 + Content-Type: application/json + Content-Length: 0 + Request Update an order (application/json; charset=utf-16) + Headers - Content-Type: application/json; charset=utf-16 - Host: example.org + Content-Type: application/json; charset=utf-16 + Host: example.org + Body - { - "data": { - "id": "1", - "type": "order", - "attributes": { - "name": "Order 1" + { + "data": { + "id": "1", + "type": "order", + "attributes": { + "name": "Order 1" + } + } } - } - } + Response 200 (application/json) + Headers - Content-Type: application/json - Content-Length: 111 + Content-Type: application/json + Content-Length: 111 + Body - { - "data": { - "id": "1", - "type": "order", - "attributes": { - "name": "Order 1", - "amount": 100.0, - "description": "A description" + { + "data": { + "id": "1", + "type": "order", + "attributes": { + "name": "Order 1", + "amount": 100.0, + "description": "A description" + } + } } - } - } """ Scenario: Example 'Deleting an order' file should not be created diff --git a/lib/rspec_api_documentation/views/api_blueprint_example.rb b/lib/rspec_api_documentation/views/api_blueprint_example.rb index 45f815a9..5d60d219 100644 --- a/lib/rspec_api_documentation/views/api_blueprint_example.rb +++ b/lib/rspec_api_documentation/views/api_blueprint_example.rb @@ -1,7 +1,7 @@ module RspecApiDocumentation module Views class ApiBlueprintExample < MarkupExample - TOTAL_SPACES_INDENTATION = 8.freeze + TOTAL_SPACES_INDENTATION = 12.freeze def initialize(example, configuration) super diff --git a/spec/views/api_blueprint_example_spec.rb b/spec/views/api_blueprint_example_spec.rb index 427ef7d0..1d7d1343 100644 --- a/spec/views/api_blueprint_example_spec.rb +++ b/spec/views/api_blueprint_example_spec.rb @@ -59,7 +59,7 @@ context 'when charset=utf-8 is present' do it "just strips that because it's the default for json" do - expect(subject).to eq "Content-Type: application/json\n Another: header; charset=utf-8" + expect(subject).to eq "Content-Type: application/json\n Another: header; charset=utf-8" end end @@ -67,7 +67,7 @@ let(:content_type) { "application/json; charset=utf-16" } it "keeps that because it's NOT the default for json" do - expect(subject).to eq "Content-Type: application/json; charset=utf-16\n Another: header; charset=utf-8" + expect(subject).to eq "Content-Type: application/json; charset=utf-16\n Another: header; charset=utf-8" end end end @@ -95,7 +95,7 @@ context 'when charset=utf-8 is present' do it "just strips that because it's the default for json" do - expect(subject).to eq "Content-Type: application/json\n Another: header; charset=utf-8" + expect(subject).to eq "Content-Type: application/json\n Another: header; charset=utf-8" end end @@ -103,7 +103,7 @@ let(:content_type) { "application/json; charset=utf-16" } it "keeps that because it's NOT the default for json" do - expect(subject).to eq "Content-Type: application/json; charset=utf-16\n Another: header; charset=utf-8" + expect(subject).to eq "Content-Type: application/json; charset=utf-16\n Another: header; charset=utf-8" end end end diff --git a/templates/rspec_api_documentation/api_blueprint_index.mustache b/templates/rspec_api_documentation/api_blueprint_index.mustache index 20c359aa..8db8cbfa 100644 --- a/templates/rspec_api_documentation/api_blueprint_index.mustache +++ b/templates/rspec_api_documentation/api_blueprint_index.mustache @@ -48,13 +48,13 @@ explanation: {{ explanation }} + Headers - {{{ request_headers_text }}} + {{{ request_headers_text }}} {{/ request_headers_text }} {{# request_body }} + Body - {{{ request_body }}} + {{{ request_body }}} {{/ request_body }} {{# has_response? }} @@ -64,13 +64,13 @@ explanation: {{ explanation }} + Headers - {{{ response_headers_text }}} + {{{ response_headers_text }}} {{/ response_headers_text }} {{# response_body }} + Body - {{{ response_body }}} + {{{ response_body }}} {{/ response_body }} {{/ requests }} {{/ examples }} From 4378ce0ff657072aa124e50da4a606325c3cfb29 Mon Sep 17 00:00:00 2001 From: Joel AZEMAR Date: Thu, 8 Mar 2018 17:18:48 +0100 Subject: [PATCH 3/7] Add Api Name --- features/api_blueprint_documentation.feature | 1 + templates/rspec_api_documentation/api_blueprint_index.mustache | 1 + 2 files changed, 2 insertions(+) diff --git a/features/api_blueprint_documentation.feature b/features/api_blueprint_documentation.feature index 4a9fe390..17c343d0 100644 --- a/features/api_blueprint_documentation.feature +++ b/features/api_blueprint_documentation.feature @@ -249,6 +249,7 @@ Feature: Generate API Blueprint documentation from test examples Then the file "doc/api/index.apib" should contain exactly: """ FORMAT: 1A + # Example API # Group Instructions diff --git a/templates/rspec_api_documentation/api_blueprint_index.mustache b/templates/rspec_api_documentation/api_blueprint_index.mustache index 8db8cbfa..865f24a3 100644 --- a/templates/rspec_api_documentation/api_blueprint_index.mustache +++ b/templates/rspec_api_documentation/api_blueprint_index.mustache @@ -1,4 +1,5 @@ FORMAT: 1A +# {{ api_name }} {{# sections }} # Group {{ resource_name }} From 1f146cba4cc6f4af20d8ee71ac42d4760a955735 Mon Sep 17 00:00:00 2001 From: Joel AZEMAR Date: Mon, 12 Mar 2018 18:23:43 +0100 Subject: [PATCH 4/7] Path segments RFC 6570 - Path segments extensions were not following the RFC 6570 --- features/api_blueprint_documentation.feature | 2 +- .../views/api_blueprint_index.rb | 13 ++++++++++++- spec/views/api_blueprint_index_spec.rb | 4 ++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/features/api_blueprint_documentation.feature b/features/api_blueprint_documentation.feature index 17c343d0..77dba72b 100644 --- a/features/api_blueprint_documentation.feature +++ b/features/api_blueprint_documentation.feature @@ -354,7 +354,7 @@ Feature: Generate API Blueprint documentation from test examples ] } - ## Single Order [/orders/:id{?optional=:optional}] + ## Single Order [/orders{/id}{?optional=:optional}] + Parameters + id: 1 (required, string) - Order id diff --git a/lib/rspec_api_documentation/views/api_blueprint_index.rb b/lib/rspec_api_documentation/views/api_blueprint_index.rb index aa7a4d50..40cf9859 100644 --- a/lib/rspec_api_documentation/views/api_blueprint_index.rb +++ b/lib/rspec_api_documentation/views/api_blueprint_index.rb @@ -23,7 +23,7 @@ def sections { "has_attributes?".to_sym => attrs.size > 0, "has_parameters?".to_sym => params.size > 0, - route: route, + route: format_route(examples[0]), route_name: examples[0][:route_name], attributes: attrs, parameters: params, @@ -45,6 +45,17 @@ def examples private + # APIB follows the RFC 6570 to format URI templates. + # According to it, path segment expansion (used to describe URI path + # hierarchies) should be represented by `{/var}` and not by `/:var` + # For example `/posts/:id` should become `/posts{/id}` + # cf. https://github.com/apiaryio/api-blueprint/blob/format-1A/API%20Blueprint%20Specification.md#431-resource-section + # cf. https://tools.ietf.org/html/rfc6570#section-3.2.6 + def format_route(example) + route_uri = example[:route_uri].gsub(/\/:(.*?)([.\/?{]|$)/, '{/\1}\2') + "#{route_uri}#{example[:route_optionals]}" + end + # APIB has both `parameters` and `attributes`. This generates a hash # with all of its properties, like name, description, required. # { diff --git a/spec/views/api_blueprint_index_spec.rb b/spec/views/api_blueprint_index_spec.rb index 92b4e21c..f8e78beb 100644 --- a/spec/views/api_blueprint_index_spec.rb +++ b/spec/views/api_blueprint_index_spec.rb @@ -109,7 +109,7 @@ post_examples = post_route[:http_methods].map { |http_method| http_method[:examples] }.flatten expect(post_examples.size).to eq 2 - expect(post_route[:route]).to eq "/posts/:id" + expect(post_route[:route]).to eq "/posts{/id}" expect(post_route[:route_name]).to eq "Single Post" expect(post_route[:has_parameters?]).to eq true expect(post_route[:parameters]).to eq [{ @@ -130,7 +130,7 @@ post_w_optionals_examples = post_route_with_optionals[:http_methods].map { |http_method| http_method[:examples] }.flatten expect(post_w_optionals_examples.size).to eq 1 - expect(post_route_with_optionals[:route]).to eq "/posts/:id{?option=:option}" + expect(post_route_with_optionals[:route]).to eq "/posts{/id}{?option=:option}" expect(post_route_with_optionals[:route_name]).to eq "Single Post" expect(post_route_with_optionals[:has_parameters?]).to eq true expect(post_route_with_optionals[:parameters]).to eq [{ From 9bf3b72975f2801980b82580d6f766c524d639d0 Mon Sep 17 00:00:00 2001 From: Joel AZEMAR Date: Mon, 12 Mar 2018 18:56:08 +0100 Subject: [PATCH 5/7] Switch from path segment expansion to simple string expansion - Switch from path segment expansion to simple string expansion because the former is not supported by Apiary --- features/api_blueprint_documentation.feature | 2 +- lib/rspec_api_documentation/views/api_blueprint_index.rb | 8 ++++---- spec/views/api_blueprint_index_spec.rb | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/features/api_blueprint_documentation.feature b/features/api_blueprint_documentation.feature index 77dba72b..5b637633 100644 --- a/features/api_blueprint_documentation.feature +++ b/features/api_blueprint_documentation.feature @@ -354,7 +354,7 @@ Feature: Generate API Blueprint documentation from test examples ] } - ## Single Order [/orders{/id}{?optional=:optional}] + ## Single Order [/orders/{id}{?optional=:optional}] + Parameters + id: 1 (required, string) - Order id diff --git a/lib/rspec_api_documentation/views/api_blueprint_index.rb b/lib/rspec_api_documentation/views/api_blueprint_index.rb index 40cf9859..ca6a05d9 100644 --- a/lib/rspec_api_documentation/views/api_blueprint_index.rb +++ b/lib/rspec_api_documentation/views/api_blueprint_index.rb @@ -46,13 +46,13 @@ def examples private # APIB follows the RFC 6570 to format URI templates. - # According to it, path segment expansion (used to describe URI path - # hierarchies) should be represented by `{/var}` and not by `/:var` - # For example `/posts/:id` should become `/posts{/id}` + # According to it, simple string expansion (used to perform variable + # expansion) should be represented by `{var}` and not by `/:var` + # For example `/posts/:id` should become `/posts/{id}` # cf. https://github.com/apiaryio/api-blueprint/blob/format-1A/API%20Blueprint%20Specification.md#431-resource-section # cf. https://tools.ietf.org/html/rfc6570#section-3.2.6 def format_route(example) - route_uri = example[:route_uri].gsub(/\/:(.*?)([.\/?{]|$)/, '{/\1}\2') + route_uri = example[:route_uri].gsub(/:(.*?)([.\/?{]|$)/, '{\1}\2') "#{route_uri}#{example[:route_optionals]}" end diff --git a/spec/views/api_blueprint_index_spec.rb b/spec/views/api_blueprint_index_spec.rb index f8e78beb..862016c2 100644 --- a/spec/views/api_blueprint_index_spec.rb +++ b/spec/views/api_blueprint_index_spec.rb @@ -109,7 +109,7 @@ post_examples = post_route[:http_methods].map { |http_method| http_method[:examples] }.flatten expect(post_examples.size).to eq 2 - expect(post_route[:route]).to eq "/posts{/id}" + expect(post_route[:route]).to eq "/posts/{id}" expect(post_route[:route_name]).to eq "Single Post" expect(post_route[:has_parameters?]).to eq true expect(post_route[:parameters]).to eq [{ @@ -130,7 +130,7 @@ post_w_optionals_examples = post_route_with_optionals[:http_methods].map { |http_method| http_method[:examples] }.flatten expect(post_w_optionals_examples.size).to eq 1 - expect(post_route_with_optionals[:route]).to eq "/posts{/id}{?option=:option}" + expect(post_route_with_optionals[:route]).to eq "/posts/{id}{?option=:option}" expect(post_route_with_optionals[:route_name]).to eq "Single Post" expect(post_route_with_optionals[:has_parameters?]).to eq true expect(post_route_with_optionals[:parameters]).to eq [{ From 2f0a216c706725341b924c6484cd37fbb21630a9 Mon Sep 17 00:00:00 2001 From: Joel AZEMAR Date: Tue, 13 Mar 2018 12:02:09 +0100 Subject: [PATCH 6/7] Handle Attributes as Parameter for API Blueprint This let spec successfully passed. --- lib/rspec_api_documentation/dsl/endpoint/params.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/rspec_api_documentation/dsl/endpoint/params.rb b/lib/rspec_api_documentation/dsl/endpoint/params.rb index 037788b8..d5d003d2 100644 --- a/lib/rspec_api_documentation/dsl/endpoint/params.rb +++ b/lib/rspec_api_documentation/dsl/endpoint/params.rb @@ -13,11 +13,14 @@ def initialize(example_group, example, extra_params) end def call - parameters = example.metadata.fetch(:parameters, {}).inject({}) do |hash, param| + set_param = -> hash, param { SetParam.new(self, hash, param).call - end - parameters.deep_merge!(extra_params) - parameters + } + + example.metadata.fetch(:parameters, {}).inject({}, &set_param) + .deep_merge( + example.metadata.fetch(:attributes, {}).inject({}, &set_param) + ).deep_merge(extra_params) end private From 561552de9e567c3469f671980fcad9efc5ccaa7e Mon Sep 17 00:00:00 2001 From: Joel AZEMAR Date: Tue, 13 Mar 2018 13:44:49 +0100 Subject: [PATCH 7/7] Warning Duplicate definition of 'Content-Type' header - Remove Content-Type header from the Header sections --- features/api_blueprint_documentation.feature | 11 -------- .../views/api_blueprint_example.rb | 16 +++++++++-- spec/views/api_blueprint_example_spec.rb | 28 ++++--------------- 3 files changed, 20 insertions(+), 35 deletions(-) diff --git a/features/api_blueprint_documentation.feature b/features/api_blueprint_documentation.feature index 5b637633..00867429 100644 --- a/features/api_blueprint_documentation.feature +++ b/features/api_blueprint_documentation.feature @@ -269,7 +269,6 @@ Feature: Generate API Blueprint documentation from test examples + Headers - Content-Type: text/html;charset=utf-8 Content-Length: 57 + Body @@ -288,7 +287,6 @@ Feature: Generate API Blueprint documentation from test examples + Headers - Content-Type: application/json Host: example.org + Body @@ -308,7 +306,6 @@ Feature: Generate API Blueprint documentation from test examples + Headers - Content-Type: application/json Content-Length: 73 + Body @@ -333,7 +330,6 @@ Feature: Generate API Blueprint documentation from test examples + Headers - Content-Type: application/vnd.api+json Content-Length: 137 + Body @@ -372,13 +368,11 @@ Feature: Generate API Blueprint documentation from test examples + Headers Host: example.org - Content-Type: application/x-www-form-urlencoded + Response 200 (text/html;charset=utf-8) + Headers - Content-Type: text/html;charset=utf-8 Content-Length: 0 ### Returns a single order [GET] @@ -393,7 +387,6 @@ Feature: Generate API Blueprint documentation from test examples + Headers - Content-Type: application/json Content-Length: 73 + Body @@ -412,21 +405,18 @@ Feature: Generate API Blueprint documentation from test examples + Headers - Content-Type: application/json; charset=utf-16 Host: example.org + Response 400 (application/json) + Headers - Content-Type: application/json Content-Length: 0 + Request Update an order (application/json; charset=utf-16) + Headers - Content-Type: application/json; charset=utf-16 Host: example.org + Body @@ -445,7 +435,6 @@ Feature: Generate API Blueprint documentation from test examples + Headers - Content-Type: application/json Content-Length: 111 + Body diff --git a/lib/rspec_api_documentation/views/api_blueprint_example.rb b/lib/rspec_api_documentation/views/api_blueprint_example.rb index 5d60d219..35e8c810 100644 --- a/lib/rspec_api_documentation/views/api_blueprint_example.rb +++ b/lib/rspec_api_documentation/views/api_blueprint_example.rb @@ -20,14 +20,14 @@ def parameters def requests super.map do |request| - request[:request_headers_text] = remove_utf8_for_json(request[:request_headers_text]) + request[:request_headers_text] = remove_utf8_for_json(remove_content_type(request[:request_headers_text])) request[:request_headers_text] = indent(request[:request_headers_text]) request[:request_content_type] = content_type(request[:request_headers]) request[:request_content_type] = remove_utf8_for_json(request[:request_content_type]) request[:request_body] = body_to_json(request, :request) request[:request_body] = indent(request[:request_body]) - request[:response_headers_text] = remove_utf8_for_json(request[:response_headers_text]) + request[:response_headers_text] = remove_utf8_for_json(remove_content_type(request[:response_headers_text])) request[:response_headers_text] = indent(request[:response_headers_text]) request[:response_content_type] = content_type(request[:response_headers]) request[:response_content_type] = remove_utf8_for_json(request[:response_content_type]) @@ -46,6 +46,18 @@ def extension private + # `Content-Type` header is removed because the information would be duplicated + # since it's already present in `request[:request_content_type]`. + def remove_content_type(headers) + return unless headers + headers + .split("\n") + .reject { |header| + header.start_with?('Content-Type:') + } + .join("\n") + end + def has_request?(metadata) metadata.any? do |key, value| [:request_body, :request_headers, :request_content_type].include?(key) && value diff --git a/spec/views/api_blueprint_example_spec.rb b/spec/views/api_blueprint_example_spec.rb index 1d7d1343..fb70a5da 100644 --- a/spec/views/api_blueprint_example_spec.rb +++ b/spec/views/api_blueprint_example_spec.rb @@ -57,17 +57,9 @@ describe 'request_headers_text' do subject { view.requests[0][:request_headers_text] } - context 'when charset=utf-8 is present' do - it "just strips that because it's the default for json" do - expect(subject).to eq "Content-Type: application/json\n Another: header; charset=utf-8" - end - end - - context 'when charset=utf-16 is present' do - let(:content_type) { "application/json; charset=utf-16" } - - it "keeps that because it's NOT the default for json" do - expect(subject).to eq "Content-Type: application/json; charset=utf-16\n Another: header; charset=utf-8" + context 'when Content-Type is present' do + it "removes it" do + expect(subject).to eq "Another: header; charset=utf-8" end end end @@ -93,17 +85,9 @@ describe 'response_headers_text' do subject { view.requests[0][:response_headers_text] } - context 'when charset=utf-8 is present' do - it "just strips that because it's the default for json" do - expect(subject).to eq "Content-Type: application/json\n Another: header; charset=utf-8" - end - end - - context 'when charset=utf-16 is present' do - let(:content_type) { "application/json; charset=utf-16" } - - it "keeps that because it's NOT the default for json" do - expect(subject).to eq "Content-Type: application/json; charset=utf-16\n Another: header; charset=utf-8" + context 'when Content-Type is present' do + it "removes it" do + expect(subject).to eq "Another: header; charset=utf-8" end end end