author | Mahlon E. Smith <mahlon@martini.nu> |
Wed, 06 Jan 2016 14:36:04 -0800 | |
branch | ruby-modules |
changeset 9 | bab54dae339a |
parent 4 | chunker/spec/chunker_spec.rb@01a3332bfe0a |
permissions | -rw-r--r-- |
4
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
2
diff
changeset
|
1 |
# vim: set nosta noet ts=4 sw=4 ft=rspec: |
1
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
2 |
|
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
3 |
BEGIN { |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
4 |
require 'pathname' |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
5 |
basedir = Pathname.new( __FILE__ ).dirname.parent |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
6 |
libdir = basedir + "lib" |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
7 |
|
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
8 |
$LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir ) |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
9 |
} |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
10 |
|
4
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
2
diff
changeset
|
11 |
require 'rspec' |
1
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
12 |
require 'chunker' |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
13 |
|
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
14 |
ENDSTUFF = <<ENDSTUFF |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
15 |
Stuff within the end block. |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
16 |
|
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
17 |
Content of the END block |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
18 |
Content of the END block |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
19 |
Content of the END block |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
20 |
Content of the END block |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
21 |
ENDSTUFF |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
22 |
|
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
23 |
HURGADURGA = <<HURGADURGA |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
24 |
|
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
25 |
Content of the HURGADURGA block |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
26 |
Content of the HURGADURGA block |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
27 |
Content of the HURGADURGA block |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
28 |
Content of the HURGADURGA block |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
29 |
|
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
30 |
HURGADURGA |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
31 |
|
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
32 |
HURRRRG = <<HURRRRG |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
33 |
123123123 123123123 123123123 |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
34 |
123123123 123123123 123123123 |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
35 |
123123123 123123123 123123123 |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
36 |
HURRRRG |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
37 |
|
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
38 |
POOP = <<POOP |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
39 |
Content of the POOP block |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
40 |
POOP |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
41 |
|
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
42 |
FILE_TEXT = <<EO_FILE_TEXT |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
43 |
|
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
44 |
This is stuff we shouldn't see or care about. |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
45 |
You know, stuff like code, presumably. |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
46 |
|
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
47 |
__END__ |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
48 |
#{ENDSTUFF} |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
49 |
EO_FILE_TEXT |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
50 |
|
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
51 |
FILE_TEXT_MULTIPLE = <<EO_FILE_TEXT |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
52 |
|
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
53 |
This is stuff we shouldn't see or care about. |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
54 |
You know, stuff like code, presumably. |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
55 |
|
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
56 |
__END__ |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
57 |
#{ENDSTUFF} |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
58 |
__POOP__ |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
59 |
#{POOP} |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
60 |
__HURRRRG__ |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
61 |
#{HURRRRG} |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
62 |
__HURGADURGA__ |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
63 |
#{HURGADURGA} |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
64 |
EO_FILE_TEXT |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
65 |
|
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
66 |
|
4
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
2
diff
changeset
|
67 |
describe Chunker do |
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
2
diff
changeset
|
68 |
|
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
2
diff
changeset
|
69 |
describe Chunker::DataParser do |
1
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
70 |
|
4
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
2
diff
changeset
|
71 |
it "doesn't include content above the __END__ token" do |
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
2
diff
changeset
|
72 |
klass = Class.new |
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
2
diff
changeset
|
73 |
dp = Chunker::DataParser.new( klass, StringIO.new( FILE_TEXT_MULTIPLE )) |
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
2
diff
changeset
|
74 |
dp.instance_variable_get( :@scanner ).string. |
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
2
diff
changeset
|
75 |
should_not =~ /This is stuff we shouldn't see/ |
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
2
diff
changeset
|
76 |
end |
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
2
diff
changeset
|
77 |
|
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
2
diff
changeset
|
78 |
it "doesn't contain the __END__ token itself" do |
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
2
diff
changeset
|
79 |
klass = Class.new |
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
2
diff
changeset
|
80 |
dp = Chunker::DataParser.new( klass, StringIO.new( FILE_TEXT )) |
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
2
diff
changeset
|
81 |
dp.instance_variable_get( :@scanner ).string.should_not =~ /^__END__/ |
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
2
diff
changeset
|
82 |
end |
1
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
83 |
end |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
84 |
|
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
85 |
|
4
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
2
diff
changeset
|
86 |
context 'when included from another class' do |
1
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
87 |
|
4
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
2
diff
changeset
|
88 |
it "has all content in DATA_END if there are no sub blocks" do |
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
2
diff
changeset
|
89 |
File.stub!( :open ).and_return( StringIO.new( FILE_TEXT )) |
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
2
diff
changeset
|
90 |
klass = Class.new { include Chunker } |
1
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
91 |
|
4
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
2
diff
changeset
|
92 |
klass.constants.should_not include( 'DATA_POOP' ) |
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
2
diff
changeset
|
93 |
klass.constants.should_not include( 'DATA_HURRRRG' ) |
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
2
diff
changeset
|
94 |
klass.constants.should_not include( 'DATA_HURGADURGA' ) |
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
2
diff
changeset
|
95 |
klass.constants.should include( 'DATA_END' ) |
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
2
diff
changeset
|
96 |
end |
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
2
diff
changeset
|
97 |
|
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
2
diff
changeset
|
98 |
it "separates data sub blocks into individual constants" do |
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
2
diff
changeset
|
99 |
File.stub!( :open ).and_return( StringIO.new( FILE_TEXT_MULTIPLE )) |
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
2
diff
changeset
|
100 |
klass = Class.new { include Chunker } |
1
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
101 |
|
4
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
2
diff
changeset
|
102 |
klass.constants.should include( 'DATA_END' ) |
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
2
diff
changeset
|
103 |
klass.constants.should include( 'DATA_POOP' ) |
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
2
diff
changeset
|
104 |
klass.constants.should include( 'DATA_HURRRRG' ) |
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
2
diff
changeset
|
105 |
klass.constants.should include( 'DATA_HURGADURGA' ) |
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
2
diff
changeset
|
106 |
end |
1
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
107 |
|
4
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
2
diff
changeset
|
108 |
it "has IO constants that contain the data block contents" do |
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
2
diff
changeset
|
109 |
File.stub!( :open ).and_return( StringIO.new( FILE_TEXT_MULTIPLE )) |
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
2
diff
changeset
|
110 |
klass = Class.new { include Chunker } |
1
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
111 |
|
4
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
2
diff
changeset
|
112 |
klass.const_get( :DATA_END ).read.chomp.should == ENDSTUFF |
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
2
diff
changeset
|
113 |
klass.const_get( :DATA_POOP ).read.chomp.should == POOP |
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
2
diff
changeset
|
114 |
klass.const_get( :DATA_HURRRRG ).read.chomp.should == HURRRRG |
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
2
diff
changeset
|
115 |
klass.const_get( :DATA_HURGADURGA ).read.chomp.should == HURGADURGA |
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
2
diff
changeset
|
116 |
end |
1
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
117 |
end |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
118 |
end |