protobuf-rspec 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,14 @@
1
+ require 'rspec/core'
1
2
  require 'protobuf/rpc/rpc.pb'
2
3
 
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
+
3
12
  # RSpec Helpers designed to give you mock abstraction of client or service layer.
4
13
  # Require as protobuf/rspec/helpers and include into your running RSpec configuration.
5
14
  #
@@ -21,6 +30,20 @@ module Protobuf
21
30
 
22
31
  module ClassMethods
23
32
 
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
+
24
47
  # Set the service subject. Use this method when the described_class is
25
48
  # not the class you wish to use with methods like local_rpc. In t
26
49
  #
@@ -53,6 +76,10 @@ module Protobuf
53
76
 
54
77
  module InstanceMethods
55
78
 
79
+ def protobuf_raw_responses?
80
+ self.class.protobuf_raw_responses?
81
+ end
82
+
56
83
  def subject_service
57
84
  self.class.subject_service
58
85
  end
@@ -96,26 +123,33 @@ module Protobuf
96
123
  #
97
124
  # @param [Symbol, String] method a symbol or string denoting the method to call.
98
125
  # @param [Protobuf::Message or Hash] request the request message of the expected type for the given method.
99
- # @param [String] a string message indicating an rpc_failed expectation.
100
126
  # @param [block] optionally provide a block which will be yielded the service instance just prior to invoking the rpc method.
101
127
  # @return [Protobuf::Service] the service instance post-calling the rpc method.
102
- def local_rpc(rpc_method, request, expected_error = nil)
128
+ def local_rpc(rpc_method, request, raw_response = false)
103
129
  request = subject_service.rpcs[rpc_method].request_type.new(request) if request.is_a?(Hash)
104
- service = subject_service.new(rpc_method, request.serialize_to_string)
105
130
 
106
- if block_given?
107
- $stderr.puts '[Warning] Ignoring error expectation %s due to given block' % expected_error unless expected_error.blank?
108
- yield(service)
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
109
138
  else
110
- if expected_error.blank?
111
- service.should_not_receive(:rpc_failed)
112
- else
113
- service.should_receive(:rpc_failed).with(expected_error)
114
- end
139
+ return __dispatch_service_call__(rpc_method, request)
115
140
  end
141
+ end
142
+
143
+ def __dispatch_service_call__(rpc_method, request)
144
+ request_params = {
145
+ :service_name => subject_service.to_s,
146
+ :method_name => rpc_method.to_s,
147
+ :request_proto => request.serialize_to_string
148
+ }
116
149
 
117
- service.__send__(rpc_method)
118
- service
150
+ rpc_request = ::Protobuf::Socketrpc::Request.new(request_params)
151
+ dispatcher = ::Protobuf::Rpc::ServiceDispatcher.new(rpc_request)
152
+ dispatcher.invoke!
119
153
  end
120
154
 
121
155
  # Provides backwards compatability to bridge to the new local_rpc usage.
@@ -1,5 +1,5 @@
1
1
  module Protobuf
2
2
  module RSpec
3
- VERSION = "0.1.3"
3
+ VERSION = "0.2.0"
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.1.3
4
+ version: 0.2.0
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-10-26 00:00:00.000000000Z
12
+ date: 2012-11-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: protobuf
16
- requirement: &2155090860 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '2.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2155090860
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '2.0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: rspec
27
- requirement: &2155090360 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ~>
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '2.8'
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *2155090360
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '2.8'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: rake
38
- requirement: &2155089980 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: '0'
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *2155089980
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: yard
49
- requirement: &2155089440 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ~>
@@ -54,10 +69,15 @@ dependencies:
54
69
  version: '0.7'
55
70
  type: :development
56
71
  prerelease: false
57
- version_requirements: *2155089440
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '0.7'
58
78
  - !ruby/object:Gem::Dependency
59
79
  name: redcarpet
60
- requirement: &2155088940 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
61
81
  none: false
62
82
  requirements:
63
83
  - - ~>
@@ -65,7 +85,12 @@ dependencies:
65
85
  version: '2.1'
66
86
  type: :development
67
87
  prerelease: false
68
- version_requirements: *2155088940
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: '2.1'
69
94
  description: Protobuf RSpec helpers for testing services and clients. Meant to be
70
95
  used with the protobuf gem. Decouple external services/clients from each other using
71
96
  the given helper methods.
@@ -97,7 +122,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
97
122
  version: '0'
98
123
  segments:
99
124
  - 0
100
- hash: -1636365208668398058
125
+ hash: -1397050459416852954
101
126
  required_rubygems_version: !ruby/object:Gem::Requirement
102
127
  none: false
103
128
  requirements:
@@ -106,10 +131,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
131
  version: '0'
107
132
  segments:
108
133
  - 0
109
- hash: -1636365208668398058
134
+ hash: -1397050459416852954
110
135
  requirements: []
111
136
  rubyforge_project: protobuf-rspec
112
- rubygems_version: 1.8.15
137
+ rubygems_version: 1.8.24
113
138
  signing_key:
114
139
  specification_version: 3
115
140
  summary: Protobuf RSpec helpers for testing services and clients. Meant to be used