Bump Chunker to 1.0.0 (release), updates for rspec 2.
This commit is contained in:
parent
935090c21b
commit
6667792230
5 changed files with 94 additions and 93 deletions
1
.hgignore
Normal file
1
.hgignore
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
^chunker/pkg
|
||||||
2
chunker/.rspec
Normal file
2
chunker/.rspec
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
-r ~/.vim/bundle/specky/ruby/specky_formatter
|
||||||
|
-f SpeckyFormatter
|
||||||
|
|
@ -1,17 +1,14 @@
|
||||||
#!/usr/bin/env rake
|
#!/usr/bin/env rake
|
||||||
#
|
#
|
||||||
# Chunker Rakefile
|
|
||||||
#
|
|
||||||
|
|
||||||
require 'rubygems'
|
require 'rubygems'
|
||||||
require 'pathname'
|
require 'pathname'
|
||||||
|
|
||||||
require 'rake'
|
require 'rake'
|
||||||
require 'spec'
|
require 'rspec'
|
||||||
require 'rake/testtask'
|
require 'rspec/core/rake_task'
|
||||||
require 'rake/packagetask'
|
require 'rake/packagetask'
|
||||||
require 'rake/gempackagetask'
|
require 'rake/gempackagetask'
|
||||||
require 'spec/rake/spectask'
|
|
||||||
require 'rubygems/installer'
|
require 'rubygems/installer'
|
||||||
require 'rubygems/uninstaller'
|
require 'rubygems/uninstaller'
|
||||||
|
|
||||||
|
|
@ -25,10 +22,10 @@ BASEDIR = Pathname.new( __FILE__ ).expand_path.dirname.relative_path_from( Pathn
|
||||||
TEXT_FILES = %w{ Rakefile README LICENSE }.collect {|f| BASEDIR + f }
|
TEXT_FILES = %w{ Rakefile README LICENSE }.collect {|f| BASEDIR + f }
|
||||||
|
|
||||||
SPECDIR = BASEDIR + 'spec'
|
SPECDIR = BASEDIR + 'spec'
|
||||||
SPEC_FILES = Pathname.glob( SPECDIR + '**/*_spec.rb' ).reject {|f| f =~ /^\.svn/ }
|
SPEC_FILES = Pathname.glob( SPECDIR + '**/*_spec.rb' )
|
||||||
|
|
||||||
LIBDIR = BASEDIR + 'lib'
|
LIBDIR = BASEDIR + 'lib'
|
||||||
LIB_FILES = Pathname.glob( LIBDIR + '**/*.rb').reject {|i| i =~ /\.svn/ }
|
LIB_FILES = Pathname.glob( LIBDIR + '**/*.rb')
|
||||||
|
|
||||||
RELEASE_FILES = TEXT_FILES + LIB_FILES + SPEC_FILES
|
RELEASE_FILES = TEXT_FILES + LIB_FILES + SPEC_FILES
|
||||||
|
|
||||||
|
|
@ -56,27 +53,32 @@ end
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
||||||
PKG_NAME = 'chunker'
|
PKG_NAME = 'chunker'
|
||||||
PKG_VERSION = find_pattern( LIBDIR + 'chunker.rb', /VERSION = ['"](\d\.\d(?:\/\d)?)['"]/ )
|
PKG_VERSION = find_pattern( LIBDIR + 'chunker.rb', /VERSION = ['"](.+)['"]/ )
|
||||||
PKG_REVISION = find_pattern( LIBDIR + 'chunker.rb', /SVNRev = .+Rev: (\d+)/ )
|
PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
|
||||||
PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}.#{PKG_REVISION}"
|
|
||||||
|
|
||||||
|
|
||||||
######################################################################
|
######################################################################
|
||||||
### T A S K S
|
### T A S K S
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
||||||
task :default => [ :test, :package ]
|
task :test => 'test:spec'
|
||||||
|
task :default => :test
|
||||||
|
# task :default => [ :test, :package ]
|
||||||
|
|
||||||
|
namespace :test do
|
||||||
|
desc 'Generate verbose and pretty output'
|
||||||
|
RSpec::Core::RakeTask.new( :spec ) do |task|
|
||||||
|
task.pattern = SPEC_FILES
|
||||||
|
task.rspec_opts = ['-b', '-fd', '-c']
|
||||||
|
end
|
||||||
|
|
||||||
### Task: run rspec tests
|
desc 'Generate quiet non-colored plain-text output'
|
||||||
###
|
RSpec::Core::RakeTask.new( :quiet ) do |task|
|
||||||
desc "Run tests"
|
task.pattern = SPEC_FILES
|
||||||
Spec::Rake::SpecTask.new('test') do |task|
|
task.rspec_opts = ['-f', 'p']
|
||||||
task.spec_files = SPEC_FILES
|
end
|
||||||
task.spec_opts = %w{ -c -fs }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
### Task: generate ctags
|
### Task: generate ctags
|
||||||
### This assumes exuberant ctags, since ctags 'native' doesn't support ruby anyway.
|
### This assumes exuberant ctags, since ctags 'native' doesn't support ruby anyway.
|
||||||
###
|
###
|
||||||
|
|
@ -89,15 +91,12 @@ end
|
||||||
### Task: Create gem from source
|
### Task: Create gem from source
|
||||||
###
|
###
|
||||||
gem = Gem::Specification.new do |gem|
|
gem = Gem::Specification.new do |gem|
|
||||||
pkg_build = PKG_REVISION || 0
|
|
||||||
|
|
||||||
gem.summary = "A convenience library for parsing __END__ tokens consistently."
|
gem.summary = "A convenience library for parsing __END__ tokens consistently."
|
||||||
gem.name = PKG_NAME
|
gem.name = PKG_NAME
|
||||||
gem.version = "%s.%s" % [ PKG_VERSION, pkg_build ]
|
gem.version = PKG_VERSION
|
||||||
gem.author = 'Mahlon E. Smith'
|
gem.author = 'Mahlon E. Smith'
|
||||||
gem.email = 'mahlon@martini.nu'
|
gem.email = 'mahlon@martini.nu'
|
||||||
gem.homepage = 'http://projects.martini.nu/ruby-modules/wiki/Chunker'
|
gem.homepage = 'http://projects.martini.nu/ruby-modules/wiki/Chunker'
|
||||||
gem.rubyforge_project = 'mahlon'
|
|
||||||
gem.has_rdoc = true
|
gem.has_rdoc = true
|
||||||
|
|
||||||
gem.files = RELEASE_FILES.
|
gem.files = RELEASE_FILES.
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,8 @@
|
||||||
#!/usr/bin/ruby
|
# vim: set nosta noet ts=4 sw=4:
|
||||||
|
|
||||||
|
require 'strscan'
|
||||||
|
require 'stringio'
|
||||||
|
|
||||||
#
|
#
|
||||||
# Chunker: A convenience library for parsing __END__ tokens consistently.
|
# Chunker: A convenience library for parsing __END__ tokens consistently.
|
||||||
#
|
#
|
||||||
|
|
@ -17,20 +21,14 @@
|
||||||
###
|
###
|
||||||
module Chunker
|
module Chunker
|
||||||
|
|
||||||
require 'strscan'
|
# VCS Revision
|
||||||
require 'stringio'
|
VCSRev = %q$Rev$
|
||||||
|
|
||||||
# SVN Revision
|
# VCS Id
|
||||||
#
|
VCSId = %q$Id$
|
||||||
SVNRev = %q$Rev$
|
|
||||||
|
|
||||||
# SVN Id
|
|
||||||
#
|
|
||||||
SVNId = %q$Id$
|
|
||||||
|
|
||||||
# Package version
|
# Package version
|
||||||
#
|
VERSION = '1.0.0'
|
||||||
VERSION = '0.1'
|
|
||||||
|
|
||||||
|
|
||||||
### Parser class for __END__ data blocks.
|
### Parser class for __END__ data blocks.
|
||||||
|
|
@ -40,11 +38,9 @@ module Chunker
|
||||||
class DataParser
|
class DataParser
|
||||||
|
|
||||||
# The mark for a DATA block.
|
# The mark for a DATA block.
|
||||||
#
|
|
||||||
END_TOKEN = /^__END__\r?\n/
|
END_TOKEN = /^__END__\r?\n/
|
||||||
|
|
||||||
# The mark for a 'sub' block.
|
# The mark for a 'sub' block.
|
||||||
#
|
|
||||||
CHUNK_TOKEN = /^__([A-Z\_0-9]+)__\r?\n/
|
CHUNK_TOKEN = /^__([A-Z\_0-9]+)__\r?\n/
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -59,11 +55,14 @@ module Chunker
|
||||||
@scanner = StringScanner.new( end_string )
|
@scanner = StringScanner.new( end_string )
|
||||||
io.close
|
io.close
|
||||||
|
|
||||||
if @scanner.check_until( CHUNK_TOKEN )
|
|
||||||
# put each chunk into its own constant
|
# put each chunk into its own constant
|
||||||
|
#
|
||||||
|
if @scanner.check_until( CHUNK_TOKEN )
|
||||||
self.extract_blocks
|
self.extract_blocks
|
||||||
else
|
|
||||||
# no sub blocks, put the whole mess into DATA_END
|
# no sub blocks, put the whole mess into DATA_END
|
||||||
|
#
|
||||||
|
else
|
||||||
@klass.const_set( :DATA_END, StringIO.new( end_string ) )
|
@klass.const_set( :DATA_END, StringIO.new( end_string ) )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -93,20 +92,20 @@ module Chunker
|
||||||
else
|
else
|
||||||
label = @scanner[1]
|
label = @scanner[1]
|
||||||
|
|
||||||
if data = @scanner.scan_until( CHUNK_TOKEN )
|
|
||||||
# Pull the next token text out of the data, set up the next pass
|
# Pull the next token text out of the data, set up the next pass
|
||||||
#
|
#
|
||||||
|
if data = @scanner.scan_until( CHUNK_TOKEN )
|
||||||
data = data[ 0, data.length - @scanner[0].length ]
|
data = data[ 0, data.length - @scanner[0].length ]
|
||||||
@scanner.pos = self.next_position
|
@scanner.pos = self.next_position
|
||||||
else
|
|
||||||
# No additional blocks
|
# No additional blocks
|
||||||
#
|
#
|
||||||
|
else
|
||||||
data = @scanner.rest
|
data = @scanner.rest
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Add the IO constant to the class that included me.
|
# Add the IO constant to the class that included me.
|
||||||
#
|
|
||||||
@klass.const_set( "DATA_#{label}".to_sym, StringIO.new( data ) )
|
@klass.const_set( "DATA_#{label}".to_sym, StringIO.new( data ) )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -126,7 +125,6 @@ module Chunker
|
||||||
def self.included( klass )
|
def self.included( klass )
|
||||||
# klass.instance_eval{ __FILE__ } awww, nope.
|
# klass.instance_eval{ __FILE__ } awww, nope.
|
||||||
# __FILE__ won't work here, so we find the filename via caller().
|
# __FILE__ won't work here, so we find the filename via caller().
|
||||||
#
|
|
||||||
io = File.open( caller(1).last.sub(/:.*?$/, ''), 'r' )
|
io = File.open( caller(1).last.sub(/:.*?$/, ''), 'r' )
|
||||||
|
|
||||||
DataParser.new( klass, io )
|
DataParser.new( klass, io )
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/env ruby
|
# vim: set nosta noet ts=4 sw=4 ft=rspec:
|
||||||
|
|
||||||
BEGIN {
|
BEGIN {
|
||||||
require 'pathname'
|
require 'pathname'
|
||||||
|
|
@ -8,9 +8,8 @@ BEGIN {
|
||||||
$LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir )
|
$LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
require 'rspec'
|
||||||
require 'chunker'
|
require 'chunker'
|
||||||
require 'rubygems'
|
|
||||||
require 'spec'
|
|
||||||
|
|
||||||
ENDSTUFF = <<ENDSTUFF
|
ENDSTUFF = <<ENDSTUFF
|
||||||
Stuff within the end block.
|
Stuff within the end block.
|
||||||
|
|
@ -65,7 +64,9 @@ __HURGADURGA__
|
||||||
EO_FILE_TEXT
|
EO_FILE_TEXT
|
||||||
|
|
||||||
|
|
||||||
describe Chunker::DataParser do
|
describe Chunker do
|
||||||
|
|
||||||
|
describe Chunker::DataParser do
|
||||||
|
|
||||||
it "doesn't include content above the __END__ token" do
|
it "doesn't include content above the __END__ token" do
|
||||||
klass = Class.new
|
klass = Class.new
|
||||||
|
|
@ -79,10 +80,10 @@ describe Chunker::DataParser do
|
||||||
dp = Chunker::DataParser.new( klass, StringIO.new( FILE_TEXT ))
|
dp = Chunker::DataParser.new( klass, StringIO.new( FILE_TEXT ))
|
||||||
dp.instance_variable_get( :@scanner ).string.should_not =~ /^__END__/
|
dp.instance_variable_get( :@scanner ).string.should_not =~ /^__END__/
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
describe 'A class that includes Chunker' do
|
context 'when included from another class' do
|
||||||
|
|
||||||
it "has all content in DATA_END if there are no sub blocks" do
|
it "has all content in DATA_END if there are no sub blocks" do
|
||||||
File.stub!( :open ).and_return( StringIO.new( FILE_TEXT ))
|
File.stub!( :open ).and_return( StringIO.new( FILE_TEXT ))
|
||||||
|
|
@ -113,5 +114,5 @@ describe 'A class that includes Chunker' do
|
||||||
klass.const_get( :DATA_HURRRRG ).read.chomp.should == HURRRRG
|
klass.const_get( :DATA_HURRRRG ).read.chomp.should == HURRRRG
|
||||||
klass.const_get( :DATA_HURGADURGA ).read.chomp.should == HURGADURGA
|
klass.const_get( :DATA_HURGADURGA ).read.chomp.should == HURGADURGA
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue