forked from webmachine/webmachine-ruby
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add specs and fix some bugs on MediaType. See webmachine#1.
- Loading branch information
1 parent
adac09b
commit 622badf
Showing
4 changed files
with
99 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
require 'spec_helper' | ||
|
||
describe Webmachine::MediaType do | ||
let(:raw_type){ "application/xml;charset=UTF-8" } | ||
subject { described_class.new("application/xml", {"charset" => "UTF-8"}) } | ||
|
||
context "equivalence" do | ||
it { should == raw_type } | ||
it { should == described_class.parse(raw_type) } | ||
end | ||
|
||
context "when it is the wildcard type" do | ||
subject { described_class.new("*/*") } | ||
it { should be_matches_all } | ||
end | ||
|
||
context "parsing a type" do | ||
it "should return MediaTypes untouched" do | ||
described_class.parse(subject).should equal(subject) | ||
end | ||
|
||
it "should parse a String" do | ||
type = described_class.parse(raw_type) | ||
type.should be_kind_of(described_class) | ||
type.type.should == "application/xml" | ||
type.params.should == {"charset" => "UTF-8"} | ||
end | ||
|
||
it "should parse a type/params pair" do | ||
type = described_class.parse(["application/xml", {"charset" => "UTF-8"}]) | ||
type.should be_kind_of(described_class) | ||
type.type.should == "application/xml" | ||
type.params.should == {"charset" => "UTF-8"} | ||
end | ||
|
||
it "should parse a type/params pair where the type has some params in the string" do | ||
type = described_class.parse(["application/xml;version=1", {"charset" => "UTF-8"}]) | ||
type.should be_kind_of(described_class) | ||
type.type.should == "application/xml" | ||
type.params.should == {"charset" => "UTF-8", "version" => "1"} | ||
end | ||
|
||
it "should raise an error when given an invalid type/params pair" do | ||
expect { | ||
described_class.parse([false, "blah"]) | ||
}.to raise_error(ArgumentError) | ||
end | ||
end | ||
|
||
describe "matching a requested type" do | ||
it { should be_match("application/xml;charset=UTF-8") } | ||
it { should be_match("application/*;charset=UTF-8") } | ||
it { should be_match("*/*;charset=UTF-8") } | ||
it { should be_match("*;charset=UTF-8") } | ||
it { should_not be_match("text/xml") } | ||
it { should_not be_match("application/xml") } | ||
it { should_not be_match("application/xml;version=1") } | ||
|
||
it { should be_type_matches("application/xml") } | ||
it { should be_type_matches("application/*") } | ||
it { should be_type_matches("*/*") } | ||
it { should be_type_matches("*") } | ||
it { should_not be_type_matches("text/xml") } | ||
it { should_not be_type_matches("text/*") } | ||
end | ||
end |