From 0062b188247781e016f05fb2ed5a39686553236f Mon Sep 17 00:00:00 2001 From: Brian Palmer Date: Tue, 5 Jan 2010 22:44:22 -0700 Subject: [PATCH] clean up gem/rake/rdoc/rspec infrastructure using the Jeweler library --- .document | 3 + .gitignore | 11 ++- Rakefile | 74 +++++++++++++------ VERSION | 2 +- ext/{extconf.rb => extconf.disabled.rb} | 0 lib/protocol_buffers.rb | 4 + .../compiler/file_descriptor_to_ruby.rb | 2 +- lib/protocol_buffers/runtime/message.rb | 2 +- spec/compiler_spec.rb | 2 +- spec/fields_spec.rb | 6 +- spec/proto_files/featureful.proto | 2 +- spec/runtime_spec.rb | 2 +- spec/spec.opts | 1 + spec/spec_helper.rb | 8 ++ 14 files changed, 83 insertions(+), 36 deletions(-) create mode 100644 .document rename ext/{extconf.rb => extconf.disabled.rb} (100%) mode change 100755 => 100644 spec/compiler_spec.rb mode change 100755 => 100644 spec/runtime_spec.rb create mode 100644 spec/spec.opts create mode 100644 spec/spec_helper.rb diff --git a/.document b/.document new file mode 100644 index 0000000..02576fd --- /dev/null +++ b/.document @@ -0,0 +1,3 @@ +README +lib/**/*.rb +LICENSE diff --git a/.gitignore b/.gitignore index ea3ae29..142adf0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,11 @@ /*.pb.rb /*.d /*.proto -pkg/* -prof/* -tests/* +coverage +rdoc +pkg +prof +tests d/* -doc/* +*.gemspec +tmp diff --git a/Rakefile b/Rakefile index 3bf5085..eba695f 100644 --- a/Rakefile +++ b/Rakefile @@ -1,29 +1,57 @@ require 'rubygems' -require 'rake/gempackagetask' - -spec = Gem::Specification.new do |s| - s.name = "ruby-protocol-buffers" - s.version = "0.1.0" - s.author = "Brian Palmer" - s.email = "brian@mozy.com" - s.homepage = "http://todo" - s.platform = Gem::Platform::RUBY - s.summary = "Ruby compiler and runtime for the google protocol buffers library. Currently includes a compiler that utilizes protoc." - - s.required_ruby_version = ">=1.8.6" - - s.files = FileList["{bin,lib,ext}/**/*"].to_a - s.require_path = 'lib' - s.executables << 'ruby-protoc' - # disabled to avoid needing to compile a C extension just to boost - # performance. TODO: is there a way to tell gems to make the extension - # optional? - # s.extensions << 'ext/extconf.rb' +require 'rake' + +begin + require 'metric_fu' +rescue LoadError +end + +begin + require 'jeweler' + Jeweler::Tasks.new do |gem| + gem.name = "ruby-protocol-buffers" + gem.summary = %Q{Ruby compiler and runtime for the google protocol buffers library.} + # gem.description = %Q{description} + gem.email = "brian@mozy.com" + gem.homepage = "http://todo/" + gem.authors = ["Brian Palmer"] + gem.version = File.read('VERSION') + gem.add_development_dependency "rspec", ">= 1.2.9" + gem.required_ruby_version = ">=1.8.6" + gem.require_path = 'lib' + # disabled to avoid needing to compile a C extension just to boost + # performance. TODO: is there a way to tell gems to make the extension + # optional? + # s.extensions << 'ext/extconf.rb' + # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings + end + Jeweler::GemcutterTasks.new +rescue LoadError + puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler" +end + +require 'spec/rake/spectask' +Spec::Rake::SpecTask.new(:spec) do |spec| + spec.libs << 'lib' << 'spec' + spec.pattern = 'spec/**/*_spec.rb' end -Rake::GemPackageTask.new(spec) do |pkg| +Spec::Rake::SpecTask.new(:rcov) do |spec| + spec.libs << 'lib' << 'spec' + spec.pattern = 'spec/**/*_spec.rb' + spec.rcov = true end -task :default => "pkg/#{spec.name}-#{spec.version}.gem" do - puts "generated latest version" +task :spec => :check_dependencies + +task :default => :spec + +require 'rake/rdoctask' +Rake::RDocTask.new do |rdoc| + version = File.exist?('VERSION') ? File.read('VERSION') : "" + + rdoc.rdoc_dir = 'rdoc' + rdoc.title = "ruby-protocol-buffers #{version}" + rdoc.rdoc_files.include('README*', 'LICENSE') + rdoc.rdoc_files.include('lib/**/*.rb') end diff --git a/VERSION b/VERSION index 77d6f4c..a3df0a6 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.0.0 +0.8.0 diff --git a/ext/extconf.rb b/ext/extconf.disabled.rb similarity index 100% rename from ext/extconf.rb rename to ext/extconf.disabled.rb diff --git a/lib/protocol_buffers.rb b/lib/protocol_buffers.rb index 1c5fa53..93aea7a 100644 --- a/lib/protocol_buffers.rb +++ b/lib/protocol_buffers.rb @@ -1 +1,5 @@ +module ProtocolBuffers + VERSION = File.read(File.join(File.dirname(__FILE__), "..", "VERSION")).chomp +end + require 'protocol_buffers/runtime/message' diff --git a/lib/protocol_buffers/compiler/file_descriptor_to_ruby.rb b/lib/protocol_buffers/compiler/file_descriptor_to_ruby.rb index c6fd817..89219c2 100644 --- a/lib/protocol_buffers/compiler/file_descriptor_to_ruby.rb +++ b/lib/protocol_buffers/compiler/file_descriptor_to_ruby.rb @@ -19,7 +19,7 @@ def write(io) #!/usr/bin/env ruby # Generated by the protocol buffer compiler. DO NOT EDIT! -require 'protocol_buffers/runtime/message' +require 'protocol_buffers' HEADER descriptor.dependency.each do |dep| diff --git a/lib/protocol_buffers/runtime/message.rb b/lib/protocol_buffers/runtime/message.rb index 292e93f..944dca6 100644 --- a/lib/protocol_buffers/runtime/message.rb +++ b/lib/protocol_buffers/runtime/message.rb @@ -419,7 +419,7 @@ def merge_field(tag, value, field = fields[tag]) # :nodoc: end def self.define_field(otype, type, name, tag, opts = {}) # :NODOC: - raise("gen_methods! already called! cannot add more fields") if @methods_generated + raise("gen_methods! already called, cannot add more fields") if @methods_generated type = type.is_a?(Module) ? type : type.to_sym name = name.to_sym tag = tag.to_i diff --git a/spec/compiler_spec.rb b/spec/compiler_spec.rb old mode 100755 new mode 100644 index f01b058..c3cb94c --- a/spec/compiler_spec.rb +++ b/spec/compiler_spec.rb @@ -1,4 +1,4 @@ -#!/usr/bin/env ruby +require File.expand_path(File.dirname(__FILE__) + '/spec_helper') $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib")) require 'protocol_buffers' diff --git a/spec/fields_spec.rb b/spec/fields_spec.rb index 079395a..52715bd 100644 --- a/spec/fields_spec.rb +++ b/spec/fields_spec.rb @@ -1,4 +1,4 @@ -#!/usr/bin/env ruby +require File.expand_path(File.dirname(__FILE__) + '/spec_helper') require 'stringio' @@ -27,9 +27,9 @@ def mkfield(ftype) pending("do UTF-8 validation") do s1 = mkfield(:StringField) proc { s1.check_valid("hello") }.should_not raise_error() + proc { s1.check_valid("\xff\xff") }.should raise_error(ArgumentError) b1 = mkfield(:BytesField) - proc { b1.valid?("\xff\xff") }.should_not raise_error() - proc { s1.valid?("\xff\xff") }.should raise_error(ArgumentError) + proc { b1.check_valid("\xff\xff") }.should_not raise_error() end end diff --git a/spec/proto_files/featureful.proto b/spec/proto_files/featureful.proto index e015647..57caaac 100644 --- a/spec/proto_files/featureful.proto +++ b/spec/proto_files/featureful.proto @@ -8,7 +8,7 @@ message A { }; optional string payload = 1; - required Payloads payload_type = 2; + required Payloads payload_type = 2 [default = P1]; message SubSub { optional string subsub_payload = 1; diff --git a/spec/runtime_spec.rb b/spec/runtime_spec.rb old mode 100755 new mode 100644 index df8117f..2c04959 --- a/spec/runtime_spec.rb +++ b/spec/runtime_spec.rb @@ -1,4 +1,4 @@ -#!/usr/bin/env ruby +require File.expand_path(File.dirname(__FILE__) + '/spec_helper') require 'stringio' diff --git a/spec/spec.opts b/spec/spec.opts new file mode 100644 index 0000000..4e1e0d2 --- /dev/null +++ b/spec/spec.opts @@ -0,0 +1 @@ +--color diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..531ae94 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,8 @@ +$LOAD_PATH.unshift(File.dirname(__FILE__)) +$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) +require 'protocol_buffers' +require 'spec' +require 'spec/autorun' + +Spec::Runner.configure do |config| +end