File: date.rb

package info (click to toggle)
ruby-protocol-http 0.55.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 840 kB
  • sloc: ruby: 6,904; makefile: 4
file content (64 lines) | stat: -rw-r--r-- 1,543 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2023-2025, by Samuel Williams.

require "protocol/http/header/date"

describe Protocol::HTTP::Header::Date do
	let(:header) {subject.new(description)}
	
	with "Wed, 21 Oct 2015 07:28:00 GMT" do
		it "can parse time" do
			time = header.to_time
			expect(time).to be_a(::Time)
			
			expect(time).to have_attributes(
				year: be == 2015,
				month: be == 10,
				mday: be == 21,
				hour: be == 7,
				min: be == 28,
				sec: be == 0
			)
		end
	end
	
	with "#<<" do
		let(:header) {subject.new}
		
		it "can replace values" do
			header << "Wed, 21 Oct 2015 07:28:00 GMT"
			expect(header.to_time).to have_attributes(
				year: be == 2015,
				month: be == 10,
				mday: be == 21
			)
			
			header << "Wed, 22 Oct 2015 07:28:00 GMT"
			expect(header.to_time).to have_attributes(
				year: be == 2015,
				month: be == 10,
				mday: be == 22
			)
		end
	end
	
	describe Protocol::HTTP::Headers do
		let(:headers) {subject[[
				["Date", "Wed, 21 Oct 2015 07:28:00 GMT"],
				["Expires", "Wed, 21 Oct 2015 07:28:00 GMT"],
				["Last-Modified", "Wed, 21 Oct 2015 07:28:00 GMT"],
				["If-Modified-Since", "Wed, 21 Oct 2015 07:28:00 GMT"],
				["If-Unmodified-Since", "Wed, 21 Oct 2015 07:28:00 GMT"]
			]]
		}
		
		it "should parse date headers" do
			# When you convert headers into a hash, the policy is applied (i.e. conversion to Date instances):
			headers.to_h.each do |key, value|
				expect(value).to be_a(Protocol::HTTP::Header::Date)
			end
		end
	end
end