File: instance_spec.rb

package info (click to toggle)
ruby-http-parser 1.2.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 280 kB
  • sloc: ansic: 2,137; ruby: 672; makefile: 12
file content (78 lines) | stat: -rw-r--r-- 1,999 bytes parent folder | download | duplicates (2)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
require 'http-parser'

describe ::HttpParser::Instance, "#initialize" do
    context "when given a block" do
        it "should yield the new Instance" do
            expected = nil

            described_class.new { |inst| expected = inst }

            expect(expected).to be_kind_of(described_class)
        end

        it "should allow changing the parser type" do
            inst = described_class.new do |inst|
                inst.type = :request
            end

            expect(inst.type).to eq(:request)
        end
    end

    describe "#type" do
        xit "should default to :both" do
            expect(subject.type).to eq(:both)
        end

        it "should convert the type to a Symbol" do
            subject[:type_flags] = ::HttpParser::TYPES[:request]

            expect(subject.type).to eq(:request)
        end

        it "should extract the type from the type_flags field" do
            subject[:type_flags] = ((0xff & ~0x3) | ::HttpParser::TYPES[:response])

            expect(subject.type).to eq(:response)
        end
    end

    describe "#type=" do
        it "should set the type" do
            subject.type = :response

            expect(subject.type).to eq(:response)
        end

        it "should not change flags" do
            flags = (0xff & ~0x3)
            subject[:type_flags] = flags

            subject.type = :request

            expect(subject[:type_flags]).to eq((flags | ::HttpParser::TYPES[:request]))
        end
    end

    describe "#stop!" do
        it "should throw :return, 1" do
            expect { subject.stop! }.to throw_symbol(:return,1)
        end
    end

    describe "#error!" do
        it "should throw :return, -1" do
            expect { subject.error! }.to throw_symbol(:return,-1)
        end
    end

    it "should not change the type" do
        inst = described_class.new do |inst|
            inst.type = :request
        end

        inst.reset!
        expect(inst.type).to eq(:request)
    end
end