rspec-twirp 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +34 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +81 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/lib/rspec/twirp/version.rb +1 -1
- data/lib/rspec/twirp.rb +1 -1
- data/rspec-twirp.gemspec +23 -0
- data/service.rb +26 -0
- metadata +27 -12
- data/spec/error_spec.rb +0 -159
- data/spec/message_spec.rb +0 -69
- data/spec/response_spec.rb +0 -89
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a706ac42abbda25e9b6928b76a21b328fcd42809228d072e5a235e18f824970
|
4
|
+
data.tar.gz: a9792cfc6fb182a13e368a73755de2680a83d2884d258b68f1b4f97050a4cc74
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80b17dd294a3b9a003fd6ee9976caefa4fa8a79191aecc6589f2f04f547853111cfbeba1c2f12ce50709b323740ca6554e07cbb5454bec4d8178c0ce555ca891
|
7
|
+
data.tar.gz: b47c5786903745444d2eb92bfdc08f1c45b2c531d42b23a89179a5c3a0b77bbcc4462fe170e21322379eb1b4028728f270e358ef079b9d5a70ab10eac194ef2b
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
### v0.3.1 (2022-12-15)
|
2
|
+
- simplify dependencies
|
3
|
+
- action permissions
|
4
|
+
- dependabot automation
|
5
|
+
- lockfile
|
6
|
+
- builds
|
7
|
+
|
8
|
+
### v0.3.0 (2022-11-16)
|
9
|
+
- diffable error matching
|
10
|
+
- extract request stubbing
|
11
|
+
|
12
|
+
### v0.2.0 (2022-10-06)
|
13
|
+
- ruby 3 fixes
|
14
|
+
- mock_client
|
15
|
+
- improved make_request spec
|
16
|
+
- upgrade mock connection
|
17
|
+
- inline request matcher
|
18
|
+
- request matcher and_return
|
19
|
+
- make request matcher
|
20
|
+
- mock_twirp_connection
|
21
|
+
- twirp message matcher simplification
|
22
|
+
|
23
|
+
### v0.1.0 (2022-09-24)
|
24
|
+
- Update README.md
|
25
|
+
- client response matcher
|
26
|
+
- improved fail messages
|
27
|
+
- response matcher
|
28
|
+
- error matcher
|
29
|
+
- improve regex match
|
30
|
+
- be_a_twirp_request
|
31
|
+
|
32
|
+
### v0.0.1 (2022-05-24)
|
33
|
+
- init
|
34
|
+
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rspec-twirp (0.3.0)
|
5
|
+
google-protobuf (>= 3)
|
6
|
+
rspec-expectations (>= 3)
|
7
|
+
rspec-protobuf (>= 0.2)
|
8
|
+
twirp (>= 1)
|
9
|
+
|
10
|
+
GEM
|
11
|
+
remote: https://rubygems.org/
|
12
|
+
specs:
|
13
|
+
byebug (11.1.3)
|
14
|
+
codecov (0.6.0)
|
15
|
+
simplecov (>= 0.15, < 0.22)
|
16
|
+
diff-lcs (1.5.0)
|
17
|
+
docile (1.4.0)
|
18
|
+
faraday (1.10.2)
|
19
|
+
faraday-em_http (~> 1.0)
|
20
|
+
faraday-em_synchrony (~> 1.0)
|
21
|
+
faraday-excon (~> 1.1)
|
22
|
+
faraday-httpclient (~> 1.0)
|
23
|
+
faraday-multipart (~> 1.0)
|
24
|
+
faraday-net_http (~> 1.0)
|
25
|
+
faraday-net_http_persistent (~> 1.0)
|
26
|
+
faraday-patron (~> 1.0)
|
27
|
+
faraday-rack (~> 1.0)
|
28
|
+
faraday-retry (~> 1.0)
|
29
|
+
ruby2_keywords (>= 0.0.4)
|
30
|
+
faraday-em_http (1.0.0)
|
31
|
+
faraday-em_synchrony (1.0.0)
|
32
|
+
faraday-excon (1.1.0)
|
33
|
+
faraday-httpclient (1.0.1)
|
34
|
+
faraday-multipart (1.0.4)
|
35
|
+
multipart-post (~> 2)
|
36
|
+
faraday-net_http (1.0.1)
|
37
|
+
faraday-net_http_persistent (1.2.0)
|
38
|
+
faraday-patron (1.0.0)
|
39
|
+
faraday-rack (1.0.0)
|
40
|
+
faraday-retry (1.0.3)
|
41
|
+
google-protobuf (3.21.12)
|
42
|
+
multipart-post (2.2.3)
|
43
|
+
rspec (3.12.0)
|
44
|
+
rspec-core (~> 3.12.0)
|
45
|
+
rspec-expectations (~> 3.12.0)
|
46
|
+
rspec-mocks (~> 3.12.0)
|
47
|
+
rspec-core (3.12.0)
|
48
|
+
rspec-support (~> 3.12.0)
|
49
|
+
rspec-expectations (3.12.0)
|
50
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
51
|
+
rspec-support (~> 3.12.0)
|
52
|
+
rspec-mocks (3.12.1)
|
53
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
54
|
+
rspec-support (~> 3.12.0)
|
55
|
+
rspec-protobuf (0.2.2)
|
56
|
+
google-protobuf (>= 3)
|
57
|
+
rspec-expectations (>= 3)
|
58
|
+
rspec-support (3.12.0)
|
59
|
+
ruby2_keywords (0.0.5)
|
60
|
+
simplecov (0.21.2)
|
61
|
+
docile (~> 1.1)
|
62
|
+
simplecov-html (~> 0.11)
|
63
|
+
simplecov_json_formatter (~> 0.1)
|
64
|
+
simplecov-html (0.12.3)
|
65
|
+
simplecov_json_formatter (0.1.4)
|
66
|
+
twirp (1.9.0)
|
67
|
+
faraday (< 2)
|
68
|
+
google-protobuf (~> 3.0, >= 3.7.0)
|
69
|
+
|
70
|
+
PLATFORMS
|
71
|
+
ruby
|
72
|
+
|
73
|
+
DEPENDENCIES
|
74
|
+
byebug
|
75
|
+
codecov
|
76
|
+
rspec (>= 3)
|
77
|
+
rspec-twirp!
|
78
|
+
simplecov
|
79
|
+
|
80
|
+
BUNDLED WITH
|
81
|
+
2.3.9
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 Daniel Pepper
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
RSpec::Twirp
|
2
|
+
======
|
3
|
+
![Gem](https://img.shields.io/gem/dt/rspec-twirp?style=plastic)
|
4
|
+
[![codecov](https://codecov.io/gh/dpep/rspec-twirp/branch/main/graph/badge.svg)](https://codecov.io/gh/dpep/rspec-twirp)
|
5
|
+
|
6
|
+
Twirp RSpec matchers.
|
7
|
+
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
require "rspec/twirp"
|
11
|
+
|
12
|
+
it "matches Twirp responses" do
|
13
|
+
is_expected.to be_a_twirp_response
|
14
|
+
is_expected.to be_a_twirp_response(count: 3)
|
15
|
+
is_expected.to be_a_twirp_response.with_error(:not_found)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "matches Twirp messages" do
|
19
|
+
is_expected.to be_a_twirp_message
|
20
|
+
is_expected.to be_a_twirp_message(MyRequest)
|
21
|
+
is_expected.to be_a_twirp_message(name: /^B/)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "matches Twirp errors" do
|
25
|
+
is_expected.to be_a_twirp_error
|
26
|
+
is_expected.to be_a_twirp_error(:internal)
|
27
|
+
end
|
28
|
+
```
|
29
|
+
|
30
|
+
To stub Twirp requests, see [webmock-twirp](https://github.com/dpep/webmock-twirp).
|
31
|
+
|
32
|
+
|
33
|
+
----
|
34
|
+
## Contributing
|
35
|
+
|
36
|
+
Yes please :)
|
37
|
+
|
38
|
+
1. Fork it
|
39
|
+
1. Create your feature branch (`git checkout -b my-feature`)
|
40
|
+
1. Ensure the tests pass (`bundle exec rspec`)
|
41
|
+
1. Commit your changes (`git commit -am 'awesome new feature'`)
|
42
|
+
1. Push your branch (`git push origin my-feature`)
|
43
|
+
1. Create a Pull Request
|
data/lib/rspec/twirp/version.rb
CHANGED
data/lib/rspec/twirp.rb
CHANGED
data/rspec-twirp.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require_relative "lib/rspec/twirp/version"
|
2
|
+
package = RSpec::Twirp
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.authors = ["Daniel Pepper"]
|
6
|
+
s.description = "Twirp RSpec matchers"
|
7
|
+
s.files = `git ls-files * ':!:spec'`.split("\n")
|
8
|
+
s.homepage = "https://github.com/dpep/rspec-twirp"
|
9
|
+
s.license = "MIT"
|
10
|
+
s.name = File.basename(__FILE__).split(".")[0]
|
11
|
+
s.summary = package.to_s
|
12
|
+
s.version = package.const_get "VERSION"
|
13
|
+
|
14
|
+
s.add_dependency "google-protobuf", ">= 3"
|
15
|
+
s.add_dependency "rspec-expectations", ">= 3"
|
16
|
+
s.add_dependency "rspec-protobuf", ">= 0.2"
|
17
|
+
s.add_dependency "twirp", ">= 1"
|
18
|
+
|
19
|
+
s.add_development_dependency "byebug"
|
20
|
+
s.add_development_dependency "codecov"
|
21
|
+
s.add_development_dependency "rspec", ">= 3"
|
22
|
+
s.add_development_dependency "simplecov"
|
23
|
+
end
|
data/service.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "google/protobuf"
|
4
|
+
require "rack"
|
5
|
+
require "twirp"
|
6
|
+
require "webrick"
|
7
|
+
require "./spec/support/hello_world"
|
8
|
+
|
9
|
+
server = WEBrick::HTTPServer.new(Port: 3000)
|
10
|
+
|
11
|
+
handler = HelloWorldHandler.new
|
12
|
+
service = HelloWorldService.new(handler)
|
13
|
+
path_prefix = "/twirp/" + service.full_name
|
14
|
+
server.mount path_prefix, Rack::Handler::WEBrick, service
|
15
|
+
|
16
|
+
handler = GoodbyeHandler.new
|
17
|
+
service = GoodbyeService.new(handler)
|
18
|
+
path_prefix = "/twirp/" + service.full_name
|
19
|
+
server.mount path_prefix, Rack::Handler::WEBrick, service
|
20
|
+
|
21
|
+
server.start
|
22
|
+
|
23
|
+
# client = HelloWorldClient.new("http://localhost:3000/twirp")
|
24
|
+
# client = GoodbyeClient.new("http://localhost:3000/twirp")
|
25
|
+
# resp = client.hello(name: "World")
|
26
|
+
# puts resp.data
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-twirp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
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-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: google-protobuf
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name: rspec
|
28
|
+
name: rspec-expectations
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: simplecov
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,16 +128,20 @@ executables: []
|
|
114
128
|
extensions: []
|
115
129
|
extra_rdoc_files: []
|
116
130
|
files:
|
131
|
+
- CHANGELOG.md
|
132
|
+
- Gemfile
|
133
|
+
- Gemfile.lock
|
134
|
+
- LICENSE.txt
|
135
|
+
- README.md
|
117
136
|
- lib/rspec-twirp.rb
|
118
137
|
- lib/rspec/twirp.rb
|
119
138
|
- lib/rspec/twirp/error_matcher.rb
|
120
139
|
- lib/rspec/twirp/message_matcher.rb
|
121
140
|
- lib/rspec/twirp/response_matcher.rb
|
122
141
|
- lib/rspec/twirp/version.rb
|
123
|
-
-
|
124
|
-
-
|
125
|
-
|
126
|
-
homepage: https://github.com/dpep/rspec-twirp_rb
|
142
|
+
- rspec-twirp.gemspec
|
143
|
+
- service.rb
|
144
|
+
homepage: https://github.com/dpep/rspec-twirp
|
127
145
|
licenses:
|
128
146
|
- MIT
|
129
147
|
metadata: {}
|
@@ -145,8 +163,5 @@ requirements: []
|
|
145
163
|
rubygems_version: 3.3.7
|
146
164
|
signing_key:
|
147
165
|
specification_version: 4
|
148
|
-
summary:
|
149
|
-
test_files:
|
150
|
-
- spec/error_spec.rb
|
151
|
-
- spec/message_spec.rb
|
152
|
-
- spec/response_spec.rb
|
166
|
+
summary: RSpec::Twirp
|
167
|
+
test_files: []
|
data/spec/error_spec.rb
DELETED
@@ -1,159 +0,0 @@
|
|
1
|
-
describe "be_a_twirp_error" do
|
2
|
-
subject(:error) { 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 "is composable" do
|
11
|
-
expect(e: error).to include(e: a_twirp_error)
|
12
|
-
end
|
13
|
-
|
14
|
-
it "catches type mismatches" do
|
15
|
-
expect {
|
16
|
-
expect(Object).to be_a_twirp_error
|
17
|
-
}.to fail_with /to be a Twirp::Error/
|
18
|
-
end
|
19
|
-
|
20
|
-
describe "status matches" do
|
21
|
-
it { is_expected.to be_a_twirp_error(404) }
|
22
|
-
|
23
|
-
it "catches mismatches" do
|
24
|
-
expect {
|
25
|
-
is_expected.to be_a_twirp_error(400)
|
26
|
-
}.to fail_including(
|
27
|
-
"to have status 400",
|
28
|
-
"found: 404",
|
29
|
-
|
30
|
-
# diff
|
31
|
-
"-:code => :invalid_argument,",
|
32
|
-
"+:code => :not_found,",
|
33
|
-
)
|
34
|
-
end
|
35
|
-
|
36
|
-
it "catches erroneous codes" do
|
37
|
-
expect {
|
38
|
-
is_expected.to be_a_twirp_error(123)
|
39
|
-
}.to raise_error(ArgumentError, /invalid error/)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe "code matches" do
|
44
|
-
it { is_expected.to be_a_twirp_error(:not_found) }
|
45
|
-
|
46
|
-
it "catches mismatches" do
|
47
|
-
expect {
|
48
|
-
is_expected.to be_a_twirp_error(:unknown)
|
49
|
-
}.to fail_including(
|
50
|
-
"to have code `:unknown`",
|
51
|
-
"found: :not_found",
|
52
|
-
|
53
|
-
# diff
|
54
|
-
"-:code => :unknown,",
|
55
|
-
"+:code => :not_found,",
|
56
|
-
)
|
57
|
-
end
|
58
|
-
|
59
|
-
it "catches erroneous codes" do
|
60
|
-
expect {
|
61
|
-
is_expected.to be_a_twirp_error(:not_a_valid_code)
|
62
|
-
}.to raise_error(ArgumentError, /:not_a_valid_code/)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
describe "msg matches" do
|
67
|
-
it { is_expected.to be_a_twirp_error("Not Found") }
|
68
|
-
|
69
|
-
it "supports Regex matches" do
|
70
|
-
is_expected.to be_a_twirp_error(/Not/)
|
71
|
-
end
|
72
|
-
|
73
|
-
it "catches mismatches" do
|
74
|
-
expect {
|
75
|
-
is_expected.to be_a_twirp_error("Not")
|
76
|
-
}.to fail_including(
|
77
|
-
'to have msg "Not"',
|
78
|
-
'found: "Not Found"',
|
79
|
-
|
80
|
-
# diff
|
81
|
-
'-:msg => "Not",',
|
82
|
-
'+:msg => "Not Found",',
|
83
|
-
)
|
84
|
-
|
85
|
-
expect {
|
86
|
-
is_expected.to be_a_twirp_error(/Nope/)
|
87
|
-
}.to fail_including(
|
88
|
-
# diff
|
89
|
-
'-:msg => /Nope/,',
|
90
|
-
'+:msg => "Not Found",',
|
91
|
-
)
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
describe "meta matches" do
|
96
|
-
it { is_expected.to be_a_twirp_error(is_meta: "true") }
|
97
|
-
it { is_expected.to be_a_twirp_error(is_meta: /^t/) }
|
98
|
-
|
99
|
-
it "catches mismatches" do
|
100
|
-
expect {
|
101
|
-
is_expected.to be_a_twirp_error(is_meta: "false")
|
102
|
-
}.to fail_including(
|
103
|
-
"to have meta",
|
104
|
-
|
105
|
-
# diff
|
106
|
-
'-:meta => {:is_meta=>"false"},',
|
107
|
-
'+:meta => {:is_meta=>"true"},',
|
108
|
-
)
|
109
|
-
|
110
|
-
expect {
|
111
|
-
is_expected.to be_a_twirp_error(not_meta: "")
|
112
|
-
}.to fail_with /to have meta.*not_meta/
|
113
|
-
end
|
114
|
-
|
115
|
-
it "catches type errors" do
|
116
|
-
expect {
|
117
|
-
is_expected.to be_a_twirp_error(is_meta: true)
|
118
|
-
}.to raise_error(ArgumentError, /meta values must be Strings/)
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
describe "instance matches" do
|
123
|
-
it "matches similar looking instances" do
|
124
|
-
error = Twirp::Error.new(code, msg, meta)
|
125
|
-
is_expected.to be_a_twirp_error(error)
|
126
|
-
end
|
127
|
-
|
128
|
-
it "catches mismatches" do
|
129
|
-
# no meta
|
130
|
-
expect {
|
131
|
-
is_expected.to be_a_twirp_error(Twirp::Error.not_found("Not Found"))
|
132
|
-
}.to fail
|
133
|
-
|
134
|
-
expect {
|
135
|
-
is_expected.to be_a_twirp_error(Twirp::Error.internal("boom"))
|
136
|
-
}.to fail
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
describe "multi matches" do
|
141
|
-
it { is_expected.to be_a_twirp_error(:not_found, "Not Found") }
|
142
|
-
it { is_expected.to be_a_twirp_error(:not_found, /Not/) }
|
143
|
-
it { is_expected.to be_a_twirp_error(:not_found, is_meta: "true") }
|
144
|
-
|
145
|
-
it "catches mismatches" do
|
146
|
-
expect {
|
147
|
-
is_expected.to be_a_twirp_error(:unknown, "Not Found")
|
148
|
-
}.to fail_with /unknown/
|
149
|
-
|
150
|
-
expect {
|
151
|
-
is_expected.to be_a_twirp_error(:not_found, "Nope")
|
152
|
-
}.to fail_with /Nope/
|
153
|
-
|
154
|
-
expect {
|
155
|
-
is_expected.to be_a_twirp_error(:not_found, is_meta: "false")
|
156
|
-
}.to fail_with /false/
|
157
|
-
end
|
158
|
-
end
|
159
|
-
end
|
data/spec/message_spec.rb
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
describe "be_a_twirp_message" do
|
2
|
-
subject(:request) { HelloRequest.new(**attrs) }
|
3
|
-
|
4
|
-
let(:attrs) { {} }
|
5
|
-
|
6
|
-
it { is_expected.to be_a_twirp_message }
|
7
|
-
|
8
|
-
it "works with responses also" do
|
9
|
-
expect(HelloResponse.new).to be_a_twirp_message
|
10
|
-
end
|
11
|
-
|
12
|
-
it "supports compound matchers" do
|
13
|
-
expect([ request ]).to include(a_twirp_message)
|
14
|
-
end
|
15
|
-
|
16
|
-
it "does not match non-twirp subjects" do
|
17
|
-
expect(Object).not_to be_a_twirp_message
|
18
|
-
end
|
19
|
-
|
20
|
-
it "matches a specific message type" do
|
21
|
-
is_expected.to be_a_twirp_message(HelloRequest)
|
22
|
-
end
|
23
|
-
|
24
|
-
it "catches type mismatches" do
|
25
|
-
is_expected.not_to be_a_twirp_message(GoodbyeRequest)
|
26
|
-
end
|
27
|
-
|
28
|
-
it "catches erroneous message types" do
|
29
|
-
expect {
|
30
|
-
is_expected.to be_a_twirp_message(Object)
|
31
|
-
}.to raise_error(TypeError, /Object/)
|
32
|
-
end
|
33
|
-
|
34
|
-
context "with attributes" do
|
35
|
-
let(:attrs) { { name: "Bob", count: 3 } }
|
36
|
-
|
37
|
-
it "can match attributes" do
|
38
|
-
is_expected.to be_a_twirp_message(HelloRequest, **attrs)
|
39
|
-
end
|
40
|
-
|
41
|
-
it "supports regex matches" do
|
42
|
-
is_expected.to be_a_twirp_message(name: /^B/)
|
43
|
-
end
|
44
|
-
|
45
|
-
it "supports range matches" do
|
46
|
-
is_expected.to be_a_twirp_message(count: 1..5)
|
47
|
-
end
|
48
|
-
|
49
|
-
it "catches mismatches" do
|
50
|
-
expect {
|
51
|
-
is_expected.to be_a_twirp_message(GoodbyeRequest, name: "Bob")
|
52
|
-
}.to fail_with /message of type/
|
53
|
-
|
54
|
-
is_expected.not_to be_a_twirp_message(name: "nope")
|
55
|
-
|
56
|
-
is_expected.not_to be_a_twirp_message(name: /no/)
|
57
|
-
|
58
|
-
is_expected.not_to be_a_twirp_message(count: 1)
|
59
|
-
end
|
60
|
-
|
61
|
-
it "catches erroneous attribute matches" do
|
62
|
-
is_expected.not_to be_a_twirp_message(namezzz: "Bob")
|
63
|
-
end
|
64
|
-
|
65
|
-
it "handles type mismatches" do
|
66
|
-
is_expected.not_to be_a_twirp_message(name: 123)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
data/spec/response_spec.rb
DELETED
@@ -1,89 +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 "handles non-twirp response" do
|
10
|
-
expect(Object).not_to be_a_twirp_response
|
11
|
-
end
|
12
|
-
|
13
|
-
context "with attributes" do
|
14
|
-
let(:response) { GoodbyeResponse.new(**attrs) }
|
15
|
-
let(:attrs) { { message: "bye", name: "Bob" } }
|
16
|
-
|
17
|
-
it "can match attributes" do
|
18
|
-
is_expected.to be_a_twirp_response(**attrs)
|
19
|
-
end
|
20
|
-
|
21
|
-
it "supports regex matches" do
|
22
|
-
is_expected.to be_a_twirp_response(name: /^B/)
|
23
|
-
end
|
24
|
-
|
25
|
-
it "catches mismatches" do
|
26
|
-
expect {
|
27
|
-
is_expected.to be_a_twirp_response(name: "nope")
|
28
|
-
}.to fail_including(
|
29
|
-
'-:name => "nope",',
|
30
|
-
'+:name => "Bob",',
|
31
|
-
)
|
32
|
-
|
33
|
-
expect {
|
34
|
-
is_expected.to be_a_twirp_response(name: /no/)
|
35
|
-
}.to fail_including(
|
36
|
-
'-:name => /no/,',
|
37
|
-
'+:name => "Bob",',
|
38
|
-
)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
context "with error" do
|
44
|
-
subject { Twirp::ClientResp.new(nil, error) }
|
45
|
-
|
46
|
-
let(:error) { Twirp::Error.new(code, msg, meta) }
|
47
|
-
let(:code) { :not_found }
|
48
|
-
let(:msg) { "Not Found" }
|
49
|
-
let(:meta) { { is_meta: "true" } }
|
50
|
-
|
51
|
-
it { is_expected.to be_a_twirp_response.with_error }
|
52
|
-
it { is_expected.to be_a_twirp_response.with_error(code) }
|
53
|
-
it { is_expected.to be_a_twirp_response.with_error(msg) }
|
54
|
-
it { is_expected.to be_a_twirp_response.with_error(**meta) }
|
55
|
-
it { is_expected.to be_a_twirp_response.with_error(/Not/) }
|
56
|
-
|
57
|
-
it "catches mismatches" do
|
58
|
-
expect {
|
59
|
-
is_expected.to be_a_twirp_response.with_error(:internal)
|
60
|
-
}.to fail_with /to have code `:internal`/
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
context "with neither response nor error" do
|
65
|
-
subject { Twirp::ClientResp.new(nil, nil) }
|
66
|
-
|
67
|
-
it "fails the response match" do
|
68
|
-
expect {
|
69
|
-
is_expected.to be_a_twirp_response
|
70
|
-
}.to fail_with /to have data/
|
71
|
-
end
|
72
|
-
|
73
|
-
it "fails the error match" do
|
74
|
-
expect {
|
75
|
-
is_expected.to be_a_twirp_response.with_error
|
76
|
-
}.to fail_with /to have an error/
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
context "with both response and error" do
|
81
|
-
subject { Twirp::ClientResp.new(GoodbyeResponse.new, Twirp::Error.not_found("Not Found")) }
|
82
|
-
|
83
|
-
it "does not permit both attr and error matching" do
|
84
|
-
expect {
|
85
|
-
is_expected.to be_a_twirp_response(name: "Bob").with_error
|
86
|
-
}.to raise_error(ArgumentError, /but not both/)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|