devver-germinate 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +12 -0
- data/README.rdoc +26 -4
- data/TODO +80 -8
- data/bin/germ +162 -38
- data/examples/basic.rb +14 -9
- data/examples/short.rb +2 -0
- data/features/author-formats-article.feature +3 -3
- data/features/{author-lists-info.feature → author-lists-info.pending_feature} +3 -0
- data/features/author-publishes-article.feature +52 -0
- data/features/author-selects-hunks.feature +1 -1
- data/features/author-sets-variables.feature +88 -0
- data/features/{author-views-stuff.feature → author-views-stuff.pending_feature} +4 -0
- data/features/example_articles/escaping.txt +1 -0
- data/features/example_articles/specials.rb +3 -3
- data/features/example_output/specials.txt +9 -5
- data/features/step_definitions/germinate.rb +9 -0
- data/germinate.gemspec +3 -3
- data/lib/germinate.rb +1 -1
- data/lib/germinate/application.rb +82 -31
- data/lib/germinate/hunk.rb +20 -0
- data/lib/germinate/insertion.rb +10 -2
- data/lib/germinate/librarian.rb +129 -31
- data/lib/germinate/origin.rb +5 -0
- data/lib/germinate/pipeline.rb +2 -0
- data/lib/germinate/publisher.rb +57 -0
- data/lib/germinate/reader.rb +51 -8
- data/lib/germinate/selector.rb +18 -6
- data/lib/germinate/shared_style_attributes.rb +18 -1
- data/lib/germinate/{process.rb → shell_process.rb} +27 -8
- data/lib/germinate/shell_publisher.rb +19 -0
- data/lib/germinate/simple_publisher.rb +7 -0
- data/lib/germinate/source_file.rb +41 -0
- data/lib/germinate/text_transforms.rb +38 -9
- data/lib/germinate/transform_process.rb +25 -0
- data/lib/germinate/variable.rb +23 -0
- data/sample.rb +14 -0
- data/spec/germinate/application_spec.rb +18 -1
- data/spec/germinate/article_editor_spec.rb +3 -3
- data/spec/germinate/code_hunk_spec.rb +28 -0
- data/spec/germinate/file_hunk_spec.rb +1 -0
- data/spec/germinate/hunk_spec.rb +1 -0
- data/spec/germinate/insertion_spec.rb +2 -1
- data/spec/germinate/librarian_spec.rb +280 -85
- data/spec/germinate/pipeline_spec.rb +10 -0
- data/spec/germinate/process_spec.rb +31 -6
- data/spec/germinate/publisher_spec.rb +130 -0
- data/spec/germinate/reader_spec.rb +58 -2
- data/spec/germinate/selector_spec.rb +34 -14
- data/spec/germinate/shell_publisher_spec.rb +61 -0
- data/spec/germinate/source_file_spec.rb +99 -0
- data/spec/germinate/text_hunk_spec.rb +45 -0
- data/spec/germinate/text_transforms_spec.rb +90 -2
- data/spec/germinate/transform_process_spec.rb +50 -0
- data/spec/germinate/variable_spec.rb +14 -0
- metadata +19 -7
- data/lib/germinate/article_formatter.rb +0 -75
- data/spec/germinate/article_formatter_spec.rb +0 -153
@@ -3,6 +3,51 @@ require File.expand_path(
|
|
3
3
|
|
4
4
|
module Germinate
|
5
5
|
describe TextHunk do
|
6
|
+
before :each do
|
7
|
+
@it = TextHunk.new(["line 1", "line 2"])
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should enable insertion expansion" do
|
11
|
+
@it.should be_expand_insertions
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should enable line joining" do
|
15
|
+
@it.should be_join_lines
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should enable blank stripping" do
|
19
|
+
@it.should be_strip_blanks
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should disable comment erasure" do
|
23
|
+
@it.should_not be_erase_comments
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should enable uncommenting" do
|
27
|
+
@it.should be_uncomment
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should enable stripping right-side whitespace" do
|
31
|
+
@it.should be_rstrip_lines
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should disable bracketing" do
|
35
|
+
@it.should_not be_bracket
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should enable pipeline processing" do
|
39
|
+
@it.should be_pipeline
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should enable insertion resolution" do
|
43
|
+
@it.should be_expand_insertions
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should enable flattening nested hunks" do
|
47
|
+
@it.should be_flatten_nested
|
48
|
+
end
|
49
|
+
|
50
|
+
|
6
51
|
context "when visited by a formatter" do
|
7
52
|
before :each do
|
8
53
|
@comment_prefix = ">>"
|
@@ -6,13 +6,35 @@ module Germinate
|
|
6
6
|
|
7
7
|
Germinate::TextTransforms.methods(false).each do |transform|
|
8
8
|
describe "'#{transform}'" do
|
9
|
+
before :each do
|
10
|
+
@transform = Germinate::TextTransforms.send(transform)
|
11
|
+
end
|
12
|
+
|
9
13
|
it "should preserve hunk attributes from input to output" do
|
10
14
|
@pipeline = lambda {|h| h}
|
11
15
|
@input = Hunk.new([], :comment_prefix => "foo", :pipeline => @pipeline)
|
12
|
-
@transform = Germinate::TextTransforms.send(transform)
|
13
16
|
@output = @transform.call(@input)
|
14
17
|
@output.comment_prefix.should == @input.comment_prefix
|
15
18
|
end
|
19
|
+
|
20
|
+
unless transform == "flatten_nested"
|
21
|
+
context "given a lumpy hunk" do
|
22
|
+
before :each do
|
23
|
+
@nested_hunk = Hunk.new(["line 3", "line 4"])
|
24
|
+
@lumpy = Hunk.new([
|
25
|
+
"line 1",
|
26
|
+
@nested_hunk,
|
27
|
+
"line 2"
|
28
|
+
],
|
29
|
+
:comment_prefix => "foo")
|
30
|
+
@output = @transform.call(@lumpy)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should pass nested hunks through untouched" do
|
34
|
+
@output[1].should == @nested_hunk
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
16
38
|
end
|
17
39
|
end
|
18
40
|
|
@@ -49,7 +71,7 @@ module Germinate
|
|
49
71
|
end
|
50
72
|
|
51
73
|
it "should do nothing" do
|
52
|
-
@it.call(["# foo", " bar"]).should == ["# foo", " bar"]
|
74
|
+
@it.call(Hunk.new(["# foo", " bar"])).should == ["# foo", " bar"]
|
53
75
|
end
|
54
76
|
end
|
55
77
|
|
@@ -63,6 +85,17 @@ module Germinate
|
|
63
85
|
end
|
64
86
|
end
|
65
87
|
|
88
|
+
context "given no explicit prefix" do
|
89
|
+
before :each do
|
90
|
+
@hunk = Hunk.new([" # foo", " bar"], :comment_prefix => " # ")
|
91
|
+
@it = TextTransforms.uncomment
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should fall back on hunk's comment prefix" do
|
95
|
+
@it.call(@hunk).should == ["foo", " bar"]
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
66
99
|
end
|
67
100
|
|
68
101
|
describe "strip_blanks" do
|
@@ -81,6 +114,23 @@ module Germinate
|
|
81
114
|
end
|
82
115
|
end
|
83
116
|
|
117
|
+
context "given a nested hunk at the end" do
|
118
|
+
before :each do
|
119
|
+
@hunk = Hunk.new(
|
120
|
+
[
|
121
|
+
"not blank",
|
122
|
+
"the good stuff",
|
123
|
+
Hunk.new(["line 1"])
|
124
|
+
])
|
125
|
+
@it = TextTransforms.strip_blanks
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should not strip the hunk" do
|
129
|
+
@it.call(@hunk).should ==
|
130
|
+
["not blank", "the good stuff", Hunk.new(["line 1"])]
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
84
134
|
end
|
85
135
|
|
86
136
|
describe "rstrip_lines" do
|
@@ -150,5 +200,43 @@ module Germinate
|
|
150
200
|
end
|
151
201
|
end
|
152
202
|
end
|
203
|
+
|
204
|
+
describe "expand_insertions" do
|
205
|
+
before :each do
|
206
|
+
@output = stub("Output")
|
207
|
+
@hunk = stub("Hunk")
|
208
|
+
end
|
209
|
+
|
210
|
+
context "called on a hunk" do
|
211
|
+
before :each do
|
212
|
+
@it = TextTransforms.expand_insertions
|
213
|
+
end
|
214
|
+
|
215
|
+
it "should invoke expand_insertions on the hunk" do
|
216
|
+
@hunk.should_receive(:resolve_insertions).and_return(@output)
|
217
|
+
@it.call(@hunk).should == @output
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
describe "flatten" do
|
223
|
+
context "given a lumpy hunk" do
|
224
|
+
before :each do
|
225
|
+
@nested_hunk = Hunk.new(["line 3", "line 4"])
|
226
|
+
@lumpy = Hunk.new([
|
227
|
+
"line 1",
|
228
|
+
@nested_hunk,
|
229
|
+
"line 2"
|
230
|
+
],
|
231
|
+
:comment_prefix => "foo")
|
232
|
+
@output = TextTransforms.flatten_nested.call(@lumpy)
|
233
|
+
end
|
234
|
+
|
235
|
+
it "should flatten the hunk into a single level" do
|
236
|
+
@output.should == ["line 1", "line 3", "line 4", "line 2"]
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
end
|
153
241
|
end
|
154
242
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'stringio'
|
2
|
+
|
3
|
+
require File.expand_path(
|
4
|
+
File.join(File.dirname(__FILE__), %w[.. .. lib germinate]))
|
5
|
+
|
6
|
+
module Germinate
|
7
|
+
describe TransformProcess do
|
8
|
+
before :each do
|
9
|
+
@hunk1 = stub("Hunk1").as_null_object
|
10
|
+
@it = TransformProcess.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def output
|
14
|
+
@output.rewind
|
15
|
+
@output.string
|
16
|
+
end
|
17
|
+
|
18
|
+
TRANSFORMS = TextTransforms.singleton_methods
|
19
|
+
TRANSFORMS.each do |transform_name|
|
20
|
+
context "when only #{transform_name} is enabled" do
|
21
|
+
before :each do
|
22
|
+
@hunk = stub("Hunk").as_null_object
|
23
|
+
@transformed = stub("Transformed Hunk")
|
24
|
+
@transform = stub("Transform", :call => @transformed)
|
25
|
+
TextTransforms.stub!(transform_name).and_return(@transform)
|
26
|
+
|
27
|
+
(TRANSFORMS - [transform_name]).each do |disabled_transform|
|
28
|
+
@hunk.stub!("#{disabled_transform}?").and_return(false)
|
29
|
+
TextTransforms.stub!(disabled_transform) do
|
30
|
+
fail "Transform #{disabled_transform} should not be enabled"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
@hunk.stub!("#{transform_name}?").and_return(true)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should perform transform on input hunks" do
|
37
|
+
@transform.should_receive(:call).with(@hunk).and_return(@transformed)
|
38
|
+
@it.call(@hunk)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should return the result of the transform" do
|
42
|
+
@it.call(@hunk).should == @transformed
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path(
|
2
|
+
File.join(File.dirname(__FILE__), %w[.. .. lib germinate]))
|
3
|
+
|
4
|
+
module Germinate
|
5
|
+
describe Variable do
|
6
|
+
before :each do
|
7
|
+
@it = Variable.new("magic_word", "xyzzy", "LINE", "SOURCE_PATH", 123)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should stringify to its value" do
|
11
|
+
@it.to_s.should == "xyzzy"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: devver-germinate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Avdi Grimm
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-07-
|
12
|
+
date: 2009-07-21 00:00:00 -07:00
|
13
13
|
default_executable: germ
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -103,13 +103,14 @@ files:
|
|
103
103
|
- examples/basic.rb
|
104
104
|
- examples/short.rb
|
105
105
|
- features/author-formats-article.feature
|
106
|
-
- features/author-lists-info.
|
106
|
+
- features/author-lists-info.pending_feature
|
107
107
|
- features/author-publishes-article-source.feature
|
108
108
|
- features/author-publishes-article.feature
|
109
109
|
- features/author-republishes-article.feature
|
110
110
|
- features/author-selects-hunks.feature
|
111
|
+
- features/author-sets-variables.feature
|
111
112
|
- features/author-updates-article-source.feature
|
112
|
-
- features/author-views-stuff.
|
113
|
+
- features/author-views-stuff.pending_feature
|
113
114
|
- features/bin/quoter
|
114
115
|
- features/bin/sorter
|
115
116
|
- features/example_articles/bracketing.rb
|
@@ -139,21 +140,27 @@ files:
|
|
139
140
|
- lib/germinate.rb
|
140
141
|
- lib/germinate/application.rb
|
141
142
|
- lib/germinate/article_editor.rb
|
142
|
-
- lib/germinate/article_formatter.rb
|
143
143
|
- lib/germinate/formatter.rb
|
144
144
|
- lib/germinate/hunk.rb
|
145
145
|
- lib/germinate/implicit_insertion.rb
|
146
146
|
- lib/germinate/insertion.rb
|
147
147
|
- lib/germinate/librarian.rb
|
148
|
+
- lib/germinate/origin.rb
|
148
149
|
- lib/germinate/pipeline.rb
|
149
|
-
- lib/germinate/
|
150
|
+
- lib/germinate/publisher.rb
|
150
151
|
- lib/germinate/reader.rb
|
151
152
|
- lib/germinate/selector.rb
|
152
153
|
- lib/germinate/shared_style_attributes.rb
|
154
|
+
- lib/germinate/shell_process.rb
|
155
|
+
- lib/germinate/shell_publisher.rb
|
156
|
+
- lib/germinate/simple_publisher.rb
|
157
|
+
- lib/germinate/source_file.rb
|
153
158
|
- lib/germinate/text_transforms.rb
|
159
|
+
- lib/germinate/transform_process.rb
|
160
|
+
- lib/germinate/variable.rb
|
161
|
+
- sample.rb
|
154
162
|
- spec/germinate/application_spec.rb
|
155
163
|
- spec/germinate/article_editor_spec.rb
|
156
|
-
- spec/germinate/article_formatter_spec.rb
|
157
164
|
- spec/germinate/code_hunk_spec.rb
|
158
165
|
- spec/germinate/file_hunk_spec.rb
|
159
166
|
- spec/germinate/formatter_spec.rb
|
@@ -163,10 +170,15 @@ files:
|
|
163
170
|
- spec/germinate/librarian_spec.rb
|
164
171
|
- spec/germinate/pipeline_spec.rb
|
165
172
|
- spec/germinate/process_spec.rb
|
173
|
+
- spec/germinate/publisher_spec.rb
|
166
174
|
- spec/germinate/reader_spec.rb
|
167
175
|
- spec/germinate/selector_spec.rb
|
176
|
+
- spec/germinate/shell_publisher_spec.rb
|
177
|
+
- spec/germinate/source_file_spec.rb
|
168
178
|
- spec/germinate/text_hunk_spec.rb
|
169
179
|
- spec/germinate/text_transforms_spec.rb
|
180
|
+
- spec/germinate/transform_process_spec.rb
|
181
|
+
- spec/germinate/variable_spec.rb
|
170
182
|
- spec/germinate_spec.rb
|
171
183
|
- spec/spec.opts
|
172
184
|
- spec/spec_helper.rb
|
@@ -1,75 +0,0 @@
|
|
1
|
-
require 'ick'
|
2
|
-
require 'fattr'
|
3
|
-
require File.expand_path("shared_style_attributes", File.dirname(__FILE__))
|
4
|
-
|
5
|
-
# A Formatter is responsible for taking content hunks received from an Editor
|
6
|
-
# and formatting them for display or publishing.
|
7
|
-
class Germinate::ArticleFormatter
|
8
|
-
Ick::Returning.belongs_to self
|
9
|
-
include Germinate::SharedStyleAttributes
|
10
|
-
|
11
|
-
fattr :join_lines => true
|
12
|
-
fattr :strip_blanks => true
|
13
|
-
fattr :rstrip_newlines => true
|
14
|
-
fattr :uncomment => true
|
15
|
-
fattr :rstrip_lines => true
|
16
|
-
|
17
|
-
def initialize(output_stream=$stdout)
|
18
|
-
@output_stream = output_stream
|
19
|
-
@first_output = true
|
20
|
-
end
|
21
|
-
|
22
|
-
def start!
|
23
|
-
end
|
24
|
-
|
25
|
-
def finish!
|
26
|
-
end
|
27
|
-
|
28
|
-
def format!(hunk)
|
29
|
-
@output_stream.puts unless first_output?
|
30
|
-
hunk.format_with(self)
|
31
|
-
@first_output = false if first_output?
|
32
|
-
end
|
33
|
-
|
34
|
-
def format_text!(hunk, comment_prefix=nil)
|
35
|
-
text_transforms.inject(hunk) do |hunk, transform|
|
36
|
-
transform.call(hunk)
|
37
|
-
end.each do |line|
|
38
|
-
@output_stream.puts(line)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def format_code!(hunk, comment_prefix=nil)
|
43
|
-
code_transforms.inject(hunk) do |hunk, transform|
|
44
|
-
transform.call(hunk)
|
45
|
-
end.each do |line|
|
46
|
-
@output_stream.puts(line)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
private
|
51
|
-
|
52
|
-
def first_output?
|
53
|
-
@first_output
|
54
|
-
end
|
55
|
-
|
56
|
-
def text_transforms
|
57
|
-
returning([]) do |transforms|
|
58
|
-
transforms << Germinate::TextTransforms.strip_blanks if strip_blanks?
|
59
|
-
if uncomment?
|
60
|
-
transforms << Germinate::TextTransforms.uncomment(comment_prefix)
|
61
|
-
end
|
62
|
-
transforms << Germinate::TextTransforms.join_lines if join_lines?
|
63
|
-
transforms << Germinate::TextTransforms.rstrip_lines if rstrip_lines?
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def code_transforms
|
68
|
-
returning([]) do |transforms|
|
69
|
-
transforms << Germinate::TextTransforms.strip_blanks if strip_blanks?
|
70
|
-
transforms << Germinate::TextTransforms.rstrip_lines if rstrip_lines?
|
71
|
-
transforms <<
|
72
|
-
Germinate::TextTransforms.bracket
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
@@ -1,153 +0,0 @@
|
|
1
|
-
require 'stringio'
|
2
|
-
|
3
|
-
require File.expand_path(
|
4
|
-
File.join(File.dirname(__FILE__), %w[.. .. lib germinate]))
|
5
|
-
|
6
|
-
module Germinate
|
7
|
-
describe ArticleFormatter do
|
8
|
-
before :each do
|
9
|
-
@output = StringIO.new
|
10
|
-
@hunk1 = stub("Hunk1")
|
11
|
-
@hunk2 = stub("Hunk2")
|
12
|
-
@it = ArticleFormatter.new(@output)
|
13
|
-
end
|
14
|
-
|
15
|
-
def output
|
16
|
-
@output.rewind
|
17
|
-
@output.string
|
18
|
-
end
|
19
|
-
|
20
|
-
context "given some hunks to format" do
|
21
|
-
before :each do
|
22
|
-
@hunks = [@hunk1, @hunk2]
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should visit each hunk in turn" do
|
26
|
-
@hunk1.should_receive(:format_with).with(@it).ordered
|
27
|
-
@hunk2.should_receive(:format_with).with(@it).ordered
|
28
|
-
@hunks.each do |hunk|
|
29
|
-
@it.format!(hunk)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
|
35
|
-
context "given some text lines to format but no comment prefix" do
|
36
|
-
before :each do
|
37
|
-
@it.join_lines = false
|
38
|
-
@it.format_text!(Hunk.new([" # foo", "bar\n\n"]))
|
39
|
-
end
|
40
|
-
|
41
|
-
it "should just normalise newlines" do
|
42
|
-
output.should == " # foo\nbar\n"
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
context "given some text lines to format and a comment prefix" do
|
47
|
-
before :each do
|
48
|
-
@it.comment_prefix = "# "
|
49
|
-
@it.uncomment = true
|
50
|
-
@it.join_lines = false
|
51
|
-
@it.format_text!(Hunk.new(["# foo", "bar\n\n"]), "# ")
|
52
|
-
end
|
53
|
-
|
54
|
-
it "should erase comments" do
|
55
|
-
output.should == " foo\nbar\n"
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
context "given leading and trailing blank lines around text" do
|
60
|
-
before :each do
|
61
|
-
@it.format_text!(Hunk.new(["", "foo", " \n "]), "#")
|
62
|
-
end
|
63
|
-
|
64
|
-
it "should erase comments" do
|
65
|
-
output.should == "foo\n"
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
context "given uncommenting is enabled and a comment prefix is set" do
|
70
|
-
it "should supply the comment prefix to the uncomment transform" do
|
71
|
-
@hunk = stub("Hunk").as_null_object
|
72
|
-
@hunk.stub!(:strip).and_return(@hunk)
|
73
|
-
@prefix = "//"
|
74
|
-
@transform = stub("Transform", :call => @transformed)
|
75
|
-
TextTransforms.stub!(:uncomment).and_return(@transform)
|
76
|
-
|
77
|
-
TextTransforms.should_receive(:uncomment).with(@prefix).
|
78
|
-
and_return(lambda{|h| h})
|
79
|
-
|
80
|
-
@it.comment_prefix = @prefix
|
81
|
-
@it.uncomment = true
|
82
|
-
@it.format_text!(@hunk)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
CODE_TRANSFORMS = %w[rstrip_lines strip_blanks]
|
87
|
-
TEXT_TRANSFORMS = %w[join_lines strip_blanks uncomment rstrip_lines]
|
88
|
-
TEXT_TRANSFORMS.each do |transform_name|
|
89
|
-
context "when only #{transform_name} is enabled" do
|
90
|
-
before :each do
|
91
|
-
(TEXT_TRANSFORMS - [transform_name]).each do |disabled_transform|
|
92
|
-
@it.send("#{disabled_transform}=", false)
|
93
|
-
TextTransforms.stub!(disabled_transform) do
|
94
|
-
fail "Transform #{disabled_transform} should not be enabled"
|
95
|
-
end
|
96
|
-
end
|
97
|
-
@it.send("#{transform_name}=", true)
|
98
|
-
|
99
|
-
@transformed = stub("Transformed Hunk").as_null_object
|
100
|
-
@hunk = stub("Hunk").as_null_object
|
101
|
-
@hunk.stub!(:strip).and_return(@hunk)
|
102
|
-
@transform = stub("Transform", :call => @transformed)
|
103
|
-
TextTransforms.stub!(transform_name).and_return(@transform)
|
104
|
-
|
105
|
-
end
|
106
|
-
|
107
|
-
it "should perform transform on text hunks" do
|
108
|
-
@transform.should_receive(:call).with(@hunk)
|
109
|
-
@it.format_text!(@hunk)
|
110
|
-
end
|
111
|
-
|
112
|
-
it "should return the result of the transform" do
|
113
|
-
@it.format_text!(@hunk).should == @transformed
|
114
|
-
end
|
115
|
-
|
116
|
-
unless CODE_TRANSFORMS.include?(transform_name)
|
117
|
-
it "should not perform transform on code hunks" do
|
118
|
-
@transform.should_not_receive(:call).with(@hunk)
|
119
|
-
@it.format_code!(@hunk)
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
context "given some code lines to format" do
|
126
|
-
before :each do
|
127
|
-
@it.format_code!(Hunk.new([" \n ", " # foo", "bar\n\n", ""]))
|
128
|
-
end
|
129
|
-
|
130
|
-
it "should normalise newlines and strip blanks" do
|
131
|
-
output.should == " # foo\nbar\n"
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
context "given a code hunk with brackets specified" do
|
136
|
-
before :each do
|
137
|
-
@hunk = Hunk.new(["line 1"],
|
138
|
-
:code_open_bracket => "<<<",
|
139
|
-
:code_close_bracket => ">>>")
|
140
|
-
end
|
141
|
-
|
142
|
-
it "should wrap the code in brackets" do
|
143
|
-
@transform = stub("Bracketer")
|
144
|
-
TextTransforms.should_receive(:bracket).
|
145
|
-
with().and_return(@transform)
|
146
|
-
@transform.should_receive(:call).with(["line 1"]).and_return([])
|
147
|
-
@it.format_code!(@hunk)
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
end
|
152
|
-
|
153
|
-
end
|