rspec-twirp 0.2.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,103 +0,0 @@
1
- describe :mock_twirp_connection do
2
- subject { client.bye(request) }
3
-
4
- let(:client) { GoodbyeClient.new(conn) }
5
- let(:request) { GoodbyeRequest.new }
6
- let(:response) { GoodbyeResponse.new(**response_attrs) }
7
- let(:response_attrs) { { message: "bye" } }
8
-
9
- context "without a mock" do
10
- let(:conn) { "http://localhost:3000/twirp/Goodbye/Bye" }
11
-
12
- it { expect { subject }.to raise_error(Faraday::Error) }
13
- end
14
-
15
- describe "with a response instance" do
16
- let(:conn) { mock_twirp_connection(response) }
17
-
18
- it { is_expected.to be_a(Twirp::ClientResp) }
19
- it { is_expected.to be_a_twirp_response }
20
- it { is_expected.to be_a_twirp_response(response) }
21
- it { is_expected.to be_a_twirp_response(message: "bye") }
22
-
23
- it "catches mismatches" do
24
- expect {
25
- is_expected.to be_a_twirp_response(message: "nope")
26
- }.to fail
27
- end
28
- end
29
-
30
- describe "with a response type" do
31
- let(:conn) { mock_twirp_connection(GoodbyeResponse) }
32
-
33
- it { is_expected.to be_a_twirp_response(GoodbyeResponse) }
34
-
35
- it "catches mismatches" do
36
- expect {
37
- is_expected.to be_a_twirp_response(HelloResponse)
38
- }.to fail
39
- end
40
- end
41
-
42
- describe "with default response" do
43
- let(:conn) { mock_twirp_connection }
44
-
45
- it { is_expected.to be_a_twirp_response(GoodbyeResponse) }
46
-
47
- context "and with attrs" do
48
- let(:conn) { mock_twirp_connection(message: "adios") }
49
-
50
- it { is_expected.to be_a_twirp_response(message: "adios") }
51
- end
52
- end
53
-
54
- describe "with an error" do
55
- let(:conn) { mock_twirp_connection(error) }
56
- let(:error) { Twirp::Error.not_found("nope") }
57
-
58
- it { is_expected.to be_a_twirp_response.with_error(error) }
59
-
60
- context "when error is symbol" do
61
- let(:error) { :not_found }
62
-
63
- it { is_expected.to be_a_twirp_response.with_error(404) }
64
- it { is_expected.to be_a_twirp_response.with_error(:not_found) }
65
- end
66
-
67
- context "when error is integer" do
68
- let(:error) { 500 }
69
-
70
- it { is_expected.to be_a_twirp_response.with_error(500) }
71
- it { is_expected.to be_a_twirp_response.with_error(:internal) }
72
- end
73
- end
74
-
75
- describe "with a block" do
76
- context "with a response object" do
77
- let(:conn) { mock_twirp_connection { response } }
78
-
79
- it { is_expected.to be_a_twirp_response(response) }
80
- end
81
-
82
- context "with response attrs" do
83
- let(:conn) { mock_twirp_connection { response_attrs } }
84
-
85
- it "determines the correct response type and incorporates the attrs" do
86
- is_expected.to be_a_twirp_response(GoodbyeResponse, **response_attrs)
87
- end
88
- end
89
-
90
- context "with error" do
91
- let(:conn) { mock_twirp_connection { error } }
92
- let(:error) { Twirp::Error.not_found("nope") }
93
-
94
- it { is_expected.to be_a_twirp_response.with_error(error) }
95
- end
96
-
97
- context "with error code" do
98
- let(:conn) { mock_twirp_connection { :not_found } }
99
-
100
- it { is_expected.to be_a_twirp_response.with_error(:not_found) }
101
- end
102
- end
103
- end
@@ -1,124 +0,0 @@
1
- describe "be_a_twirp_response" do
2
- context "with a response" do
3
- subject { Twirp::ClientResp.new(response, nil) }
4
-
5
- let(:response) { GoodbyeResponse.new }
6
-
7
- it { is_expected.to be_a_twirp_response }
8
-
9
- it "catches non-twirp response" do
10
- expect {
11
- expect(Object).to be_a_twirp_response
12
- }.to fail_with /found Object/
13
- end
14
-
15
- it "matches a specific response type" do
16
- is_expected.to be_a_twirp_response(GoodbyeResponse)
17
- end
18
-
19
- it "matches a specific response" do
20
- is_expected.to be_a_twirp_response(response)
21
- end
22
-
23
- it "catches type mismatches" do
24
- expect {
25
- is_expected.to be_a_twirp_response(HelloResponse)
26
- }.to fail_with /of type HelloResponse/
27
- end
28
-
29
- it "catches erroneous response types" do
30
- expect {
31
- is_expected.to be_a_twirp_response(Object)
32
- }.to raise_error(ArgumentError, /Object/)
33
- end
34
-
35
- context "with attributes" do
36
- subject { Twirp::ClientResp.new(GoodbyeResponse.new(**attrs), nil) }
37
-
38
- let(:attrs) { { message: "bye", name: "Bob" } }
39
-
40
- it "can match attributes" do
41
- is_expected.to be_a_twirp_response(GoodbyeResponse, **attrs)
42
- end
43
-
44
- it "supports regex matches" do
45
- is_expected.to be_a_twirp_response(name: /^B/)
46
- end
47
-
48
- it "catches mismatches" do
49
- expect {
50
- is_expected.to be_a_twirp_response(name: "nope")
51
- }.to fail_with /to have name: "nope"/
52
-
53
- expect {
54
- is_expected.to be_a_twirp_response(name: /no/)
55
- }.to fail_with /to have name: \/no\//
56
- end
57
-
58
- it "catches the erroneous attributes" do
59
- expect {
60
- is_expected.to be_a_twirp_response(namezzz: "Bob")
61
- }.to raise_error(ArgumentError, /namezzz/)
62
- end
63
-
64
- it "catches type mismatches" do
65
- expect {
66
- is_expected.to be_a_twirp_response(name: 123)
67
- }.to raise_error(TypeError, /string field.*given Integer/)
68
- end
69
-
70
- it "can't also match a specific response" do
71
- expect {
72
- is_expected.to be_a_twirp_response(response, name: "Bob")
73
- }.to raise_error(ArgumentError, /but not both/)
74
- end
75
- end
76
- end
77
-
78
- context "with error" do
79
- subject { Twirp::ClientResp.new(nil, error) }
80
-
81
- let(:error) { Twirp::Error.new(code, msg, meta) }
82
- let(:code) { :not_found }
83
- let(:msg) { "Not Found" }
84
- let(:meta) { { is_meta: "true" } }
85
-
86
- it { is_expected.to be_a_twirp_response.with_error }
87
- it { is_expected.to be_a_twirp_response.with_error(code) }
88
- it { is_expected.to be_a_twirp_response.with_error(msg) }
89
- it { is_expected.to be_a_twirp_response.with_error(**meta) }
90
- it { is_expected.to be_a_twirp_response.with_error(/Not/) }
91
-
92
- it "catches mismatches" do
93
- expect {
94
- is_expected.to be_a_twirp_response.with_error(:internal)
95
- }.to fail_with /code: :internal/
96
- end
97
- end
98
-
99
- context "with neither response nor error" do
100
- subject { Twirp::ClientResp.new(nil, nil) }
101
-
102
- it "fails the response match" do
103
- expect {
104
- is_expected.to be_a_twirp_response
105
- }.to fail_with /to have data/
106
- end
107
-
108
- it "fails the error match" do
109
- expect {
110
- is_expected.to be_a_twirp_response.with_error
111
- }.to fail_with /to have an error/
112
- end
113
- end
114
-
115
- context "with both response and error" do
116
- subject { Twirp::ClientResp.new(GoodbyeResponse.new, Twirp::Error.not_found("Not Found")) }
117
-
118
- it "fails" do
119
- expect {
120
- is_expected.to be_a_twirp_response(name: "Bob").with_error
121
- }.to raise_error(ArgumentError, /but not both/)
122
- end
123
- end
124
- end