|
11 | 11 | expect(media_range.quality_factor).to be == 1.0
|
12 | 12 | end
|
13 | 13 |
|
14 |
| - with "#===" do |
15 |
| - let(:media_range) {subject.new("text", "plain")} |
16 |
| - |
17 |
| - it "can compare with bare string" do |
18 |
| - expect(media_range).to be === "text/plain" |
19 |
| - end |
20 |
| - |
21 |
| - it "can compare with media range" do |
22 |
| - expect(media_range).to be === media_range |
23 |
| - end |
24 |
| - end |
25 |
| - |
26 | 14 | with "#to_s" do
|
27 | 15 | it "can convert to string" do
|
28 | 16 | media_range = subject.new("text", "plain", {"q" => "0.5"})
|
29 | 17 | expect(media_range.to_s).to be == "text/plain;q=0.5"
|
30 | 18 | end
|
31 | 19 | end
|
32 |
| - |
33 |
| - with "#split" do |
34 |
| - it "can split media range" do |
35 |
| - media_range = subject.new("text", "plain", {"q" => "0.5"}) |
36 |
| - type, subtype = media_range.split |
37 |
| - expect(type).to be == "text" |
38 |
| - expect(subtype).to be == "plain" |
39 |
| - end |
40 |
| - end |
41 | 20 | end
|
42 | 21 |
|
43 | 22 | describe Protocol::HTTP::Header::Accept do
|
|
48 | 27 | it "can parse media ranges" do
|
49 | 28 | expect(header.length).to be == 3
|
50 | 29 |
|
51 |
| - expect(media_ranges[0].range_string).to be == "text/plain" |
52 |
| - expect(media_ranges[0].quality_factor).to be == 1.0 |
53 |
| - |
54 |
| - expect(media_ranges[1].range_string).to be == "text/html" |
55 |
| - expect(media_ranges[1].quality_factor).to be == 0.5 |
| 30 | + expect(media_ranges[0]).to have_attributes( |
| 31 | + type: be == "text", |
| 32 | + subtype: be == "plain", |
| 33 | + quality_factor: be == 1.0 |
| 34 | + ) |
56 | 35 |
|
57 |
| - expect(media_ranges[2].range_string).to be == "text/xml" |
| 36 | + expect(media_ranges[1]).to have_attributes( |
| 37 | + type: be == "text", |
| 38 | + subtype: be == "html", |
| 39 | + quality_factor: be == 0.5 |
| 40 | + ) |
| 41 | + |
| 42 | + expect(media_ranges[2]).to have_attributes( |
| 43 | + type: be == "text", |
| 44 | + subtype: be == "xml", |
| 45 | + quality_factor: be == 0.25 |
| 46 | + ) |
58 | 47 | end
|
59 | 48 |
|
60 | 49 | it "can convert to string" do
|
|
70 | 59 |
|
71 | 60 | with "text/html;q=0.25, text/xml;q=0.5, text/plain" do
|
72 | 61 | it "should order based on quality factor" do
|
73 |
| - expect(media_ranges.collect(&:range_string)).to be == %w{text/plain text/xml text/html} |
| 62 | + expect(media_ranges.collect(&:to_s)).to be == %w{text/plain text/xml;q=0.5 text/html;q=0.25} |
74 | 63 | end
|
75 | 64 | end
|
76 | 65 |
|
77 | 66 | with "text/html, text/plain;q=0.8, text/xml;q=0.6, application/json" do
|
78 | 67 | it "should order based on quality factor" do
|
79 |
| - expect(media_ranges.collect(&:range_string)).to be == %w{text/html application/json text/plain text/xml} |
| 68 | + expect(media_ranges.collect(&:to_s)).to be == %w{text/html application/json text/plain;q=0.8 text/xml;q=0.6} |
80 | 69 | end
|
81 | 70 | end
|
82 | 71 |
|
83 |
| - with "*/*;q=0" do |
| 72 | + with "*/*" do |
84 | 73 | it "should accept wildcard media range" do
|
85 |
| - expect(media_ranges[0].range_string).to be == "*/*" |
86 |
| - expect(media_ranges[0].quality_factor).to be == 0 |
| 74 | + expect(media_ranges[0].to_s).to be == "*/*" |
87 | 75 | end
|
88 | 76 | end
|
89 | 77 |
|
|
0 commit comments