protobuf-rspec 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,14 +1,5 @@
1
- require 'rspec/core'
2
1
  require 'protobuf/rpc/rpc.pb'
3
2
 
4
- ::RSpec.configure do |config|
5
- config.add_setting :protobuf_raw_response, :default => false
6
-
7
- def config.protobuf_raw_responses
8
- self.protobuf_raw_response = true
9
- end
10
- end
11
-
12
3
  # RSpec Helpers designed to give you mock abstraction of client or service layer.
13
4
  # Require as protobuf/rspec/helpers and include into your running RSpec configuration.
14
5
  #
@@ -30,20 +21,6 @@ module Protobuf
30
21
 
31
22
  module ClassMethods
32
23
 
33
- def metadata_for_protobuf_rspec
34
- metadata[:protobuf_rspec] = metadata[:protobuf_rspec] ? metadata[:protobuf_rspec].dup : {}
35
- end
36
-
37
- def protobuf_raw_responses(true_or_false = true)
38
- metadata_for_protobuf_rspec[:protobuf_raw_response] = true_or_false
39
- end
40
-
41
- def protobuf_raw_responses?
42
- metadata_for_protobuf_rspec.fetch(:protobuf_raw_response) do
43
- ::RSpec.configuration.protobuf_raw_response?
44
- end
45
- end
46
-
47
24
  # Set the service subject. Use this method when the described_class is
48
25
  # not the class you wish to use with methods like local_rpc. In t
49
26
  #
@@ -76,10 +53,6 @@ module Protobuf
76
53
 
77
54
  module InstanceMethods
78
55
 
79
- def protobuf_raw_responses?
80
- self.class.protobuf_raw_responses?
81
- end
82
-
83
56
  def subject_service
84
57
  self.class.subject_service
85
58
  end
@@ -123,43 +96,21 @@ module Protobuf
123
96
  #
124
97
  # @param [Symbol, String] method a symbol or string denoting the method to call.
125
98
  # @param [Protobuf::Message or Hash] request the request message of the expected type for the given method.
126
- # @param [block] optionally provide a block which will be yielded the service instance just prior to invoking the rpc method.
127
- # @return [Protobuf::Service] the service instance post-calling the rpc method.
128
- def local_rpc(rpc_method, request, raw_response = false)
99
+ # @return [Protobuf::Message or String] the resulting protobuf message or error string
100
+ def local_rpc(rpc_method, request)
129
101
  request = subject_service.rpcs[rpc_method].request_type.new(request) if request.is_a?(Hash)
130
102
 
131
- if raw_response || protobuf_raw_responses? || request.serialize_to_string.empty?
132
- service = subject_service.new(rpc_method, request.serialize_to_string)
133
-
134
- yield(service) if block_given?
135
-
136
- service.__send__(rpc_method)
137
- return service
138
- else
139
- return __dispatch_service_call__(rpc_method, request)
140
- end
141
- end
142
-
143
- def __dispatch_service_call__(rpc_method, request)
144
- request_params = {
103
+ outer_request_params = {
145
104
  :service_name => subject_service.to_s,
146
105
  :method_name => rpc_method.to_s,
147
106
  :request_proto => request.serialize_to_string
148
107
  }
149
108
 
150
- rpc_request = ::Protobuf::Socketrpc::Request.new(request_params)
151
- dispatcher = ::Protobuf::Rpc::ServiceDispatcher.new(rpc_request)
152
- dispatcher.invoke!
153
- end
109
+ outer_request = ::Protobuf::Socketrpc::Request.new(outer_request_params)
110
+ dispatcher = ::Protobuf::Rpc::ServiceDispatcher.new(outer_request)
154
111
 
155
- # Provides backwards compatability to bridge to the new local_rpc usage.
156
- #
157
- def call_local_service(klass, rpc_method, request, &block)
158
- $stderr.puts '[Deprecated] call_local_service is deprecated. Please use local_rpc in conjunction with subject_service.'
159
- self.class.service { klass }
160
- local_rpc(rpc_method, request, nil &block)
112
+ dispatcher.invoke!
161
113
  end
162
- alias_method :call_service, :call_local_service
163
114
 
164
115
  # Create a mock service that responds in the way you are expecting to aid in testing client -> service calls.
165
116
  # In order to test your success callback you should provide a :response object. Similarly, to test your failure
@@ -1,5 +1,5 @@
1
1
  module Protobuf
2
2
  module RSpec
3
- VERSION = "0.2.0"
3
+ VERSION = "0.2.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protobuf-rspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-19 00:00:00.000000000 Z
12
+ date: 2012-11-19 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: protobuf
16
- requirement: !ruby/object:Gem::Requirement
16
+ requirement: &2156886860 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,15 +21,10 @@ dependencies:
21
21
  version: '2.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: '2.0'
24
+ version_requirements: *2156886860
30
25
  - !ruby/object:Gem::Dependency
31
26
  name: rspec
32
- requirement: !ruby/object:Gem::Requirement
27
+ requirement: &2156839100 !ruby/object:Gem::Requirement
33
28
  none: false
34
29
  requirements:
35
30
  - - ~>
@@ -37,15 +32,10 @@ dependencies:
37
32
  version: '2.8'
38
33
  type: :runtime
39
34
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ~>
44
- - !ruby/object:Gem::Version
45
- version: '2.8'
35
+ version_requirements: *2156839100
46
36
  - !ruby/object:Gem::Dependency
47
37
  name: rake
48
- requirement: !ruby/object:Gem::Requirement
38
+ requirement: &2156838620 !ruby/object:Gem::Requirement
49
39
  none: false
50
40
  requirements:
51
41
  - - ! '>='
@@ -53,15 +43,10 @@ dependencies:
53
43
  version: '0'
54
44
  type: :development
55
45
  prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ! '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
46
+ version_requirements: *2156838620
62
47
  - !ruby/object:Gem::Dependency
63
48
  name: yard
64
- requirement: !ruby/object:Gem::Requirement
49
+ requirement: &2156837580 !ruby/object:Gem::Requirement
65
50
  none: false
66
51
  requirements:
67
52
  - - ~>
@@ -69,15 +54,10 @@ dependencies:
69
54
  version: '0.7'
70
55
  type: :development
71
56
  prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ~>
76
- - !ruby/object:Gem::Version
77
- version: '0.7'
57
+ version_requirements: *2156837580
78
58
  - !ruby/object:Gem::Dependency
79
59
  name: redcarpet
80
- requirement: !ruby/object:Gem::Requirement
60
+ requirement: &2156836540 !ruby/object:Gem::Requirement
81
61
  none: false
82
62
  requirements:
83
63
  - - ~>
@@ -85,12 +65,7 @@ dependencies:
85
65
  version: '2.1'
86
66
  type: :development
87
67
  prerelease: false
88
- version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
- requirements:
91
- - - ~>
92
- - !ruby/object:Gem::Version
93
- version: '2.1'
68
+ version_requirements: *2156836540
94
69
  description: Protobuf RSpec helpers for testing services and clients. Meant to be
95
70
  used with the protobuf gem. Decouple external services/clients from each other using
96
71
  the given helper methods.
@@ -122,7 +97,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
122
97
  version: '0'
123
98
  segments:
124
99
  - 0
125
- hash: -1397050459416852954
100
+ hash: -1849475935849692850
126
101
  required_rubygems_version: !ruby/object:Gem::Requirement
127
102
  none: false
128
103
  requirements:
@@ -131,10 +106,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
106
  version: '0'
132
107
  segments:
133
108
  - 0
134
- hash: -1397050459416852954
109
+ hash: -1849475935849692850
135
110
  requirements: []
136
111
  rubyforge_project: protobuf-rspec
137
- rubygems_version: 1.8.24
112
+ rubygems_version: 1.8.15
138
113
  signing_key:
139
114
  specification_version: 3
140
115
  summary: Protobuf RSpec helpers for testing services and clients. Meant to be used