twirp_rails 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -1
- data/Gemfile.lock +1 -1
- data/README.md +28 -1
- data/lib/twirp_rails/generators/twirp/twirp_generator.rb +1 -1
- data/lib/twirp_rails/generators/twirp/twirp_rspec_generator.rb +25 -0
- data/lib/twirp_rails/version.rb +1 -1
- data/lib/twirp_rails.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a92255521f3ac2df3ae47a597caa01c1815a03c60a5ab0b7e8d459162a32dd9
|
4
|
+
data.tar.gz: 7c6bc605775f5bbf1fafa1292bd116be996ab536a602335bc83c0b43cdedf529
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b515cb51dd041ded6089f55fde625cc8b52c23b3526179a102ef4145e6c12f38953c052cdf5fbc987fe0c177acc938fc959128d8f1cab5dc87ef8ac6800118fb
|
7
|
+
data.tar.gz: 12b4c238b0ce754a205b84d49f00fb3edef603fe0152a49bc08d6b565886f59cc46932c6808824bbd9e678aeb00e22b45197ef1757b394de22827c2c36104ee2
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
5
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
+
## 0.1.7 - 2020-02-11
|
8
|
+
|
9
|
+
### Changed
|
10
|
+
- initial inject required rspec helper required code moved to the ```twirp:rspec``` generator.
|
11
|
+
|
7
12
|
## 0.1.6 - 2020-02-11
|
8
13
|
|
9
14
|
### Added
|
@@ -27,7 +32,7 @@ config.include TwirpRails::RSpec::Helper, type: :rpc, file_path: %r{spec/rpc}
|
|
27
32
|
describe TeamsHandler do
|
28
33
|
let!(:team) { create :team }
|
29
34
|
|
30
|
-
context '
|
35
|
+
context '#get' do
|
31
36
|
rpc { [:get, id: team.id] }
|
32
37
|
|
33
38
|
it { should match(team: team.to_twirp.symbolize_keys) }
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -39,6 +39,7 @@ and run
|
|
39
39
|
|
40
40
|
```sh
|
41
41
|
rails g twirp people
|
42
|
+
rails g twirp:rspec # run only once, if you want to use rspec rpc helper
|
42
43
|
```
|
43
44
|
|
44
45
|
This command will add the route and generate ```lib/twirp/people_pb.rb```, ```lib/twirp/people_twirp.rb```,
|
@@ -59,7 +60,7 @@ end
|
|
59
60
|
Modify ```app/rpc/people_handler.rb```:
|
60
61
|
```ruby
|
61
62
|
def get_name(req, _env)
|
62
|
-
|
63
|
+
{ name: "Name of #{req.uid}" }
|
63
64
|
end
|
64
65
|
```
|
65
66
|
|
@@ -74,6 +75,32 @@ PeopleClient.new('http://localhost:3000').get_name(GetNameRequest.new uid: '1').
|
|
74
75
|
=> "Name of 1"
|
75
76
|
```
|
76
77
|
|
78
|
+
### Test your service with rspec
|
79
|
+
|
80
|
+
If you use RSpec, twirp generator creates handler spec file with all service methods test templates.
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
describe TeamsHandler do
|
84
|
+
|
85
|
+
context '#get' do
|
86
|
+
rpc { [:get, id: team.id] }
|
87
|
+
|
88
|
+
it { should match(team: team.to_twirp) }
|
89
|
+
end
|
90
|
+
end
|
91
|
+
```
|
92
|
+
|
93
|
+
To include required spec helpers add this code to ```rails_helper.rb```
|
94
|
+
```ruby
|
95
|
+
require 'twirp_rails/rspec/helper'
|
96
|
+
|
97
|
+
RSpec.configure do |config|
|
98
|
+
config.include RSpec::Rails::RequestExampleGroup, type: :request, file_path: %r{spec/api}
|
99
|
+
end
|
100
|
+
```
|
101
|
+
|
102
|
+
or run ```rails g twirp:rspec``` to do it automatically.
|
103
|
+
|
77
104
|
## Development
|
78
105
|
|
79
106
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module Twirp
|
4
|
+
class RspecGenerator < Rails::Generators::Base
|
5
|
+
desc 'Install twirp rspec helpers into rails_helper.rb'
|
6
|
+
def inject_rspec_helper
|
7
|
+
in_root do
|
8
|
+
unless File.exist?('spec/rails_helper.rb')
|
9
|
+
log :inject_rspec, 'spec/rails_helper.rb is not found'
|
10
|
+
return
|
11
|
+
end
|
12
|
+
|
13
|
+
require_sentinel = %r{require 'rspec/rails'\s*\n}m
|
14
|
+
include_sentinel = /RSpec\.configure\s*do\s*\|config\|\s*\n/m
|
15
|
+
|
16
|
+
inject_into_file 'spec/rails_helper.rb',
|
17
|
+
"require 'twirp_rails/rspec/helper'\n",
|
18
|
+
after: require_sentinel, verbose: true, force: false
|
19
|
+
inject_into_file 'spec/rails_helper.rb',
|
20
|
+
" config.include TwirpRails::RSpec::Helper, type: :rpc, file_path: %r{spec/rpc}\n",
|
21
|
+
after: include_sentinel, verbose: true, force: false
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/twirp_rails/version.rb
CHANGED
data/lib/twirp_rails.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twirp_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexandr Zimin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-02-
|
11
|
+
date: 2020-02-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: twirp
|
@@ -144,6 +144,7 @@ files:
|
|
144
144
|
- lib/twirp_rails/engine.rb
|
145
145
|
- lib/twirp_rails/generators/twirp/USAGE
|
146
146
|
- lib/twirp_rails/generators/twirp/twirp_generator.rb
|
147
|
+
- lib/twirp_rails/generators/twirp/twirp_rspec_generator.rb
|
147
148
|
- lib/twirp_rails/routes.rb
|
148
149
|
- lib/twirp_rails/rspec/helper.rb
|
149
150
|
- lib/twirp_rails/twirp.rb
|