File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -156,8 +156,8 @@ def chunked?
156156 # @param type [#to_s] Parse as given MIME type.
157157 # @raise (see MimeType.[])
158158 # @return [Object]
159- def parse ( type )
160- MimeType [ type ] . decode to_s
159+ def parse ( type = nil )
160+ MimeType [ type || mime_type ] . decode to_s
161161 end
162162
163163 # Inspect a response
Original file line number Diff line number Diff line change 8787 end
8888
8989 describe "#parse" do
90- let ( :headers ) { { "Content-Type" => "application/json" } }
90+ let ( :headers ) { { "Content-Type" => content_type } }
9191 let ( :body ) { '{"foo":"bar"}' }
9292
93- it "fails if MIME type decoder is not found" do
94- expect { response . parse "text/html" } . to raise_error ( HTTP ::Error )
93+ context "with known content type" do
94+ let ( :content_type ) { "application/json" }
95+ it "returns parsed body" do
96+ expect ( response . parse ) . to eq "foo" => "bar"
97+ end
9598 end
9699
97- it "uses decoder found by given MIME type" do
98- expect ( response . parse ( "application/json" ) ) . to eq ( "foo" => "bar" )
100+ context "with unknown content type" do
101+ let ( :content_type ) { "application/deadbeef" }
102+ it "raises HTTP::Error" do
103+ expect { response . parse } . to raise_error HTTP ::Error
104+ end
99105 end
100106
101- it "uses decoder found by given MIME type alias" do
102- expect ( response . parse ( :json ) ) . to eq ( "foo" => "bar" )
107+ context "with explicitly given mime type" do
108+ let ( :content_type ) { "application/deadbeef" }
109+ it "ignores mime_type of response" do
110+ expect ( response . parse ( "application/json" ) ) . to eq "foo" => "bar"
111+ end
112+
113+ it "supports mime type aliases" do
114+ expect ( response . parse ( :json ) ) . to eq "foo" => "bar"
115+ end
103116 end
104117 end
105118
You can’t perform that action at this time.
0 commit comments