|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +# Released under the MIT License. |
| 4 | +# Copyright, 2018-2026, by Samuel Williams. |
| 5 | + |
| 6 | +require "protocol/http/error" |
| 7 | + |
| 8 | +describe Protocol::HTTP::DuplicateHeaderError do |
| 9 | + let(:key) {"content-length"} |
| 10 | + let(:existing_value) {"100"} |
| 11 | + let(:new_value) {"200"} |
| 12 | + let(:error) {subject.new(key, existing_value, new_value)} |
| 13 | + |
| 14 | + with "#initialize" do |
| 15 | + it "should set the key and values" do |
| 16 | + expect(error.key).to be == key |
| 17 | + expect(error.existing_value).to be == existing_value |
| 18 | + expect(error.new_value).to be == new_value |
| 19 | + end |
| 20 | + |
| 21 | + it "should have a descriptive message" do |
| 22 | + expect(error.message).to be =~ /Duplicate singleton header key: "content-length"/ |
| 23 | + end |
| 24 | + end |
| 25 | + |
| 26 | + with "#detailed_message" do |
| 27 | + it "should include the header key and both values" do |
| 28 | + message = error.detailed_message |
| 29 | + |
| 30 | + expect(message).to be =~ /Duplicate singleton header key: "content-length"/ |
| 31 | + expect(message).to be =~ /Existing value: "100"/ |
| 32 | + expect(message).to be =~ /New value: "200"/ |
| 33 | + end |
| 34 | + |
| 35 | + it "should work with highlight parameter" do |
| 36 | + message = error.detailed_message(highlight: true) |
| 37 | + |
| 38 | + expect(message).to be =~ /Duplicate singleton header key: "content-length"/ |
| 39 | + expect(message).to be =~ /Existing value: "100"/ |
| 40 | + expect(message).to be =~ /New value: "200"/ |
| 41 | + end |
| 42 | + end |
| 43 | +end |
0 commit comments