rspec-twirp 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/rspec/twirp/client_response_matcher.rb +48 -0
- data/lib/rspec/twirp/error_matcher.rb +49 -0
- data/lib/rspec/twirp/request_matcher.rb +37 -0
- data/lib/rspec/twirp/response_matcher.rb +37 -0
- data/lib/rspec/twirp/version.rb +5 -0
- data/lib/rspec/twirp.rb +32 -0
- data/lib/rspec-twirp.rb +1 -5
- data/spec/client_response_spec.rb +112 -0
- data/spec/error_spec.rb +86 -0
- data/spec/request_spec.rb +75 -0
- data/spec/response_spec.rb +56 -0
- metadata +46 -5
- data/lib/rspec-twirp/version.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2f0ca51df29824ba1c1f2d1944ca94119501b3ec6366d09144f077bd99c92f2
|
4
|
+
data.tar.gz: 513bdae144ce76ecec652954cff14d3f8467037f6ec706ab67181be0ac036d61
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a4ebdce6d3d96826eca31484d1d4c22dc5b9e07fb109bea659315c5cfc7265f497f8d0a0bb498115e654ee139b232d6c6eb74bfd6da03a325a44411e636486c
|
7
|
+
data.tar.gz: 4342593db5f6e34db3fb0c3829a04ff1b8bc5806960e6b0efb144f650c38b80b08559b7f1f1a616a1c36712e2fb4a1c9cb963e457accd9451ac1ad3a6314096f
|
@@ -0,0 +1,48 @@
|
|
1
|
+
RSpec::Matchers.define :be_a_twirp_client_response do |type = nil, **attrs|
|
2
|
+
chain :with_error do |*matchers, **meta_matchers|
|
3
|
+
# code, msg, meta
|
4
|
+
@with_error = [ matchers, meta_matchers ]
|
5
|
+
end
|
6
|
+
|
7
|
+
match do |actual|
|
8
|
+
# ensure type is a valid twirp request type
|
9
|
+
if type && !(type < Google::Protobuf::MessageExts)
|
10
|
+
raise ArgumentError, "Expected `type` to be a Twirp response, found: #{type}"
|
11
|
+
end
|
12
|
+
|
13
|
+
@fail_msg = "Expected a Twirp::ClientResp, found #{actual}"
|
14
|
+
return false unless actual.is_a?(Twirp::ClientResp)
|
15
|
+
|
16
|
+
# match expected response type
|
17
|
+
@fail_msg = "Expected a Twirp::ClientResp of type #{type}, found #{actual.data&.class}"
|
18
|
+
return false if type && actual.data&.class != type
|
19
|
+
|
20
|
+
if @with_error
|
21
|
+
unless attrs.empty?
|
22
|
+
raise ArgumentError, "match data attributes or error, but not both"
|
23
|
+
end
|
24
|
+
|
25
|
+
@fail_msg = "Expected #{actual} to have an error"
|
26
|
+
return false unless actual.error
|
27
|
+
|
28
|
+
matchers, meta_matchers = @with_error
|
29
|
+
expect(actual.error).to be_a_twirp_error(*matchers, **meta_matchers)
|
30
|
+
else
|
31
|
+
@fail_msg = "Expected #{actual} to have data"
|
32
|
+
return false unless actual.data
|
33
|
+
|
34
|
+
expect(actual.data).to be_a_twirp_response(**attrs)
|
35
|
+
end
|
36
|
+
rescue RSpec::Expectations::ExpectationNotMetError => err
|
37
|
+
@fail_msg = err.message
|
38
|
+
false
|
39
|
+
end
|
40
|
+
|
41
|
+
description do
|
42
|
+
type ? "a #{type} Twirp response" : "a Twirp response"
|
43
|
+
end
|
44
|
+
|
45
|
+
failure_message { @fail_msg }
|
46
|
+
end
|
47
|
+
|
48
|
+
RSpec::Matchers.alias_matcher :a_twirp_client_response, :be_a_twirp_client_response
|
@@ -0,0 +1,49 @@
|
|
1
|
+
RSpec::Matchers.define :be_a_twirp_error do |*matchers, **meta_matcher|
|
2
|
+
match do |actual|
|
3
|
+
@fail_msg = "Expected #{actual} to be a Twirp::Error, found #{actual.class}"
|
4
|
+
return false unless actual.is_a?(Twirp::Error)
|
5
|
+
|
6
|
+
matchers.each do |matcher|
|
7
|
+
case matcher
|
8
|
+
when Symbol
|
9
|
+
# match code
|
10
|
+
|
11
|
+
unless Twirp::Error.valid_code?(matcher)
|
12
|
+
raise ArgumentError, "invalid error code: #{matcher.inspect}"
|
13
|
+
end
|
14
|
+
|
15
|
+
@fail_msg = "Expected #{actual} to have code: #{matcher.inspect}, found #{actual.code}"
|
16
|
+
return false unless actual.code == matcher
|
17
|
+
else
|
18
|
+
# match msg
|
19
|
+
|
20
|
+
@fail_msg = "Expected #{actual} to have msg: #{matcher.inspect}, found #{actual.msg}"
|
21
|
+
return false unless values_match?(matcher, actual.msg)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# match meta
|
26
|
+
unless meta_matcher.empty?
|
27
|
+
@cur_match = { meta: meta_matcher }
|
28
|
+
|
29
|
+
# sanity check...values must be Strings or Regexp
|
30
|
+
discrete_attrs = meta_matcher.transform_values do |attr|
|
31
|
+
attr.is_a?(Regexp) ? attr.inspect : attr
|
32
|
+
end
|
33
|
+
actual.send(:validate_meta, discrete_attrs)
|
34
|
+
|
35
|
+
@fail_msg = "Expected #{actual} to have meta: #{meta_matcher.inspect}, found #{actual.meta}"
|
36
|
+
return false unless values_match?(meta_matcher, actual.meta)
|
37
|
+
end
|
38
|
+
|
39
|
+
true
|
40
|
+
end
|
41
|
+
|
42
|
+
description do
|
43
|
+
"a Twirp::Error"
|
44
|
+
end
|
45
|
+
|
46
|
+
failure_message { @fail_msg }
|
47
|
+
end
|
48
|
+
|
49
|
+
RSpec::Matchers.alias_matcher :a_twirp_error, :be_a_twirp_error
|
@@ -0,0 +1,37 @@
|
|
1
|
+
RSpec::Matchers.define :be_a_twirp_request do |type = nil, **attrs|
|
2
|
+
match do |actual|
|
3
|
+
# ensure type is a valid twirp request type
|
4
|
+
if type && !(type < Google::Protobuf::MessageExts)
|
5
|
+
raise ArgumentError, "Expected `type` to be a Twirp request, found: #{type}"
|
6
|
+
end
|
7
|
+
|
8
|
+
@fail_msg = "Expected a Twirp request, found #{actual}"
|
9
|
+
return false unless actual.is_a?(Google::Protobuf::MessageExts)
|
10
|
+
|
11
|
+
# match expected request type
|
12
|
+
@fail_msg = "Expected a Twirp request of type #{type}, found #{actual.class}"
|
13
|
+
return false if type && actual.class != type
|
14
|
+
|
15
|
+
return true if attrs.empty?
|
16
|
+
|
17
|
+
RSpec::Twirp.validate_types(attrs, actual.class)
|
18
|
+
|
19
|
+
# match attributes which are present
|
20
|
+
attrs.each do |attr_name, expected_attr|
|
21
|
+
actual_attr = actual.send(attr_name)
|
22
|
+
|
23
|
+
@fail_msg = "Expected #{actual} to have #{attr_name}: #{expected_attr.inspect}, found #{actual_attr}"
|
24
|
+
return false unless values_match?(expected_attr, actual_attr)
|
25
|
+
end
|
26
|
+
|
27
|
+
true
|
28
|
+
end
|
29
|
+
|
30
|
+
description do
|
31
|
+
type ? "a #{type} Twirp request" : "a Twirp request"
|
32
|
+
end
|
33
|
+
|
34
|
+
failure_message { @fail_msg }
|
35
|
+
end
|
36
|
+
|
37
|
+
RSpec::Matchers.alias_matcher :a_twirp_request, :be_a_twirp_request
|
@@ -0,0 +1,37 @@
|
|
1
|
+
RSpec::Matchers.define :be_a_twirp_response do |type = nil, **attrs|
|
2
|
+
match do |actual|
|
3
|
+
# ensure type is a valid twirp response type
|
4
|
+
if type && !(type < Google::Protobuf::MessageExts)
|
5
|
+
raise ArgumentError, "Expected `type` to be a Twirp response, found: #{type}"
|
6
|
+
end
|
7
|
+
|
8
|
+
@fail_msg = "Expected a Twirp response, found #{actual}"
|
9
|
+
return false unless actual.is_a?(Google::Protobuf::MessageExts)
|
10
|
+
|
11
|
+
# match expected response type
|
12
|
+
@fail_msg = "Expected a Twirp response of type #{type}, found #{actual.class}"
|
13
|
+
return false if type && actual.class != type
|
14
|
+
|
15
|
+
return true if attrs.empty?
|
16
|
+
|
17
|
+
RSpec::Twirp.validate_types(attrs, actual.class)
|
18
|
+
|
19
|
+
# match attributes which are present
|
20
|
+
attrs.each do |attr_name, expected_attr|
|
21
|
+
actual_attr = actual.send(attr_name)
|
22
|
+
|
23
|
+
@fail_msg = "Expected #{actual} to have #{attr_name}: #{expected_attr.inspect}, found #{actual_attr}"
|
24
|
+
return false unless values_match?(expected_attr, actual_attr)
|
25
|
+
end
|
26
|
+
|
27
|
+
true
|
28
|
+
end
|
29
|
+
|
30
|
+
description do
|
31
|
+
type ? "a #{type} Twirp response" : "a Twirp response"
|
32
|
+
end
|
33
|
+
|
34
|
+
failure_message { @fail_msg }
|
35
|
+
end
|
36
|
+
|
37
|
+
RSpec::Matchers.alias_matcher :a_twirp_response, :be_a_twirp_response
|
data/lib/rspec/twirp.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require "rspec/expectations"
|
2
|
+
require "rspec/twirp/client_response_matcher"
|
3
|
+
require "rspec/twirp/error_matcher"
|
4
|
+
require "rspec/twirp/request_matcher"
|
5
|
+
require "rspec/twirp/response_matcher"
|
6
|
+
|
7
|
+
module RSpec
|
8
|
+
module Twirp
|
9
|
+
extend self
|
10
|
+
|
11
|
+
def validate_types(attrs, klass)
|
12
|
+
# sanity check type and names of attrs by constructing an actual
|
13
|
+
# proto object
|
14
|
+
discrete_attrs = attrs.transform_values do |attr|
|
15
|
+
case attr
|
16
|
+
when Regexp
|
17
|
+
attr.inspect
|
18
|
+
when Range
|
19
|
+
attr.first
|
20
|
+
when RSpec::Matchers::BuiltIn::BaseMatcher
|
21
|
+
nil
|
22
|
+
else
|
23
|
+
attr
|
24
|
+
end
|
25
|
+
end.compact
|
26
|
+
|
27
|
+
klass.new(**discrete_attrs)
|
28
|
+
rescue Google::Protobuf::TypeError => e
|
29
|
+
raise TypeError, e.message
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/rspec-twirp.rb
CHANGED
@@ -0,0 +1,112 @@
|
|
1
|
+
describe "be_a_twirp_client_response" do
|
2
|
+
context "with a response" do
|
3
|
+
subject { Twirp::ClientResp.new(GoodbyeResponse.new, nil) }
|
4
|
+
|
5
|
+
it { is_expected.to be_a_twirp_client_response }
|
6
|
+
|
7
|
+
it "catches non-twirp response" do
|
8
|
+
expect {
|
9
|
+
expect(Object).to be_a_twirp_client_response
|
10
|
+
}.to fail_with /found Object/
|
11
|
+
end
|
12
|
+
|
13
|
+
it "matches a specific response type" do
|
14
|
+
is_expected.to be_a_twirp_client_response(GoodbyeResponse)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "catches type mismatches" do
|
18
|
+
expect {
|
19
|
+
is_expected.to be_a_twirp_client_response(HelloResponse)
|
20
|
+
}.to fail_with /of type HelloResponse/
|
21
|
+
end
|
22
|
+
|
23
|
+
it "catches erroneous response types" do
|
24
|
+
expect {
|
25
|
+
is_expected.to be_a_twirp_client_response(Object)
|
26
|
+
}.to raise_error(ArgumentError, /Object/)
|
27
|
+
end
|
28
|
+
|
29
|
+
context "with attributes" do
|
30
|
+
subject { Twirp::ClientResp.new(GoodbyeResponse.new(**attrs), nil) }
|
31
|
+
|
32
|
+
let(:attrs) { { message: "bye", name: "Bob" } }
|
33
|
+
|
34
|
+
it "can match attributes" do
|
35
|
+
is_expected.to be_a_twirp_client_response(GoodbyeResponse, **attrs)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "supports regex matches" do
|
39
|
+
is_expected.to be_a_twirp_client_response(name: /^B/)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "catches mismatches" do
|
43
|
+
expect {
|
44
|
+
is_expected.to be_a_twirp_client_response(name: "nope")
|
45
|
+
}.to fail_with /to have name: "nope"/
|
46
|
+
|
47
|
+
expect {
|
48
|
+
is_expected.to be_a_twirp_client_response(name: /no/)
|
49
|
+
}.to fail_with /to have name: \/no\//
|
50
|
+
end
|
51
|
+
|
52
|
+
it "catches the erroneous attributes" do
|
53
|
+
expect {
|
54
|
+
is_expected.to be_a_twirp_client_response(namezzz: "Bob")
|
55
|
+
}.to raise_error(ArgumentError, /namezzz/)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "catches type mismatches" do
|
59
|
+
expect {
|
60
|
+
is_expected.to be_a_twirp_client_response(name: 123)
|
61
|
+
}.to raise_error(TypeError, /string field.*given Integer/)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context "with error" do
|
67
|
+
subject { Twirp::ClientResp.new(nil, error) }
|
68
|
+
|
69
|
+
let(:error) { Twirp::Error.new(code, msg, meta) }
|
70
|
+
let(:code) { :not_found }
|
71
|
+
let(:msg) { "Not Found" }
|
72
|
+
let(:meta) { { is_meta: "true" } }
|
73
|
+
|
74
|
+
it { is_expected.to be_a_twirp_client_response.with_error }
|
75
|
+
it { is_expected.to be_a_twirp_client_response.with_error(code) }
|
76
|
+
it { is_expected.to be_a_twirp_client_response.with_error(msg) }
|
77
|
+
it { is_expected.to be_a_twirp_client_response.with_error(**meta) }
|
78
|
+
it { is_expected.to be_a_twirp_client_response.with_error(/Not/) }
|
79
|
+
|
80
|
+
it "catches mismatches" do
|
81
|
+
expect {
|
82
|
+
is_expected.to be_a_twirp_client_response.with_error(:internal)
|
83
|
+
}.to fail_with /code: :internal/
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context "with neither response nor error" do
|
88
|
+
subject { Twirp::ClientResp.new(nil, nil) }
|
89
|
+
|
90
|
+
it "fails the response match" do
|
91
|
+
expect {
|
92
|
+
is_expected.to be_a_twirp_client_response
|
93
|
+
}.to fail_with /to have data/
|
94
|
+
end
|
95
|
+
|
96
|
+
it "fails the error match" do
|
97
|
+
expect {
|
98
|
+
is_expected.to be_a_twirp_client_response.with_error
|
99
|
+
}.to fail_with /to have an error/
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
context "with both response and error" do
|
104
|
+
subject { Twirp::ClientResp.new(GoodbyeResponse.new, Twirp::Error.not_found("Not Found")) }
|
105
|
+
|
106
|
+
it "fails" do
|
107
|
+
expect {
|
108
|
+
is_expected.to be_a_twirp_client_response(name: "Bob").with_error
|
109
|
+
}.to raise_error(ArgumentError, /but not both/)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
data/spec/error_spec.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
describe "be_a_twirp_error" do
|
2
|
+
subject { Twirp::Error.new(code, msg, meta) }
|
3
|
+
|
4
|
+
let(:code) { :not_found }
|
5
|
+
let(:msg) { "Not Found" }
|
6
|
+
let(:meta) { { is_meta: "true" } }
|
7
|
+
|
8
|
+
it { is_expected.to be_a_twirp_error }
|
9
|
+
|
10
|
+
it "catches type mismatches" do
|
11
|
+
expect {
|
12
|
+
expect(Object).to be_a_twirp_error
|
13
|
+
}.to fail_with /to be a Twirp::Error/
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "code matches" do
|
17
|
+
it { is_expected.to be_a_twirp_error(:not_found) }
|
18
|
+
|
19
|
+
it { expect { is_expected.to be_a_twirp_error(:unknown) }.to fail }
|
20
|
+
|
21
|
+
it "catches erroneous codes" do
|
22
|
+
expect {
|
23
|
+
is_expected.to be_a_twirp_error(:not_a_valid_code)
|
24
|
+
}.to raise_error(ArgumentError, /:not_a_valid_code/)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "msg matches" do
|
29
|
+
it { is_expected.to be_a_twirp_error("Not Found") }
|
30
|
+
|
31
|
+
it "supports Regex matches" do
|
32
|
+
is_expected.to be_a_twirp_error(/Not/)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "catches mismatches" do
|
36
|
+
expect {
|
37
|
+
is_expected.to be_a_twirp_error("Not")
|
38
|
+
}.to fail_with /to have msg: "Not"/
|
39
|
+
|
40
|
+
expect {
|
41
|
+
is_expected.to be_a_twirp_error(/Nope/)
|
42
|
+
}.to fail_with /to have msg: \/Nope\//
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "meta matches" do
|
47
|
+
it { is_expected.to be_a_twirp_error(is_meta: "true") }
|
48
|
+
it { is_expected.to be_a_twirp_error(is_meta: /^t/) }
|
49
|
+
|
50
|
+
it "catches mismatches" do
|
51
|
+
expect {
|
52
|
+
is_expected.to be_a_twirp_error(is_meta: "false")
|
53
|
+
}.to fail_with /to have meta.*is_meta/
|
54
|
+
|
55
|
+
expect {
|
56
|
+
is_expected.to be_a_twirp_error(not_meta: "")
|
57
|
+
}.to fail_with /to have meta.*not_meta/
|
58
|
+
end
|
59
|
+
|
60
|
+
it "catches type errors" do
|
61
|
+
expect {
|
62
|
+
is_expected.to be_a_twirp_error(is_meta: true)
|
63
|
+
}.to raise_error(ArgumentError, /meta values must be Strings/)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "multi matches" do
|
68
|
+
it { is_expected.to be_a_twirp_error(:not_found, "Not Found") }
|
69
|
+
it { is_expected.to be_a_twirp_error(:not_found, /Not/) }
|
70
|
+
it { is_expected.to be_a_twirp_error(:not_found, is_meta: "true") }
|
71
|
+
|
72
|
+
it "catches mismatches" do
|
73
|
+
expect {
|
74
|
+
is_expected.to be_a_twirp_error(:unknown, "Not Found")
|
75
|
+
}.to fail_with /unknown/
|
76
|
+
|
77
|
+
expect {
|
78
|
+
is_expected.to be_a_twirp_error(:not_found, "Nope")
|
79
|
+
}.to fail_with /Nope/
|
80
|
+
|
81
|
+
expect {
|
82
|
+
is_expected.to be_a_twirp_error(:not_found, is_meta: "false")
|
83
|
+
}.to fail_with /false/
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
describe "be_a_twirp_request" do
|
2
|
+
subject { HelloRequest.new(**attrs) }
|
3
|
+
|
4
|
+
let(:attrs) { {} }
|
5
|
+
|
6
|
+
it { is_expected.to be_a_twirp_request }
|
7
|
+
|
8
|
+
it "catches non-twirp requests" do
|
9
|
+
expect {
|
10
|
+
expect(Object).to be_a_twirp_request
|
11
|
+
}.to fail_with /Expected a Twirp request, found Object/
|
12
|
+
end
|
13
|
+
|
14
|
+
it "matches a specific request type" do
|
15
|
+
is_expected.to be_a_twirp_request(HelloRequest)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "catches type mismatches" do
|
19
|
+
expect {
|
20
|
+
is_expected.to be_a_twirp_request(GoodbyeRequest)
|
21
|
+
}.to fail_with /request of type GoodbyeRequest/
|
22
|
+
end
|
23
|
+
|
24
|
+
it "catches erroneous request types" do
|
25
|
+
expect {
|
26
|
+
is_expected.to be_a_twirp_request(Object)
|
27
|
+
}.to raise_error(ArgumentError, /Object/)
|
28
|
+
end
|
29
|
+
|
30
|
+
context "with attributes" do
|
31
|
+
let(:attrs) { { name: "Bob", count: 3 } }
|
32
|
+
|
33
|
+
it "can match attributes" do
|
34
|
+
is_expected.to be_a_twirp_request(HelloRequest, **attrs)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "supports regex matches" do
|
38
|
+
is_expected.to be_a_twirp_request(name: /^B/)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "supports range matches" do
|
42
|
+
is_expected.to be_a_twirp_request(count: 1..5)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "catches mismatches" do
|
46
|
+
expect {
|
47
|
+
is_expected.to be_a_twirp_request(GoodbyeRequest, name: "Bob")
|
48
|
+
}.to fail_with /request of type/
|
49
|
+
|
50
|
+
expect {
|
51
|
+
is_expected.to be_a_twirp_request(name: "nope")
|
52
|
+
}.to fail_with /to have name: "nope"/
|
53
|
+
|
54
|
+
expect {
|
55
|
+
is_expected.to be_a_twirp_request(name: /no/)
|
56
|
+
}.to fail_with /to have name: \/no\//
|
57
|
+
|
58
|
+
expect {
|
59
|
+
is_expected.to be_a_twirp_request(count: 1)
|
60
|
+
}.to fail_with /to have count: 1/
|
61
|
+
end
|
62
|
+
|
63
|
+
it "catches the erroneous attribute matches" do
|
64
|
+
expect {
|
65
|
+
is_expected.to be_a_twirp_request(namezzz: "Bob")
|
66
|
+
}.to raise_error(ArgumentError, /namezzz/)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "catches type mismatches" do
|
70
|
+
expect {
|
71
|
+
is_expected.to be_a_twirp_request(name: 123)
|
72
|
+
}.to raise_error(TypeError, /string field.*given Integer/)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
describe "be_a_twirp_response" do
|
2
|
+
subject { HelloResponse.new(**attrs) }
|
3
|
+
|
4
|
+
let(:attrs) { {} }
|
5
|
+
|
6
|
+
it { is_expected.to be_a_twirp_response }
|
7
|
+
|
8
|
+
it "catches non-twirp response" do
|
9
|
+
expect {
|
10
|
+
expect(Object).to be_a_twirp_response
|
11
|
+
}.to fail_with /Expected a Twirp response, found Object/
|
12
|
+
end
|
13
|
+
|
14
|
+
it "matches a specific response type" do
|
15
|
+
is_expected.to be_a_twirp_request(HelloResponse)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "catches type mismatches" do
|
19
|
+
expect {
|
20
|
+
is_expected.to be_a_twirp_request(GoodbyeResponse)
|
21
|
+
}.to fail_with /request of type GoodbyeResponse/
|
22
|
+
end
|
23
|
+
|
24
|
+
context "with attributes" do
|
25
|
+
let(:attrs) { { message: msg } }
|
26
|
+
let(:msg) { [ "Hello World" ] }
|
27
|
+
|
28
|
+
it { is_expected.to be_a_twirp_response(**attrs) }
|
29
|
+
|
30
|
+
it "supports regex matches" do
|
31
|
+
is_expected.to be_a_twirp_response(message: include(/Hello/))
|
32
|
+
end
|
33
|
+
|
34
|
+
it "catches mismatches" do
|
35
|
+
expect {
|
36
|
+
is_expected.to be_a_twirp_response(message: [ "" ])
|
37
|
+
}.to fail_with /to have message/
|
38
|
+
|
39
|
+
expect {
|
40
|
+
is_expected.to be_a_twirp_response(message: [ "Hello" ])
|
41
|
+
}.to fail_with /to have message/
|
42
|
+
end
|
43
|
+
|
44
|
+
it "catches the erroneous attributes" do
|
45
|
+
expect {
|
46
|
+
is_expected.to be_a_twirp_response(msg: [])
|
47
|
+
}.to raise_error(ArgumentError, /msg/)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "catches type mismatches" do
|
51
|
+
expect {
|
52
|
+
is_expected.to be_a_twirp_response(message: "Hello World")
|
53
|
+
}.to raise_error(ArgumentError, /Expected array/)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-twirp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Pepper
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-09-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: twirp
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec-expectations
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3'
|
13
41
|
- !ruby/object:Gem::Dependency
|
14
42
|
name: byebug
|
15
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -73,7 +101,16 @@ extensions: []
|
|
73
101
|
extra_rdoc_files: []
|
74
102
|
files:
|
75
103
|
- lib/rspec-twirp.rb
|
76
|
-
- lib/rspec
|
104
|
+
- lib/rspec/twirp.rb
|
105
|
+
- lib/rspec/twirp/client_response_matcher.rb
|
106
|
+
- lib/rspec/twirp/error_matcher.rb
|
107
|
+
- lib/rspec/twirp/request_matcher.rb
|
108
|
+
- lib/rspec/twirp/response_matcher.rb
|
109
|
+
- lib/rspec/twirp/version.rb
|
110
|
+
- spec/client_response_spec.rb
|
111
|
+
- spec/error_spec.rb
|
112
|
+
- spec/request_spec.rb
|
113
|
+
- spec/response_spec.rb
|
77
114
|
homepage: https://github.com/dpep/rspec-twirp_rb
|
78
115
|
licenses:
|
79
116
|
- MIT
|
@@ -96,5 +133,9 @@ requirements: []
|
|
96
133
|
rubygems_version: 3.1.6
|
97
134
|
signing_key:
|
98
135
|
specification_version: 4
|
99
|
-
summary:
|
100
|
-
test_files:
|
136
|
+
summary: Gem::Specification::RSpec::Twirp
|
137
|
+
test_files:
|
138
|
+
- spec/error_spec.rb
|
139
|
+
- spec/request_spec.rb
|
140
|
+
- spec/response_spec.rb
|
141
|
+
- spec/client_response_spec.rb
|
data/lib/rspec-twirp/version.rb
DELETED