spec/webmachine/decision/conneg_spec.rb in webmachine-0.4.2 vs spec/webmachine/decision/conneg_spec.rb in webmachine-1.0.0
- old
+ new
@@ -1,15 +1,9 @@
require 'spec_helper'
describe Webmachine::Decision::Conneg do
- let(:request) { Webmachine::Request.new("GET", URI.parse("http://localhost:8080/"), Webmachine::Headers["accept" => "*/*"], "") }
- let(:response) { Webmachine::Response.new }
- let(:resource) do
- Class.new(Webmachine::Resource) do
- def to_html; "hello world!"; end
- end
- end
+ include_context "default resource"
subject do
Webmachine::Decision::FSM.new(resource, request, response)
end
@@ -31,11 +25,11 @@
subject.choose_media_type(["text/html",
["text/html", {"charset" => "iso8859-1"}]],
"text/html;charset=iso8859-1, application/xml").
should == "text/html;charset=iso8859-1"
end
-
+
it "should choose a type more specific than requested when an exact match is not present" do
subject.choose_media_type(["application/json;v=3;foo=bar", "application/json;v=2"],
"text/html, application/json").
should == "application/json;v=3;foo=bar"
end
@@ -68,9 +62,16 @@
response.headers['Content-Encoding'].should be_nil
end
it "should choose the first acceptable encoding" do
subject.choose_encoding({"gzip" => :encode_gzip}, "identity, gzip")
+ subject.metadata['Content-Encoding'].should == 'gzip'
+ response.headers['Content-Encoding'].should == 'gzip'
+ end
+
+ it "should choose the first acceptable encoding" \
+ ", even when no white space after comma" do
+ subject.choose_encoding({"gzip" => :encode_gzip}, "identity,gzip")
subject.metadata['Content-Encoding'].should == 'gzip'
response.headers['Content-Encoding'].should == 'gzip'
end
it "should choose the preferred encoding over less-preferred encodings" do