File: methods.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 (60 lines) | stat: -rw-r--r-- 1,445 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
# frozen_string_literal: true

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

require "protocol/http/methods"

ValidMethod = Sus::Shared("valid method") do |name|
	it "defines #{name} method" do
		expect(Protocol::HTTP::Methods.constants).to be(:include?, name.to_sym)
	end
	
	it "has correct value" do
		expect(Protocol::HTTP::Methods.const_get(name)).to be == name.to_s
	end
	
	it "is a valid method" do
		expect(Protocol::HTTP::Methods).to be(:valid?, name)
	end
end

describe Protocol::HTTP::Methods do
	it "defines several methods" do
		expect(subject.constants).not.to be(:empty?)
	end
	
	it_behaves_like ValidMethod, "GET"
	it_behaves_like ValidMethod, "POST"
	it_behaves_like ValidMethod, "PUT"
	it_behaves_like ValidMethod, "PATCH"
	it_behaves_like ValidMethod, "DELETE"
	it_behaves_like ValidMethod, "HEAD"
	it_behaves_like ValidMethod, "OPTIONS"
	it_behaves_like ValidMethod, "TRACE"
	it_behaves_like ValidMethod, "CONNECT"
	
	it "defines exactly 9 methods" do
		expect(subject.constants.length).to be == 9
	end
	
	with ".valid?" do
		with "FOOBAR" do
			it "is not a valid method" do
				expect(subject).not.to be(:valid?, description)
			end
		end
		
		with "GETEMALL" do
			it "is not a valid method" do
				expect(subject).not.to be(:valid?, description)
			end
		end
		
		with "Accept:" do
			it "is not a valid method" do
				expect(subject).not.to be(:valid?, description)
			end
		end
	end
end