chunker/spec/chunker_spec.rb
branchruby-modules
changeset 4 01a3332bfe0a
parent 2 e5c705047540
--- a/chunker/spec/chunker_spec.rb	Thu Jun 04 17:28:02 2009 +0000
+++ b/chunker/spec/chunker_spec.rb	Fri Jan 21 19:41:16 2011 -0800
@@ -1,4 +1,4 @@
-#!/usr/bin/env ruby
+# vim: set nosta noet ts=4 sw=4 ft=rspec:
 
 BEGIN {
 	require 'pathname'
@@ -8,9 +8,8 @@
 	$LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir )
 }
 
+require 'rspec'
 require 'chunker'
-require 'rubygems'
-require 'spec'
 
 ENDSTUFF = <<ENDSTUFF
 Stuff within the end block.
@@ -65,53 +64,55 @@
 EO_FILE_TEXT
 
 
-describe Chunker::DataParser do
+describe Chunker do
+
+	describe Chunker::DataParser do
 
-	it "doesn't include content above the __END__ token" do
-		klass = Class.new
-		dp = Chunker::DataParser.new( klass, StringIO.new( FILE_TEXT_MULTIPLE ))
-		dp.instance_variable_get( :@scanner ).string.
-			should_not =~ /This is stuff we shouldn't see/
+		it "doesn't include content above the __END__ token" do
+			klass = Class.new
+			dp = Chunker::DataParser.new( klass, StringIO.new( FILE_TEXT_MULTIPLE ))
+			dp.instance_variable_get( :@scanner ).string.
+				should_not =~ /This is stuff we shouldn't see/
+		end
+
+		it "doesn't contain the __END__ token itself" do
+			klass = Class.new
+			dp = Chunker::DataParser.new( klass, StringIO.new( FILE_TEXT ))
+			dp.instance_variable_get( :@scanner ).string.should_not =~ /^__END__/
+		end
 	end
 
-	it "doesn't contain the __END__ token itself" do
-		klass = Class.new
-		dp = Chunker::DataParser.new( klass, StringIO.new( FILE_TEXT ))
-		dp.instance_variable_get( :@scanner ).string.should_not =~ /^__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
-		File.stub!( :open ).and_return( StringIO.new( FILE_TEXT ))
-		klass = Class.new { include Chunker }
+		it "has all content in DATA_END if there are no sub blocks" do
+			File.stub!( :open ).and_return( StringIO.new( FILE_TEXT ))
+			klass = Class.new { include Chunker }
 
-		klass.constants.should_not include( 'DATA_POOP' )
-		klass.constants.should_not include( 'DATA_HURRRRG' )
-		klass.constants.should_not include( 'DATA_HURGADURGA' )
-		klass.constants.should include( 'DATA_END' )
-	end
+			klass.constants.should_not include( 'DATA_POOP' )
+			klass.constants.should_not include( 'DATA_HURRRRG' )
+			klass.constants.should_not include( 'DATA_HURGADURGA' )
+			klass.constants.should include( 'DATA_END' )
+		end
+
+		it "separates data sub blocks into individual constants" do
+			File.stub!( :open ).and_return( StringIO.new( FILE_TEXT_MULTIPLE ))
+			klass = Class.new { include Chunker }
 
-	it "separates data sub blocks into individual constants" do
-		File.stub!( :open ).and_return( StringIO.new( FILE_TEXT_MULTIPLE ))
-		klass = Class.new { include Chunker }
+			klass.constants.should include( 'DATA_END' )
+			klass.constants.should include( 'DATA_POOP' )
+			klass.constants.should include( 'DATA_HURRRRG' )
+			klass.constants.should include( 'DATA_HURGADURGA' )
+		end
 
-		klass.constants.should include( 'DATA_END' )
-		klass.constants.should include( 'DATA_POOP' )
-		klass.constants.should include( 'DATA_HURRRRG' )
-		klass.constants.should include( 'DATA_HURGADURGA' )
-	end
+		it "has IO constants that contain the data block contents" do
+			File.stub!( :open ).and_return( StringIO.new( FILE_TEXT_MULTIPLE ))
+			klass = Class.new { include Chunker }
 
-	it "has IO constants that contain the data block contents" do
-		File.stub!( :open ).and_return( StringIO.new( FILE_TEXT_MULTIPLE ))
-		klass = Class.new { include Chunker }
-
-		klass.const_get( :DATA_END ).read.chomp.should        == ENDSTUFF
-		klass.const_get( :DATA_POOP ).read.chomp.should       == POOP
-		klass.const_get( :DATA_HURRRRG ).read.chomp.should    == HURRRRG
-		klass.const_get( :DATA_HURGADURGA ).read.chomp.should == HURGADURGA
+			klass.const_get( :DATA_END ).read.chomp.should        == ENDSTUFF
+			klass.const_get( :DATA_POOP ).read.chomp.should       == POOP
+			klass.const_get( :DATA_HURRRRG ).read.chomp.should    == HURRRRG
+			klass.const_get( :DATA_HURGADURGA ).read.chomp.should == HURGADURGA
+		end
 	end
 end
-