protobuf 2.8.0.beta9 → 2.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (204) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +0 -1
  3. data/{UPGRADING.md → CHANGES.md} +20 -12
  4. data/LICENSE.txt +14 -0
  5. data/README.md +60 -74
  6. data/bin/protoc-gen-ruby +26 -0
  7. data/bin/rprotoc +4 -58
  8. data/lib/protobuf.rb +15 -13
  9. data/lib/protobuf/code_generator.rb +41 -0
  10. data/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb +51 -0
  11. data/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb +248 -0
  12. data/lib/protobuf/field/base_field.rb +0 -1
  13. data/lib/protobuf/field/bytes_field.rb +1 -1
  14. data/lib/protobuf/field/message_field.rb +2 -4
  15. data/lib/protobuf/field/varint_field.rb +4 -7
  16. data/lib/protobuf/generators/base.rb +71 -0
  17. data/lib/protobuf/generators/enum_generator.rb +31 -0
  18. data/lib/protobuf/generators/extension_generator.rb +28 -0
  19. data/lib/protobuf/generators/field_generator.rb +132 -0
  20. data/lib/protobuf/generators/file_generator.rb +140 -0
  21. data/lib/protobuf/generators/group_generator.rb +113 -0
  22. data/lib/protobuf/generators/message_generator.rb +99 -0
  23. data/lib/protobuf/generators/printable.rb +161 -0
  24. data/lib/protobuf/generators/service_generator.rb +27 -0
  25. data/lib/protobuf/lifecycle.rb +7 -3
  26. data/lib/protobuf/message.rb +51 -34
  27. data/lib/protobuf/rpc/connectors/common.rb +4 -6
  28. data/lib/protobuf/rpc/server.rb +1 -1
  29. data/lib/protobuf/rpc/servers/zmq/server.rb +2 -2
  30. data/lib/protobuf/rpc/servers/zmq/worker.rb +2 -2
  31. data/lib/protobuf/rpc/service.rb +3 -3
  32. data/lib/protobuf/rpc/service_directory.rb +24 -12
  33. data/lib/protobuf/version.rb +1 -1
  34. data/proto/google/protobuf/compiler/plugin.proto +147 -0
  35. data/proto/google/protobuf/descriptor.proto +620 -0
  36. data/protobuf.gemspec +12 -21
  37. data/spec/bin/protoc-gen-ruby_spec.rb +18 -0
  38. data/spec/data/data.bin +3 -0
  39. data/{test/data/unk.png → spec/data/types.bin} +0 -0
  40. data/spec/encoding/all_types_spec.rb +91 -0
  41. data/spec/encoding/extreme_values_spec.rb +0 -0
  42. data/spec/lib/protobuf/code_generator_spec.rb +60 -0
  43. data/spec/lib/protobuf/generators/base_spec.rb +87 -0
  44. data/spec/lib/protobuf/generators/enum_generator_spec.rb +45 -0
  45. data/spec/lib/protobuf/generators/extension_generator_spec.rb +43 -0
  46. data/spec/lib/protobuf/generators/field_generator_spec.rb +99 -0
  47. data/spec/lib/protobuf/generators/file_generator_spec.rb +29 -0
  48. data/spec/lib/protobuf/generators/message_generator_spec.rb +0 -0
  49. data/spec/lib/protobuf/generators/service_generator_spec.rb +43 -0
  50. data/spec/lib/protobuf/lifecycle_spec.rb +31 -1
  51. data/spec/lib/protobuf/logger_spec.rb +5 -0
  52. data/spec/lib/protobuf/message_spec.rb +22 -8
  53. data/spec/lib/protobuf/rpc/connectors/common_spec.rb +1 -1
  54. data/spec/lib/protobuf/rpc/service_directory_spec.rb +45 -7
  55. data/spec/lib/protobuf/rpc/service_spec.rb +3 -3
  56. data/spec/spec_helper.rb +15 -16
  57. data/spec/support/test/all_types.data.bin +0 -0
  58. data/spec/support/test/all_types.data.txt +119 -0
  59. data/spec/support/test/defaults.pb.rb +25 -0
  60. data/spec/support/test/defaults.proto +9 -0
  61. data/spec/support/test/enum.pb.rb +10 -8
  62. data/spec/support/test/extended.pb.rb +5 -3
  63. data/spec/support/test/extreme_values.data.bin +0 -0
  64. data/spec/support/test/google_unittest.pb.rb +543 -0
  65. data/spec/support/test/google_unittest.proto +713 -0
  66. data/spec/support/test/google_unittest_import.pb.rb +37 -0
  67. data/{ext/protobuf-2.4.1/src/google/protobuf/io/package_info.h → spec/support/test/google_unittest_import.proto} +27 -17
  68. data/spec/support/test/google_unittest_import_public.pb.rb +8 -0
  69. data/{ext/protobuf-2.4.1/src/google/protobuf/io/coded_stream_inl.h → spec/support/test/google_unittest_import_public.proto} +5 -31
  70. data/spec/support/test/multi_field_extensions.pb.rb +29 -7
  71. data/spec/support/test/multi_field_extensions.proto +12 -2
  72. data/spec/support/test/resource.pb.rb +20 -16
  73. metadata +149 -236
  74. data/examples/addressbook.pb.rb +0 -55
  75. data/examples/addressbook.proto +0 -24
  76. data/examples/reading_a_message.rb +0 -32
  77. data/examples/writing_a_message.rb +0 -46
  78. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/code_generator.h +0 -142
  79. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/command_line_interface.h +0 -318
  80. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_enum.h +0 -99
  81. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_enum_field.h +0 -103
  82. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_extension.h +0 -85
  83. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_field.h +0 -167
  84. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_file.h +0 -98
  85. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_generator.h +0 -72
  86. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_helpers.h +0 -159
  87. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_message.h +0 -170
  88. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_message_field.h +0 -102
  89. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_primitive_field.h +0 -103
  90. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_service.h +0 -118
  91. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_string_field.h +0 -104
  92. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_test_bad_identifiers.pb.h +0 -2721
  93. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/importer.h +0 -303
  94. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_enum.h +0 -84
  95. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_enum_field.h +0 -121
  96. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_extension.h +0 -77
  97. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_field.h +0 -108
  98. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_file.h +0 -101
  99. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_generator.h +0 -72
  100. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_helpers.h +0 -213
  101. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_message.h +0 -109
  102. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_message_field.h +0 -134
  103. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_primitive_field.h +0 -121
  104. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_service.h +0 -113
  105. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_string_field.h +0 -120
  106. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/mock_code_generator.h +0 -113
  107. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/package_info.h +0 -64
  108. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/parser.h +0 -434
  109. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/plugin.h +0 -73
  110. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/plugin.pb.h +0 -790
  111. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/python/python_generator.h +0 -156
  112. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/subprocess.h +0 -108
  113. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/zip_writer.h +0 -93
  114. data/ext/protobuf-2.4.1/src/google/protobuf/descriptor.h +0 -1367
  115. data/ext/protobuf-2.4.1/src/google/protobuf/descriptor.pb.h +0 -5223
  116. data/ext/protobuf-2.4.1/src/google/protobuf/descriptor_database.h +0 -366
  117. data/ext/protobuf-2.4.1/src/google/protobuf/dynamic_message.h +0 -136
  118. data/ext/protobuf-2.4.1/src/google/protobuf/extension_set.h +0 -904
  119. data/ext/protobuf-2.4.1/src/google/protobuf/generated_message_reflection.h +0 -424
  120. data/ext/protobuf-2.4.1/src/google/protobuf/generated_message_util.h +0 -82
  121. data/ext/protobuf-2.4.1/src/google/protobuf/io/coded_stream.h +0 -1102
  122. data/ext/protobuf-2.4.1/src/google/protobuf/io/gzip_stream.h +0 -207
  123. data/ext/protobuf-2.4.1/src/google/protobuf/io/printer.h +0 -136
  124. data/ext/protobuf-2.4.1/src/google/protobuf/io/tokenizer.h +0 -313
  125. data/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream.h +0 -238
  126. data/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream_impl.h +0 -357
  127. data/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream_impl_lite.h +0 -340
  128. data/ext/protobuf-2.4.1/src/google/protobuf/message.h +0 -692
  129. data/ext/protobuf-2.4.1/src/google/protobuf/message_lite.h +0 -239
  130. data/ext/protobuf-2.4.1/src/google/protobuf/package_info.h +0 -64
  131. data/ext/protobuf-2.4.1/src/google/protobuf/reflection_ops.h +0 -80
  132. data/ext/protobuf-2.4.1/src/google/protobuf/repeated_field.h +0 -1295
  133. data/ext/protobuf-2.4.1/src/google/protobuf/service.h +0 -291
  134. data/ext/protobuf-2.4.1/src/google/protobuf/stubs/common.h +0 -1211
  135. data/ext/protobuf-2.4.1/src/google/protobuf/stubs/hash.h +0 -220
  136. data/ext/protobuf-2.4.1/src/google/protobuf/stubs/map-util.h +0 -119
  137. data/ext/protobuf-2.4.1/src/google/protobuf/stubs/once.h +0 -123
  138. data/ext/protobuf-2.4.1/src/google/protobuf/stubs/stl_util-inl.h +0 -121
  139. data/ext/protobuf-2.4.1/src/google/protobuf/stubs/strutil.h +0 -457
  140. data/ext/protobuf-2.4.1/src/google/protobuf/stubs/substitute.h +0 -170
  141. data/ext/protobuf-2.4.1/src/google/protobuf/test_util.h +0 -174
  142. data/ext/protobuf-2.4.1/src/google/protobuf/test_util_lite.h +0 -101
  143. data/ext/protobuf-2.4.1/src/google/protobuf/testing/file.h +0 -83
  144. data/ext/protobuf-2.4.1/src/google/protobuf/testing/googletest.h +0 -98
  145. data/ext/protobuf-2.4.1/src/google/protobuf/text_format.h +0 -285
  146. data/ext/protobuf-2.4.1/src/google/protobuf/unittest.pb.h +0 -11915
  147. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_custom_options.pb.h +0 -2895
  148. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_embed_optimize_for.pb.h +0 -211
  149. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_empty.pb.h +0 -56
  150. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_import.pb.h +0 -188
  151. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_import_lite.pb.h +0 -151
  152. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_lite.pb.h +0 -4752
  153. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_lite_imports_nonlite.pb.h +0 -150
  154. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_mset.pb.h +0 -816
  155. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_no_generic_services.pb.h +0 -197
  156. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_optimize_for.pb.h +0 -403
  157. data/ext/protobuf-2.4.1/src/google/protobuf/unknown_field_set.h +0 -268
  158. data/ext/protobuf-2.4.1/src/google/protobuf/wire_format.h +0 -304
  159. data/ext/protobuf-2.4.1/src/google/protobuf/wire_format_lite.h +0 -620
  160. data/ext/protobuf-2.4.1/src/google/protobuf/wire_format_lite_inl.h +0 -774
  161. data/ext/ruby_generator/Makefile +0 -10
  162. data/ext/ruby_generator/RubyGenerator.cpp +0 -544
  163. data/ext/ruby_generator/RubyGenerator.h +0 -206
  164. data/ext/ruby_generator/extconf.rb +0 -35
  165. data/test/data/data_source.py +0 -14
  166. data/test/data/types_source.py +0 -22
  167. data/test/proto/addressbook.pb.rb +0 -66
  168. data/test/proto/addressbook.proto +0 -33
  169. data/test/proto/addressbook_base.pb.rb +0 -58
  170. data/test/proto/addressbook_base.proto +0 -26
  171. data/test/proto/addressbook_ext.pb.rb +0 -20
  172. data/test/proto/addressbook_ext.proto +0 -6
  173. data/test/proto/collision.pb.rb +0 -17
  174. data/test/proto/collision.proto +0 -5
  175. data/test/proto/ext_collision.pb.rb +0 -24
  176. data/test/proto/ext_collision.proto +0 -8
  177. data/test/proto/ext_range.pb.rb +0 -22
  178. data/test/proto/ext_range.proto +0 -7
  179. data/test/proto/float_default.proto +0 -10
  180. data/test/proto/lowercase.pb.rb +0 -30
  181. data/test/proto/lowercase.proto +0 -9
  182. data/test/proto/merge.pb.rb +0 -39
  183. data/test/proto/merge.proto +0 -15
  184. data/test/proto/nested.pb.rb +0 -30
  185. data/test/proto/nested.proto +0 -9
  186. data/test/proto/optional_field.pb.rb +0 -35
  187. data/test/proto/optional_field.proto +0 -12
  188. data/test/proto/packed.pb.rb +0 -22
  189. data/test/proto/packed.proto +0 -6
  190. data/test/proto/rpc.proto +0 -6
  191. data/test/proto/types.pb.rb +0 -84
  192. data/test/proto/types.proto +0 -37
  193. data/test/test_addressbook.rb +0 -56
  194. data/test/test_enum_value.rb +0 -41
  195. data/test/test_extension.rb +0 -36
  196. data/test/test_lowercase.rb +0 -11
  197. data/test/test_message.rb +0 -128
  198. data/test/test_optional_field.rb +0 -103
  199. data/test/test_packed_field.rb +0 -40
  200. data/test/test_parse.rb +0 -15
  201. data/test/test_repeated_types.rb +0 -132
  202. data/test/test_serialize.rb +0 -61
  203. data/test/test_standard_message.rb +0 -96
  204. data/test/test_types.rb +0 -226
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ require 'protobuf/generators/file_generator'
4
+
5
+ describe ::Protobuf::Generators::FileGenerator do
6
+
7
+ let(:base_descriptor_fields) { { :name => 'test/foo.proto' } }
8
+ let(:descriptor_fields) { base_descriptor_fields }
9
+ let(:file_descriptor) { ::Google::Protobuf::FileDescriptorProto.new(descriptor_fields) }
10
+
11
+ subject { described_class.new(file_descriptor) }
12
+ its(:file_name) { should eq 'test/foo.pb.rb' }
13
+
14
+ describe '#print_import_requires' do
15
+ let(:descriptor_fields) do
16
+ base_descriptor_fields.merge!({ :dependency => [ 'test/bar.proto',
17
+ 'test/baz.proto' ] })
18
+ end
19
+
20
+ it 'prints a ruby require for each dependency' do
21
+ subject.should_receive(:print_require).with('test/bar.pb')
22
+ subject.should_receive(:print_require).with('test/baz.pb')
23
+ subject.print_import_requires
24
+ end
25
+
26
+ end
27
+
28
+ end
29
+
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ require 'protobuf/generators/service_generator'
4
+
5
+ describe ::Protobuf::Generators::ServiceGenerator do
6
+
7
+ let(:methods) {
8
+ [
9
+ { :name => 'Search', :input_type => 'FooRequest', :output_type => 'FooResponse' },
10
+ { :name => 'FooBar', :input_type => '.foo.Request', :output_type => '.bar.Response' }
11
+ ]
12
+ }
13
+ let(:service_fields) { { :name => 'TestService',
14
+ :method => methods } }
15
+
16
+ let(:service) { ::Google::Protobuf::ServiceDescriptorProto.new(service_fields) }
17
+
18
+ subject { described_class.new(service) }
19
+
20
+ describe '#compile' do
21
+ let(:compiled) {
22
+ %q{class TestService < ::Protobuf::Rpc::Service
23
+ rpc :search, FooRequest, FooResponse
24
+ rpc :foo_bar, ::Foo::Request, ::Bar::Response
25
+ end
26
+
27
+ }
28
+ }
29
+
30
+ it 'compiles the service and it\'s rpc methods' do
31
+ subject.compile
32
+ subject.to_s.should eq(compiled)
33
+ end
34
+ end
35
+
36
+ describe '#build_method' do
37
+ it 'returns a string identifying the given method descriptor' do
38
+ subject.build_method(service.method.first).should eq("rpc :search, FooRequest, FooResponse")
39
+ end
40
+ end
41
+
42
+ end
43
+
@@ -27,7 +27,7 @@ describe ::Protobuf::Lifecycle do
27
27
  it "only registers blocks for event callbacks" do
28
28
  expect {
29
29
  subject.register("something")
30
- }.to raise_error( /block/ )
30
+ }.to raise_error( /block/ )
31
31
  end
32
32
 
33
33
  it "calls the registered block when triggered" do
@@ -60,6 +60,36 @@ describe ::Protobuf::Lifecycle do
60
60
  that.should eq("not nil")
61
61
  end
62
62
 
63
+ context 'when the registered block has arity' do
64
+ context 'and the triggered event does not have args' do
65
+ it 'does not pass the args' do
66
+ outer_bar = nil
67
+
68
+ subject.register('foo') do |bar|
69
+ bar.should be_nil
70
+ outer_bar = 'triggered'
71
+ end
72
+
73
+ subject.trigger('foo')
74
+ outer_bar.should eq 'triggered'
75
+ end
76
+ end
77
+
78
+ context 'and the triggered event has arguments' do
79
+ it 'does not pass the args' do
80
+ outer_bar = nil
81
+
82
+ subject.register('foo') do |bar|
83
+ bar.should_not be_nil
84
+ outer_bar = bar
85
+ end
86
+
87
+ subject.trigger('foo', 'baz')
88
+ outer_bar.should eq 'baz'
89
+ end
90
+ end
91
+ end
92
+
63
93
  context "normalized event names" do
64
94
  specify { subject.normalized_event_name(:derp).should eq("derp") }
65
95
  specify { subject.normalized_event_name(:Derp).should eq("derp") }
@@ -1,5 +1,6 @@
1
1
  require 'protobuf/logger'
2
2
  require 'stringio'
3
+ require 'fileutils'
3
4
 
4
5
  describe Protobuf::Logger do
5
6
 
@@ -11,6 +12,10 @@ describe Protobuf::Logger do
11
12
  Protobuf::Logger.level = ::Logger::INFO
12
13
  end
13
14
 
15
+ after(:all) do
16
+ ::FileUtils.rm_f('myfile.log')
17
+ end
18
+
14
19
  describe '.instance' do
15
20
 
16
21
  it 'doesn\'t create a logger if the file was not set' do
@@ -2,6 +2,14 @@ require 'spec_helper'
2
2
 
3
3
  describe Protobuf::Message do
4
4
 
5
+ describe '.decode' do
6
+ let(:message) { ::Test::Resource.new(:name => "Jim") }
7
+
8
+ it 'creates a new message object decoded from the given bytes' do
9
+ ::Test::Resource.decode(message.encode).should eq message
10
+ end
11
+ end
12
+
5
13
  describe '.define_field' do
6
14
  context 'when defining a field with a tag that has already been used' do
7
15
  it 'raises a TagCollisionError' do
@@ -50,6 +58,14 @@ describe Protobuf::Message do
50
58
  end
51
59
  end
52
60
 
61
+ describe '.encode' do
62
+ let(:values) { { :name => "Jim" } }
63
+
64
+ it 'creates a new message object with the given values and returns the encoded bytes' do
65
+ ::Test::Resource.encode(values).should eq ::Test::Resource.new(values).encode
66
+ end
67
+ end
68
+
53
69
  describe '#initialize' do
54
70
  it "initializes the enum getter to 0" do
55
71
  test_enum = Test::EnumTestMessage.new
@@ -69,7 +85,7 @@ describe Protobuf::Message do
69
85
 
70
86
  it "does not try to set attributes which have nil values" do
71
87
  Test::EnumTestMessage.any_instance.should_not_receive("non_default_enum=")
72
- test_enum = Test::EnumTestMessage.new(:non_default_enum => nil)
88
+ Test::EnumTestMessage.new(:non_default_enum => nil)
73
89
  end
74
90
 
75
91
  it "takes a hash as an initialization argument" do
@@ -89,7 +105,7 @@ describe Protobuf::Message do
89
105
  it "accepts UTF-8 strings into string fields" do
90
106
  message = ::Test::Resource.new(:name => "Kyle Redfearn\u0060s iPad")
91
107
 
92
- expect { message.serialize_to_string }.to_not raise_error
108
+ expect { message.encode }.to_not raise_error
93
109
  end
94
110
 
95
111
  it "keeps utf-8 when utf-8 is input for string fields" do
@@ -97,8 +113,7 @@ describe Protobuf::Message do
97
113
  name.force_encoding("UTF-8")
98
114
 
99
115
  message = ::Test::Resource.new(:name => name)
100
- new_message = ::Test::Resource.new
101
- new_message.parse_from_string(message.serialize_to_string)
116
+ new_message = ::Test::Resource.decode(message.encode)
102
117
  (new_message.name == name).should be_true
103
118
  end
104
119
 
@@ -107,8 +122,7 @@ describe Protobuf::Message do
107
122
  name.force_encoding("ASCII-8BIT")
108
123
 
109
124
  message = ::Test::Resource.new(:name => name)
110
- new_message = ::Test::Resource.new
111
- new_message.parse_from_string(message.serialize_to_string)
125
+ new_message = ::Test::Resource.decode(message.encode)
112
126
  (new_message.name == "my name").should be_true
113
127
  end
114
128
  end
@@ -118,7 +132,7 @@ describe Protobuf::Message do
118
132
 
119
133
  it "raises a 'message not initialized' error" do
120
134
  expect {
121
- message.serialize_to_string
135
+ message.encode
122
136
  }.to raise_error(Protobuf::SerializationError, /required/i)
123
137
  end
124
138
  end
@@ -129,7 +143,7 @@ describe Protobuf::Message do
129
143
  it "does not raise an error when repeated fields are []" do
130
144
  expect {
131
145
  message.repeated_enum = []
132
- message.serialize_to_string
146
+ message.encode
133
147
  }.to_not raise_error
134
148
  end
135
149
 
@@ -87,7 +87,7 @@ describe Protobuf::Rpc::Connectors::Common do
87
87
  before { subject.stub(:validate_request_type!).and_return(true) }
88
88
  before { subject.should_not_receive(:fail) }
89
89
 
90
- its(:request_bytes) { should eq expected.serialize_to_string }
90
+ its(:request_bytes) { should eq expected.encode }
91
91
  end
92
92
 
93
93
  describe "#verify_callbacks" do
@@ -58,17 +58,55 @@ describe ::Protobuf::Rpc::ServiceDirectory do
58
58
  end
59
59
  end
60
60
 
61
+ describe '#add_listing_for' do
62
+ let(:server) { double('server', { :uuid => '123',
63
+ :services => ['Known::Service'],
64
+ :address => "0.0.0.0",
65
+ :port => 9999,
66
+ :ttl => 15 }) }
67
+
68
+ it 'adds the listing to the known @listings' do
69
+ expect {
70
+ ::Protobuf::Lifecycle.should_receive(:trigger)
71
+ .with('directory.listing.added', an_instance_of(::Protobuf::Rpc::ServiceDirectory::Listing))
72
+ .once
73
+ instance.add_listing_for(server)
74
+ }.to change(listings, :size).from(0).to(1)
75
+ end
76
+ end
77
+
78
+ describe '#each_listing' do
79
+ let(:listing_doubles) { { '1' => double('listing 1'),
80
+ '2' => double('listing 2'),
81
+ '3' => double('listing 3') } }
82
+
83
+ before do
84
+ instance.instance_variable_set(:@listings, listing_doubles)
85
+ end
86
+
87
+ it 'invokes the given block for each listing known by the directory' do
88
+ yielded_listings = []
89
+ instance.each_listing do |listing|
90
+ yielded_listings << listing
91
+ end
92
+ yielded_listings.should eq(listing_doubles.values)
93
+ end
94
+ end
95
+
61
96
  describe "#remove_expired_listings" do
97
+ let(:listing_doubles) { { '1' => double(:expired? => true),
98
+ '2' => double(:expired? => true),
99
+ '3' => double(:expired? => false) } }
100
+
62
101
  before do
63
- instance.instance_variable_set(:@listings, {
64
- '1' => double(:expired? => true),
65
- '2' => double(:expired? => true),
66
- '3' => double(:expired? => false),
67
- })
102
+ instance.instance_variable_set(:@listings, listing_doubles)
68
103
  end
69
104
 
70
105
  it "removes expired listings" do
71
106
  expect {
107
+ ::Protobuf::Lifecycle.should_receive(:trigger)
108
+ .with('directory.listing.removed', an_instance_of(RSpec::Mocks::Mock))
109
+ .twice
72
110
  instance.remove_expired_listings
73
111
  }.to change(listings, :size).from(3).to(1)
74
112
  listings.keys.should eq ['3']
@@ -121,7 +159,7 @@ describe ::Protobuf::Rpc::ServiceDirectory do
121
159
  :server => server,
122
160
  :beacon_type => ::Protobuf::Rpc::DynamicDiscovery::BeaconType::HEARTBEAT
123
161
  )}
124
- let(:payload) { beacon.serialize_to_string }
162
+ let(:payload) { beacon.encode }
125
163
 
126
164
  it "adds a listing" do
127
165
  instance.should_receive(:add_listing_for).with(server)
@@ -137,7 +175,7 @@ describe ::Protobuf::Rpc::ServiceDirectory do
137
175
  :server => server,
138
176
  :beacon_type => ::Protobuf::Rpc::DynamicDiscovery::BeaconType::FLATLINE
139
177
  )}
140
- let(:payload) { beacon.serialize_to_string }
178
+ let(:payload) { beacon.encode }
141
179
 
142
180
  it "removes a listing" do
143
181
  instance.should_receive(:remove_listing_for).with(server)
@@ -131,7 +131,7 @@ describe Protobuf::Rpc::Service do
131
131
 
132
132
  context 'when calling the rpc method' do
133
133
  context 'when response is implied' do
134
- subject { NewTestService.new(:find_with_implied_response, request.serialize_to_string) }
134
+ subject { NewTestService.new(:find_with_implied_response, request.encode) }
135
135
 
136
136
  before { subject.find_with_implied_response }
137
137
  its(:response) { should be_a(Test::Resource) }
@@ -139,7 +139,7 @@ describe Protobuf::Rpc::Service do
139
139
  end
140
140
 
141
141
  context 'when using respond_with paradigm' do
142
- subject { NewTestService.new(:find_with_respond_with, request.serialize_to_string) }
142
+ subject { NewTestService.new(:find_with_respond_with, request.encode) }
143
143
 
144
144
  before { subject.find_with_respond_with }
145
145
  its(:response) { should be_a(Test::Resource) }
@@ -148,7 +148,7 @@ describe Protobuf::Rpc::Service do
148
148
  end
149
149
 
150
150
  context 'when calling rpc_failed in the method' do
151
- subject { NewTestService.new(:find_with_rpc_failed, request.serialize_to_string) }
151
+ subject { NewTestService.new(:find_with_rpc_failed, request.encode) }
152
152
 
153
153
  it 'invokes the rpc_failed callback with the error' do
154
154
  error = nil
data/spec/spec_helper.rb CHANGED
@@ -6,15 +6,17 @@ require 'bundler'
6
6
  Bundler.setup :default, :development, :test
7
7
  require 'pry'
8
8
 
9
- $: << ::File.expand_path('..', File.dirname(__FILE__))
10
- $: << ::File.expand_path('../spec/support', File.dirname(__FILE__))
11
- #$: << ::File.expand_path('../lib', File.dirname(__FILE__))
9
+ $: << ::File.expand_path('../..', __FILE__)
10
+ $: << ::File.expand_path('../support', __FILE__)
12
11
 
13
12
  require 'protobuf'
14
- require ::File.dirname(__FILE__) + '/support/all'
13
+ require ::File.expand_path('../support/all', __FILE__)
14
+
15
+ $: << ::File.expand_path("../../lib/protobuf/descriptors", __FILE__)
16
+ require 'google/protobuf/compiler/plugin.pb'
15
17
 
16
18
  # Including a way to turn on debug logger for spec runs
17
- if ENV["DEBUG"]
19
+ if ENV.key?('DEBUG')
18
20
  debug_log = ::File.expand_path('../debug_specs.log', File.dirname(__FILE__) )
19
21
  ::Protobuf::Logger.configure(:file => debug_log, :level => ::Logger::DEBUG)
20
22
  end
@@ -27,21 +29,18 @@ ENV.delete("PB_IGNORE_DEPRECATIONS")
27
29
  c.mock_with :rspec
28
30
 
29
31
  c.before(:suite) do
30
- unless defined?(JRUBY_VERSION)
31
- unless ENV['NO_COMPILE_TEST_PROTOS']
32
- $stdout.puts 'Compiling test protos (use NO_COMPILE_TEST_PROTOS=1 to skip)'
33
- proto_path = File.expand_path("../support/", __FILE__)
34
- cmd = %Q{ rprotoc --proto_path=#{proto_path} --ruby_out=#{proto_path} #{File.join(proto_path, '**', '*.proto')} }
35
- puts cmd
36
- %x{#{cmd}}
37
- end
32
+ unless ENV['NO_COMPILE_TEST_PROTOS']
33
+ $stdout.puts 'Compiling test protos (use NO_COMPILE_TEST_PROTOS=1 to skip)'
34
+ proto_path = File.expand_path("../support/", __FILE__)
35
+ cmd = %Q{protoc --plugin=./bin/protoc-gen-ruby --ruby_out=#{proto_path} -I #{proto_path} #{File.join(proto_path, '**', '*.proto')}}
36
+ puts cmd
37
+ %x{#{cmd}}
38
38
  end
39
39
  end
40
40
  end
41
41
 
42
- Dir[File.expand_path('../support/**/*.pb.rb', __FILE__)].each do |proto_file|
43
- require proto_file
44
- end
42
+ support_proto_glob = File.expand_path('../support/**/*.pb.rb', __FILE__)
43
+ Dir[support_proto_glob].each { |proto_file| require proto_file }
45
44
 
46
45
  class ::Protobuf::Rpc::Client
47
46
  def ==(other)
@@ -0,0 +1,119 @@
1
+ optional_int32: 101
2
+ optional_int64: 102
3
+ optional_uint32: 103
4
+ optional_uint64: 104
5
+ optional_sint32: 105
6
+ optional_sint64: 106
7
+ optional_fixed32: 107
8
+ optional_fixed64: 108
9
+ optional_sfixed32: 109
10
+ optional_sfixed64: 110
11
+ optional_float: 111
12
+ optional_double: 112
13
+ optional_bool: true
14
+ optional_string: "115"
15
+ optional_bytes: "116"
16
+ optional_nested_message {
17
+ bb: 118
18
+ }
19
+ optional_foreign_message {
20
+ c: 119
21
+ }
22
+ optional_import_message {
23
+ d: 120
24
+ }
25
+ optional_nested_enum: BAZ
26
+ optional_foreign_enum: FOREIGN_BAZ
27
+ optional_import_enum: IMPORT_BAZ
28
+ optional_string_piece: "124"
29
+ optional_cord: "125"
30
+ optional_public_import_message {
31
+ e: 126
32
+ }
33
+ optional_lazy_message {
34
+ bb: 127
35
+ }
36
+ repeated_int32: 201
37
+ repeated_int32: 301
38
+ repeated_int64: 202
39
+ repeated_int64: 302
40
+ repeated_uint32: 203
41
+ repeated_uint32: 303
42
+ repeated_uint64: 204
43
+ repeated_uint64: 304
44
+ repeated_sint32: 205
45
+ repeated_sint32: 305
46
+ repeated_sint64: 206
47
+ repeated_sint64: 306
48
+ repeated_fixed32: 207
49
+ repeated_fixed32: 307
50
+ repeated_fixed64: 208
51
+ repeated_fixed64: 308
52
+ repeated_sfixed32: 209
53
+ repeated_sfixed32: 309
54
+ repeated_sfixed64: 210
55
+ repeated_sfixed64: 310
56
+ repeated_float: 211
57
+ repeated_float: 311
58
+ repeated_double: 212
59
+ repeated_double: 312
60
+ repeated_bool: true
61
+ repeated_bool: false
62
+ repeated_string: "215"
63
+ repeated_string: "315"
64
+ repeated_bytes: "216"
65
+ repeated_bytes: "316"
66
+ repeated_nested_message {
67
+ bb: 218
68
+ }
69
+ repeated_nested_message {
70
+ bb: 318
71
+ }
72
+ repeated_foreign_message {
73
+ c: 219
74
+ }
75
+ repeated_foreign_message {
76
+ c: 319
77
+ }
78
+ repeated_import_message {
79
+ d: 220
80
+ }
81
+ repeated_import_message {
82
+ d: 320
83
+ }
84
+ repeated_nested_enum: BAR
85
+ repeated_nested_enum: BAZ
86
+ repeated_foreign_enum: FOREIGN_BAR
87
+ repeated_foreign_enum: FOREIGN_BAZ
88
+ repeated_import_enum: IMPORT_BAR
89
+ repeated_import_enum: IMPORT_BAZ
90
+ repeated_string_piece: "224"
91
+ repeated_string_piece: "324"
92
+ repeated_cord: "225"
93
+ repeated_cord: "325"
94
+ repeated_lazy_message {
95
+ bb: 227
96
+ }
97
+ repeated_lazy_message {
98
+ bb: 327
99
+ }
100
+ default_int32: 401
101
+ default_int64: 402
102
+ default_uint32: 403
103
+ default_uint64: 404
104
+ default_sint32: 405
105
+ default_sint64: 406
106
+ default_fixed32: 407
107
+ default_fixed64: 408
108
+ default_sfixed32: 409
109
+ default_sfixed64: 410
110
+ default_float: 411
111
+ default_double: 412
112
+ default_bool: false
113
+ default_string: "415"
114
+ default_bytes: "416"
115
+ default_nested_enum: FOO
116
+ default_foreign_enum: FOREIGN_FOO
117
+ default_import_enum: IMPORT_FOO
118
+ default_string_piece: "424"
119
+ default_cord: "425"