Changeset 01a3332bfe0a


Ignore:
Timestamp:
01/21/11 19:41:16 (16 months ago)
Author:
Mahlon E. Smith <mahlon@…>
Branch:
ruby-modules
Message:

Bump Chunker to 1.0.0 (release), updates for rspec 2.

Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • chunker/Rakefile

    r3 r4  
    11#!/usr/bin/env rake 
    2 # 
    3 # Chunker Rakefile 
    42# 
    53 
     
    86 
    97require 'rake' 
    10 require 'spec' 
    11 require 'rake/testtask' 
     8require 'rspec' 
     9require 'rspec/core/rake_task' 
    1210require 'rake/packagetask' 
    1311require 'rake/gempackagetask' 
    14 require 'spec/rake/spectask' 
    1512require 'rubygems/installer' 
    1613require 'rubygems/uninstaller' 
     
    2623 
    2724SPECDIR    = BASEDIR + 'spec' 
    28 SPEC_FILES = Pathname.glob( SPECDIR + '**/*_spec.rb' ).reject {|f| f =~ /^\.svn/ } 
     25SPEC_FILES = Pathname.glob( SPECDIR + '**/*_spec.rb' ) 
    2926 
    3027LIBDIR    = BASEDIR + 'lib' 
    31 LIB_FILES = Pathname.glob( LIBDIR + '**/*.rb').reject {|i| i =~ /\.svn/ } 
     28LIB_FILES = Pathname.glob( LIBDIR + '**/*.rb') 
    3229 
    3330RELEASE_FILES = TEXT_FILES + LIB_FILES + SPEC_FILES 
     
    5754 
    5855PKG_NAME      = 'chunker' 
    59 PKG_VERSION   = find_pattern( LIBDIR + 'chunker.rb', /VERSION = ['"](\d\.\d(?:\/\d)?)['"]/ ) 
    60 PKG_REVISION  = find_pattern( LIBDIR + 'chunker.rb', /SVNRev = .+Rev: (\d+)/ ) 
    61 PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}.#{PKG_REVISION}" 
     56PKG_VERSION   = find_pattern( LIBDIR + 'chunker.rb', /VERSION = ['"](.+)['"]/ ) 
     57PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}" 
    6258 
    6359 
     
    6662###################################################################### 
    6763 
    68 task :default => [ :test, :package ] 
     64task :test    => 'test:spec' 
     65task :default => :test 
     66# task :default => [ :test, :package ] 
    6967 
     68namespace :test do 
     69    desc 'Generate verbose and pretty output' 
     70    RSpec::Core::RakeTask.new( :spec ) do |task| 
     71        task.pattern = SPEC_FILES 
     72        task.rspec_opts  = ['-b', '-fd', '-c'] 
     73    end 
    7074 
    71 ### Task: run rspec tests 
    72 ### 
    73 desc "Run tests" 
    74 Spec::Rake::SpecTask.new('test') do |task| 
    75     task.spec_files = SPEC_FILES 
    76     task.spec_opts  = %w{ -c -fs } 
     75    desc 'Generate quiet non-colored plain-text output' 
     76    RSpec::Core::RakeTask.new( :quiet ) do |task| 
     77        task.pattern = SPEC_FILES 
     78        task.rspec_opts  = ['-f', 'p'] 
     79    end 
    7780end 
    78  
    7981 
    8082### Task: generate ctags 
     
    9092### 
    9193gem = Gem::Specification.new do |gem| 
    92     pkg_build = PKG_REVISION || 0 
    93  
    9494    gem.summary           = "A convenience library for parsing __END__ tokens consistently." 
    9595    gem.name              = PKG_NAME 
    96     gem.version           = "%s.%s" % [ PKG_VERSION, pkg_build ] 
     96    gem.version           = PKG_VERSION 
    9797    gem.author            = 'Mahlon E. Smith' 
    9898    gem.email             = 'mahlon@martini.nu' 
    9999    gem.homepage          = 'http://projects.martini.nu/ruby-modules/wiki/Chunker' 
    100     gem.rubyforge_project = 'mahlon' 
    101100    gem.has_rdoc          = true 
    102101 
  • chunker/lib/chunker.rb

    r2 r4  
    1 #!/usr/bin/ruby 
     1# vim: set nosta noet ts=4 sw=4: 
     2 
     3require 'strscan' 
     4require 'stringio' 
     5 
    26# 
    37# Chunker: A convenience library for parsing __END__ tokens consistently. 
     
    1822module Chunker 
    1923 
    20     require 'strscan' 
    21     require 'stringio' 
     24    # VCS Revision 
     25    VCSRev = %q$Rev$ 
    2226 
    23     # SVN Revision 
    24     # 
    25     SVNRev = %q$Rev$ 
    26  
    27     # SVN Id 
    28     # 
    29     SVNId = %q$Id$ 
     27    # VCS Id 
     28    VCSId = %q$Id$ 
    3029 
    3130    # Package version 
    32     # 
    33     VERSION = '0.1' 
     31    VERSION = '1.0.0' 
    3432 
    3533 
     
    4139 
    4240        # The mark for a DATA block. 
    43         # 
    4441        END_TOKEN = /^__END__\r?\n/ 
    4542 
    4643        # The mark for a 'sub' block. 
    47         # 
    4844        CHUNK_TOKEN = /^__([A-Z\_0-9]+)__\r?\n/ 
    4945 
     
    6056            io.close 
    6157 
     58            # put each chunk into its own constant 
     59            # 
    6260            if @scanner.check_until( CHUNK_TOKEN ) 
    63                 # put each chunk into its own constant 
    6461                self.extract_blocks 
     62 
     63            # no sub blocks, put the whole mess into DATA_END 
     64            # 
    6565            else 
    66                 # no sub blocks, put the whole mess into DATA_END 
    6766                @klass.const_set( :DATA_END, StringIO.new( end_string ) ) 
    6867            end 
     
    9493                    label = @scanner[1] 
    9594 
     95                    # Pull the next token text out of the data, set up the next pass 
     96                    # 
    9697                    if data = @scanner.scan_until( CHUNK_TOKEN ) 
    97                         # Pull the next token text out of the data, set up the next pass 
    98                         # 
    99                         data         = data[ 0, data.length - @scanner[0].length ] 
     98                        data = data[ 0, data.length - @scanner[0].length ] 
    10099                        @scanner.pos = self.next_position 
     100 
     101                    # No additional blocks 
     102                    # 
    101103                    else 
    102                         # No additional blocks 
    103                         # 
    104104                        data = @scanner.rest 
    105105                    end 
     
    107107 
    108108                # Add the IO constant to the class that included me. 
    109                 # 
    110109                @klass.const_set( "DATA_#{label}".to_sym, StringIO.new( data ) ) 
    111110            end 
     
    127126        # klass.instance_eval{ __FILE__ }   awww, nope. 
    128127        # __FILE__ won't work here, so we find the filename via caller(). 
    129         # 
    130128        io = File.open( caller(1).last.sub(/:.*?$/, ''), 'r' ) 
    131129 
  • chunker/spec/chunker_spec.rb

    r2 r4  
    1 #!/usr/bin/env ruby 
     1# vim: set nosta noet ts=4 sw=4 ft=rspec: 
    22 
    33BEGIN { 
     
    99} 
    1010 
     11require 'rspec' 
    1112require 'chunker' 
    12 require 'rubygems' 
    13 require 'spec' 
    1413 
    1514ENDSTUFF = <<ENDSTUFF 
     
    6665 
    6766 
    68 describe Chunker::DataParser do 
     67describe Chunker do 
    6968 
    70     it "doesn't include content above the __END__ token" do 
    71         klass = Class.new 
    72         dp = Chunker::DataParser.new( klass, StringIO.new( FILE_TEXT_MULTIPLE )) 
    73         dp.instance_variable_get( :@scanner ).string. 
    74             should_not =~ /This is stuff we shouldn't see/ 
     69    describe Chunker::DataParser do 
     70 
     71        it "doesn't include content above the __END__ token" do 
     72            klass = Class.new 
     73            dp = Chunker::DataParser.new( klass, StringIO.new( FILE_TEXT_MULTIPLE )) 
     74            dp.instance_variable_get( :@scanner ).string. 
     75                should_not =~ /This is stuff we shouldn't see/ 
     76        end 
     77 
     78        it "doesn't contain the __END__ token itself" do 
     79            klass = Class.new 
     80            dp = Chunker::DataParser.new( klass, StringIO.new( FILE_TEXT )) 
     81            dp.instance_variable_get( :@scanner ).string.should_not =~ /^__END__/ 
     82        end 
    7583    end 
    7684 
    77     it "doesn't contain the __END__ token itself" do 
    78         klass = Class.new 
    79         dp = Chunker::DataParser.new( klass, StringIO.new( FILE_TEXT )) 
    80         dp.instance_variable_get( :@scanner ).string.should_not =~ /^__END__/ 
     85 
     86    context 'when included from another class' do 
     87 
     88        it "has all content in DATA_END if there are no sub blocks" do 
     89            File.stub!( :open ).and_return( StringIO.new( FILE_TEXT )) 
     90            klass = Class.new { include Chunker } 
     91 
     92            klass.constants.should_not include( 'DATA_POOP' ) 
     93            klass.constants.should_not include( 'DATA_HURRRRG' ) 
     94            klass.constants.should_not include( 'DATA_HURGADURGA' ) 
     95            klass.constants.should include( 'DATA_END' ) 
     96        end 
     97 
     98        it "separates data sub blocks into individual constants" do 
     99            File.stub!( :open ).and_return( StringIO.new( FILE_TEXT_MULTIPLE )) 
     100            klass = Class.new { include Chunker } 
     101 
     102            klass.constants.should include( 'DATA_END' ) 
     103            klass.constants.should include( 'DATA_POOP' ) 
     104            klass.constants.should include( 'DATA_HURRRRG' ) 
     105            klass.constants.should include( 'DATA_HURGADURGA' ) 
     106        end 
     107 
     108        it "has IO constants that contain the data block contents" do 
     109            File.stub!( :open ).and_return( StringIO.new( FILE_TEXT_MULTIPLE )) 
     110            klass = Class.new { include Chunker } 
     111 
     112            klass.const_get( :DATA_END ).read.chomp.should        == ENDSTUFF 
     113            klass.const_get( :DATA_POOP ).read.chomp.should       == POOP 
     114            klass.const_get( :DATA_HURRRRG ).read.chomp.should    == HURRRRG 
     115            klass.const_get( :DATA_HURGADURGA ).read.chomp.should == HURGADURGA 
     116        end 
    81117    end 
    82118end 
    83  
    84  
    85 describe 'A class that includes Chunker' do 
    86  
    87     it "has all content in DATA_END if there are no sub blocks" do 
    88         File.stub!( :open ).and_return( StringIO.new( FILE_TEXT )) 
    89         klass = Class.new { include Chunker } 
    90  
    91         klass.constants.should_not include( 'DATA_POOP' ) 
    92         klass.constants.should_not include( 'DATA_HURRRRG' ) 
    93         klass.constants.should_not include( 'DATA_HURGADURGA' ) 
    94         klass.constants.should include( 'DATA_END' ) 
    95     end 
    96  
    97     it "separates data sub blocks into individual constants" do 
    98         File.stub!( :open ).and_return( StringIO.new( FILE_TEXT_MULTIPLE )) 
    99         klass = Class.new { include Chunker } 
    100  
    101         klass.constants.should include( 'DATA_END' ) 
    102         klass.constants.should include( 'DATA_POOP' ) 
    103         klass.constants.should include( 'DATA_HURRRRG' ) 
    104         klass.constants.should include( 'DATA_HURGADURGA' ) 
    105     end 
    106  
    107     it "has IO constants that contain the data block contents" do 
    108         File.stub!( :open ).and_return( StringIO.new( FILE_TEXT_MULTIPLE )) 
    109         klass = Class.new { include Chunker } 
    110  
    111         klass.const_get( :DATA_END ).read.chomp.should        == ENDSTUFF 
    112         klass.const_get( :DATA_POOP ).read.chomp.should       == POOP 
    113         klass.const_get( :DATA_HURRRRG ).read.chomp.should    == HURRRRG 
    114         klass.const_get( :DATA_HURGADURGA ).read.chomp.should == HURGADURGA 
    115     end 
    116 end 
    117  
Note: See TracChangeset for help on using the changeset viewer.