27
27
snippet~~~~
28
28
END
29
29
30
- ORIGINAL_CONTENTS = <<END
31
- var mod = angular.module( 'coffeetech', [] )
32
- mod.controller( 'ShopsCtrl', function( $scope ) {
33
- var github = new Github({} );
34
- var repo = github.getRepo( "xrd", "spa.coffeete.ch" );
35
- repo.contents( "gh-pages", "portland.json", function(err, data) {
36
- $scope.shops = JSON.parse( data );
37
- $scope.$digest();
38
- }, false );
39
- })
40
- END
41
-
42
30
LOTS_OF_IDENTIFIERS = <<END
43
31
44
32
[filename="spec/fixtures/coffeetech.js", language="js"]
88
76
89
77
END
90
78
79
+ FLATTEN_WITH_SPACES = <<END
80
+ [filename="spec/fixtures/with_spaces.rb", language="ruby", flatten="true", lines="1..3"]
81
+ snippet~~~~
82
+ Put any descriptive text you want here. It will be replaced with the
83
+ specified code snippet when you build ebook outputs
84
+ snippet~~~~
85
+ END
86
+
87
+ FLATTEN_NO_LINE_NUMBERS = <<END
88
+ [filename="spec/fixtures/with_tabs.rb", language="ruby", flatten="true"]
89
+ snippet~~~~
90
+ Put any descriptive text you want here. It will be replaced with the
91
+ specified code snippet when you build ebook outputs
92
+ snippet~~~~
93
+ END
94
+
95
+ FLATTEN_WITH_TABS = <<END
96
+ [filename="spec/fixtures/with_tabs.rb", language="ruby", flatten="true", lines="1..3"]
97
+ snippet~~~~
98
+ Put any descriptive text you want here. It will be replaced with the
99
+ specified code snippet when you build ebook outputs
100
+ snippet~~~~
101
+ END
102
+
91
103
def download_test_repository
92
104
root = File . join ( "spec" , TEST_REPO )
93
105
unless File . exists? root
@@ -124,6 +136,7 @@ def download_test_repository
124
136
output = outputs [ 0 ]
125
137
output [ :sha ] . should == "c863f786f5959799d7c:test.js"
126
138
end
139
+
127
140
end
128
141
129
142
# describe "#scrub_other_identifiers" do
@@ -150,6 +163,30 @@ def download_test_repository
150
163
output . should_not match ( /END FACTORIAL_FUNC/ )
151
164
end
152
165
166
+ describe "#flatten" do
167
+ before ( :each ) do
168
+ @with_spaces = File . read ( "spec/fixtures/with_spaces.rb" )
169
+ @with_tabs = File . read ( "spec/fixtures/with_tabs.rb" )
170
+ @spaces_flattened = @with_spaces . split ( "\n " ) [ 0 ..3 ] . join ( "\n " ) . gsub ( /^ / , "" )
171
+ @tabs_flattened = @with_tabs . split ( "\n " ) [ 0 ..3 ] . join ( "\n " ) . gsub ( /^\t \t / , "" )
172
+ end
173
+
174
+ it "should not flatten when indentation level is zero" do
175
+ output = Oreilly ::Snippets . process ( FLATTEN_NO_LINE_NUMBERS )
176
+ output
177
+ end
178
+
179
+ it "should support flattening with tabs" do
180
+ output = Oreilly ::Snippets . process ( FLATTEN_WITH_TABS )
181
+ output . should == @tabs_flattened
182
+ end
183
+
184
+ it "should support flattening with spaces" do
185
+ output = Oreilly ::Snippets . process ( FLATTEN_WITH_SPACES )
186
+ output . should == @spaces_flattened
187
+ end
188
+ end
189
+
153
190
# NYI
154
191
# it "should remove all identifiers when processing" do
155
192
# output = Oreilly::Snippets.process( LOTS_OF_IDENTIFIERS )
@@ -169,22 +206,19 @@ def download_test_repository
169
206
170
207
it "should retrieve by SHA and give us only certain lines" do
171
208
output = Oreilly ::Snippets . process ( WITH_SHA_LINE_NUMBERS )
172
- cwd = Dir . getwd
173
- Dir . chdir File . join ( ROOT )
174
- original = `git show c863f786f5959799d7c11312a7ba1d603ff16339:test.js`
175
- Dir . chdir cwd
209
+ original = nil
210
+ Dir . chdir File . join ( ROOT ) do
211
+ original = `git show c863f786f5959799d7c11312a7ba1d603ff16339:test.js`
212
+ end
176
213
lines = original . split /\n /
177
- original = lines [ 0 ..2 ] . join "\n "
178
- output . strip . should == original . strip
214
+ original = lines [ 0 ..2 ] . join ( " \n " ) + "\n "
215
+ output . should == original
179
216
end
180
217
181
218
it "should indicate placeholder if using xxx as the sha" do
182
219
output = Oreilly ::Snippets . process ( WITH_PLACEHOLDER_SHA )
183
220
output . should match ( /PLACEHOLDER/ )
184
221
end
185
222
end
186
-
187
-
188
-
189
223
end
190
224
end
0 commit comments