rspec-twirp 0.2.0 → 0.3.1
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/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/error_matcher.rb +34 -12
- data/lib/rspec/twirp/message_matcher.rb +2 -61
- data/lib/rspec/twirp/response_matcher.rb +2 -20
- data/lib/rspec/twirp/version.rb +1 -1
- data/lib/rspec/twirp.rb +3 -48
- data/rspec-twirp.gemspec +23 -0
- data/service.rb +26 -0
- metadata +42 -21
- data/lib/rspec/twirp/helpers.rb +0 -16
- data/lib/rspec/twirp/make_request_matcher.rb +0 -169
- data/lib/rspec/twirp/mock_client.rb +0 -59
- data/lib/rspec/twirp/mock_connection.rb +0 -54
- data/spec/error_spec.rb +0 -116
- data/spec/make_request_spec.rb +0 -181
- data/spec/message_spec.rb +0 -83
- data/spec/mock_connection_spec.rb +0 -103
- data/spec/response_spec.rb +0 -124
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
|
+

|
4
|
+
[](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
|
@@ -1,43 +1,59 @@
|
|
1
1
|
RSpec::Matchers.define :be_a_twirp_error do |*matchers, **meta_matcher|
|
2
2
|
match do |actual|
|
3
|
-
@fail_msg = "Expected
|
3
|
+
@fail_msg = "Expected `#{actual}` to be a Twirp::Error, found: #{actual.class}"
|
4
4
|
return false unless actual.is_a?(Twirp::Error)
|
5
5
|
|
6
|
-
|
6
|
+
@expected = {}
|
7
|
+
@actual = {}
|
8
|
+
|
9
|
+
matched = matchers.all? do |matcher|
|
7
10
|
case matcher
|
8
11
|
when Symbol
|
9
12
|
# match code
|
13
|
+
@expected[:code] = matcher
|
14
|
+
@actual[:code] = actual.code
|
10
15
|
|
11
16
|
unless Twirp::Error.valid_code?(matcher)
|
12
17
|
raise ArgumentError, "invalid error code: #{matcher.inspect}"
|
13
18
|
end
|
14
19
|
|
15
|
-
@fail_msg = "Expected #{actual} to have code
|
16
|
-
|
20
|
+
@fail_msg = "Expected #{actual} to have code `#{matcher.inspect}`, found: #{actual.code.inspect}"
|
21
|
+
actual.code == matcher
|
17
22
|
when Integer
|
18
23
|
# match http status code
|
19
24
|
|
20
25
|
if code = Twirp::ERROR_CODES_TO_HTTP_STATUS.key(matcher)
|
21
|
-
@
|
22
|
-
|
26
|
+
@expected[:code] = code
|
27
|
+
@actual[:code] = actual.code
|
28
|
+
|
29
|
+
actual_status = Twirp::ERROR_CODES_TO_HTTP_STATUS[actual.code]
|
30
|
+
|
31
|
+
@fail_msg = "Expected #{actual} to have status #{matcher} / #{code.inspect}, found: #{actual_status} / #{actual.code.inspect}"
|
32
|
+
actual.code == code
|
23
33
|
else
|
24
34
|
raise ArgumentError, "invalid error status code: #{matcher}"
|
25
35
|
end
|
26
36
|
when Twirp::Error
|
27
37
|
# match instance
|
38
|
+
@expected = matcher.to_h
|
39
|
+
@actual = actual.to_h
|
28
40
|
|
29
41
|
@fail_msg = "Expected #{actual} to equal #{matcher}"
|
30
|
-
|
42
|
+
values_match?(matcher.to_h, actual.to_h)
|
31
43
|
else
|
32
44
|
# match msg
|
33
|
-
@
|
34
|
-
|
45
|
+
@expected[:msg] = matcher
|
46
|
+
@actual[:msg] = actual.msg
|
47
|
+
|
48
|
+
@fail_msg = "Expected #{actual} to have msg #{matcher.inspect}, found: #{actual.msg.inspect}"
|
49
|
+
values_match?(matcher, actual.msg)
|
35
50
|
end
|
36
51
|
end
|
37
52
|
|
38
53
|
# match meta
|
39
54
|
unless meta_matcher.empty?
|
40
|
-
@
|
55
|
+
@expected[:meta] = meta_matcher
|
56
|
+
@actual[:meta] = actual.meta
|
41
57
|
|
42
58
|
# sanity check...values must be Strings or Regexp
|
43
59
|
discrete_attrs = meta_matcher.transform_values do |attr|
|
@@ -46,10 +62,10 @@ RSpec::Matchers.define :be_a_twirp_error do |*matchers, **meta_matcher|
|
|
46
62
|
actual.send(:validate_meta, discrete_attrs)
|
47
63
|
|
48
64
|
@fail_msg = "Expected #{actual} to have meta: #{meta_matcher.inspect}, found #{actual.meta}"
|
49
|
-
|
65
|
+
matched &= values_match?(meta_matcher, actual.meta)
|
50
66
|
end
|
51
67
|
|
52
|
-
|
68
|
+
matched
|
53
69
|
end
|
54
70
|
|
55
71
|
description do
|
@@ -57,6 +73,12 @@ RSpec::Matchers.define :be_a_twirp_error do |*matchers, **meta_matcher|
|
|
57
73
|
end
|
58
74
|
|
59
75
|
failure_message { @fail_msg }
|
76
|
+
|
77
|
+
diffable
|
78
|
+
|
79
|
+
def expected
|
80
|
+
@expected
|
81
|
+
end
|
60
82
|
end
|
61
83
|
|
62
84
|
RSpec::Matchers.alias_matcher :a_twirp_error, :be_a_twirp_error
|
@@ -1,61 +1,2 @@
|
|
1
|
-
RSpec::Matchers.
|
2
|
-
|
3
|
-
# ensure type is a valid twirp message type
|
4
|
-
if type && !(type < Google::Protobuf::MessageExts)
|
5
|
-
raise TypeError, "Expected `type` to be a Google::Protobuf::MessageExts, found: #{type}"
|
6
|
-
end
|
7
|
-
|
8
|
-
@fail_msg = "Expected a Twirp message, found #{actual}"
|
9
|
-
return false unless actual.is_a?(Google::Protobuf::MessageExts)
|
10
|
-
|
11
|
-
# match expected message type
|
12
|
-
@fail_msg = "Expected a Twirp message of type #{type}, found #{actual.class}"
|
13
|
-
return false if type && actual.class != type
|
14
|
-
|
15
|
-
return true if attrs.empty?
|
16
|
-
|
17
|
-
# sanity check inputs
|
18
|
-
validate_types(attrs, actual.class)
|
19
|
-
|
20
|
-
# match attributes which are present
|
21
|
-
attrs.each do |attr_name, expected_attr|
|
22
|
-
actual_attr = actual.send(attr_name)
|
23
|
-
|
24
|
-
@fail_msg = "Expected #{actual} to have #{attr_name}: #{expected_attr.inspect}, found #{actual_attr}"
|
25
|
-
return false unless values_match?(expected_attr, actual_attr)
|
26
|
-
end
|
27
|
-
|
28
|
-
true
|
29
|
-
end
|
30
|
-
|
31
|
-
description do
|
32
|
-
type ? "a #{type} Twirp message" : "a Twirp message"
|
33
|
-
end
|
34
|
-
|
35
|
-
failure_message { @fail_msg }
|
36
|
-
|
37
|
-
private
|
38
|
-
|
39
|
-
def validate_types(attrs, klass)
|
40
|
-
# check names and types of attrs by constructing an actual proto object
|
41
|
-
discrete_attrs = attrs.transform_values do |attr|
|
42
|
-
case attr
|
43
|
-
when Regexp
|
44
|
-
attr.inspect
|
45
|
-
when Range
|
46
|
-
attr.first
|
47
|
-
when RSpec::Matchers::BuiltIn::BaseMatcher
|
48
|
-
# no good substitute, so skip attr and hope for the best
|
49
|
-
nil
|
50
|
-
else
|
51
|
-
attr
|
52
|
-
end
|
53
|
-
end.compact
|
54
|
-
|
55
|
-
klass.new(**discrete_attrs)
|
56
|
-
rescue Google::Protobuf::TypeError => e
|
57
|
-
raise TypeError, e.message
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
RSpec::Matchers.alias_matcher :a_twirp_message, :be_a_twirp_message
|
1
|
+
RSpec::Matchers.alias_matcher :be_a_twirp_message, :be_a_protobuf
|
2
|
+
RSpec::Matchers.alias_matcher :a_twirp_message, :a_protobuf
|
@@ -1,31 +1,13 @@
|
|
1
|
-
RSpec::Matchers.define :be_a_twirp_response do
|
1
|
+
RSpec::Matchers.define :be_a_twirp_response do |**attrs|
|
2
2
|
chain :with_error do |*matchers, **meta_matchers|
|
3
3
|
# code, msg, meta
|
4
4
|
@with_error = [ matchers, meta_matchers ]
|
5
5
|
end
|
6
6
|
|
7
7
|
match do |actual|
|
8
|
-
# ensure type is a valid twirp request type
|
9
|
-
if type
|
10
|
-
if type.is_a?(Google::Protobuf::MessageExts)
|
11
|
-
unless attrs.empty?
|
12
|
-
raise ArgumentError, "Expected Google::Protobuf::MessageExts instance or attrs, but not both"
|
13
|
-
end
|
14
|
-
|
15
|
-
attrs = type.to_h
|
16
|
-
type = type.class
|
17
|
-
elsif !(type < Google::Protobuf::MessageExts)
|
18
|
-
raise ArgumentError, "Expected `type` to be a Google::Protobuf::MessageExts, found: #{type}"
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
8
|
@fail_msg = "Expected a Twirp::ClientResp, found #{actual}"
|
23
9
|
return false unless actual.is_a?(Twirp::ClientResp)
|
24
10
|
|
25
|
-
# match expected response type
|
26
|
-
@fail_msg = "Expected a Twirp::ClientResp of type #{type}, found #{actual.data&.class}"
|
27
|
-
return false if type && actual.data&.class != type
|
28
|
-
|
29
11
|
if @with_error
|
30
12
|
unless attrs.empty?
|
31
13
|
raise ArgumentError, "match data attributes or error, but not both"
|
@@ -48,7 +30,7 @@ RSpec::Matchers.define :be_a_twirp_response do |type = nil, **attrs|
|
|
48
30
|
end
|
49
31
|
|
50
32
|
description do
|
51
|
-
|
33
|
+
"a Twirp response"
|
52
34
|
end
|
53
35
|
|
54
36
|
failure_message { @fail_msg }
|
data/lib/rspec/twirp/version.rb
CHANGED
data/lib/rspec/twirp.rb
CHANGED
@@ -1,54 +1,9 @@
|
|
1
1
|
require "google/protobuf"
|
2
|
-
require "rspec"
|
2
|
+
require "rspec/expectations"
|
3
|
+
require "rspec/protobuf"
|
3
4
|
require "twirp"
|
4
5
|
|
5
|
-
require "rspec/twirp/helpers"
|
6
|
-
require "rspec/twirp/make_request_matcher"
|
7
6
|
require "rspec/twirp/error_matcher"
|
8
7
|
require "rspec/twirp/message_matcher"
|
9
8
|
require "rspec/twirp/response_matcher"
|
10
|
-
|
11
|
-
module RSpec
|
12
|
-
module Twirp
|
13
|
-
extend RSpec::Mocks::ExampleMethods
|
14
|
-
|
15
|
-
# private
|
16
|
-
|
17
|
-
def generate_client_response(arg)
|
18
|
-
res = case arg
|
19
|
-
when Google::Protobuf::MessageExts, ::Twirp::Error
|
20
|
-
arg
|
21
|
-
when Class
|
22
|
-
if arg < Google::Protobuf::MessageExts
|
23
|
-
arg.new
|
24
|
-
else
|
25
|
-
raise TypeError, "Expected type `Google::Protobuf::MessageExts`, found: #{arg}"
|
26
|
-
end
|
27
|
-
when Symbol
|
28
|
-
if ::Twirp::Error.valid_code?(arg)
|
29
|
-
::Twirp::Error.new(arg, arg)
|
30
|
-
else
|
31
|
-
raise ArgumentError, "invalid error code: #{arg}"
|
32
|
-
end
|
33
|
-
when Integer
|
34
|
-
if code = ::Twirp::ERROR_CODES_TO_HTTP_STATUS.key(arg)
|
35
|
-
::Twirp::Error.new(code, code)
|
36
|
-
else
|
37
|
-
raise ArgumentError, "invalid error code: #{arg}"
|
38
|
-
end
|
39
|
-
else
|
40
|
-
raise NotImplementedError
|
41
|
-
end
|
42
|
-
|
43
|
-
if res.is_a?(Google::Protobuf::MessageExts)
|
44
|
-
::Twirp::ClientResp.new(res, nil)
|
45
|
-
else
|
46
|
-
::Twirp::ClientResp.new(nil, res)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
RSpec.configure do |config|
|
53
|
-
config.include(RSpec::Twirp::Helpers)
|
54
|
-
end
|
9
|
+
require "rspec/twirp/version"
|
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.
|
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
|
- - ">="
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec-protobuf
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.2'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.2'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: twirp
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,6 +94,20 @@ dependencies:
|
|
80
94
|
- - ">="
|
81
95
|
- !ruby/object:Gem::Version
|
82
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'
|
83
111
|
- !ruby/object:Gem::Dependency
|
84
112
|
name: simplecov
|
85
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,28 +122,26 @@ dependencies:
|
|
94
122
|
- - ">="
|
95
123
|
- !ruby/object:Gem::Version
|
96
124
|
version: '0'
|
97
|
-
description:
|
125
|
+
description: Twirp RSpec matchers
|
98
126
|
email:
|
99
127
|
executables: []
|
100
128
|
extensions: []
|
101
129
|
extra_rdoc_files: []
|
102
130
|
files:
|
131
|
+
- CHANGELOG.md
|
132
|
+
- Gemfile
|
133
|
+
- Gemfile.lock
|
134
|
+
- LICENSE.txt
|
135
|
+
- README.md
|
103
136
|
- lib/rspec-twirp.rb
|
104
137
|
- lib/rspec/twirp.rb
|
105
138
|
- lib/rspec/twirp/error_matcher.rb
|
106
|
-
- lib/rspec/twirp/helpers.rb
|
107
|
-
- lib/rspec/twirp/make_request_matcher.rb
|
108
139
|
- lib/rspec/twirp/message_matcher.rb
|
109
|
-
- lib/rspec/twirp/mock_client.rb
|
110
|
-
- lib/rspec/twirp/mock_connection.rb
|
111
140
|
- lib/rspec/twirp/response_matcher.rb
|
112
141
|
- lib/rspec/twirp/version.rb
|
113
|
-
-
|
114
|
-
-
|
115
|
-
|
116
|
-
- spec/mock_connection_spec.rb
|
117
|
-
- spec/response_spec.rb
|
118
|
-
homepage: https://github.com/dpep/rspec-twirp_rb
|
142
|
+
- rspec-twirp.gemspec
|
143
|
+
- service.rb
|
144
|
+
homepage: https://github.com/dpep/rspec-twirp
|
119
145
|
licenses:
|
120
146
|
- MIT
|
121
147
|
metadata: {}
|
@@ -137,10 +163,5 @@ requirements: []
|
|
137
163
|
rubygems_version: 3.3.7
|
138
164
|
signing_key:
|
139
165
|
specification_version: 4
|
140
|
-
summary:
|
141
|
-
test_files:
|
142
|
-
- spec/error_spec.rb
|
143
|
-
- spec/make_request_spec.rb
|
144
|
-
- spec/message_spec.rb
|
145
|
-
- spec/mock_connection_spec.rb
|
146
|
-
- spec/response_spec.rb
|
166
|
+
summary: RSpec::Twirp
|
167
|
+
test_files: []
|
data/lib/rspec/twirp/helpers.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
require "rspec/twirp/mock_client"
|
2
|
-
require "rspec/twirp/mock_connection"
|
3
|
-
|
4
|
-
module RSpec
|
5
|
-
module Twirp
|
6
|
-
module Helpers
|
7
|
-
def mock_twirp_connection(...)
|
8
|
-
RSpec::Twirp.mock_connection(...)
|
9
|
-
end
|
10
|
-
|
11
|
-
def mock_twirp_client(...)
|
12
|
-
RSpec::Twirp.mock_client(...)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|