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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ebf7858e259ac7b44fe27db5912c15093db8e4c056278293c7a505f0ce3ba0d9
4
- data.tar.gz: f52465a773645cb16aa65dbf7b32db9de95f804f1903230d265fd31fcd55ec68
3
+ metadata.gz: 2a92255521f3ac2df3ae47a597caa01c1815a03c60a5ab0b7e8d459162a32dd9
4
+ data.tar.gz: 7c6bc605775f5bbf1fafa1292bd116be996ab536a602335bc83c0b43cdedf529
5
5
  SHA512:
6
- metadata.gz: a6c7dc0ab5860f6c203429536276f51ea8bbc31bc1e243f030c7fa78d6c5a547381fafd66fa4d00b1c2f6681e99f8e5f5cdbf8cf61e4ec22c38c0735f3c64abe
7
- data.tar.gz: dd9967d8189ad815a01e8aa82dcc612e245fa9041a5e5ca2711b2cf28298bdd39d192f5bf8c23ce49d1a6aa8cddfbeab85e88552668e5aeb324d033d9116118c
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 '.get' do
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- twirp_rails (0.1.6)
4
+ twirp_rails (0.1.7)
5
5
  railties (~> 6.0)
6
6
  twirp (~> 1)
7
7
 
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
- GetNameResponse.new name: "Name of #{req.uid}"
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.
@@ -43,7 +43,7 @@ class TwirpGenerator < Rails::Generators::NamedBase
43
43
 
44
44
  proto_files.each do |file|
45
45
  gen_swagger = gen_swagger? && file =~ %r{/#{file_name}\.proto$}
46
- pp [gen_swagger, file]
46
+
47
47
  cmd = protoc_cmd(file, gen_swagger: gen_swagger)
48
48
 
49
49
  `#{cmd}`
@@ -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
@@ -1,3 +1,3 @@
1
1
  module TwirpRails
2
- VERSION = '0.1.6'.freeze
2
+ VERSION = '0.1.7'.freeze
3
3
  end
data/lib/twirp_rails.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require 'twirp_rails/version'
4
4
  require 'twirp_rails/engine'
5
5
  require 'twirp_rails/generators/twirp/twirp_generator'
6
+ require 'twirp_rails/generators/twirp/twirp_rspec_generator'
6
7
  require 'twirp_rails/active_record_extension'
7
8
 
8
9
  module TwirpRails
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.6
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 00:00:00.000000000 Z
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