germinate 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.
Files changed (105) hide show
  1. data/.gitignore +2 -0
  2. data/History.txt +26 -0
  3. data/README.rdoc +152 -0
  4. data/Rakefile +43 -0
  5. data/TODO +140 -0
  6. data/bin/germ +260 -0
  7. data/cucumber.yml +2 -0
  8. data/examples/basic.rb +123 -0
  9. data/examples/short.rb +19 -0
  10. data/features/author-formats-article.feature +111 -0
  11. data/features/author-lists-info.pending_feature +48 -0
  12. data/features/author-publishes-article-source.feature +5 -0
  13. data/features/author-publishes-article.feature +57 -0
  14. data/features/author-republishes-article.feature +5 -0
  15. data/features/author-selects-hunks.feature +26 -0
  16. data/features/author-sets-variables.feature +88 -0
  17. data/features/author-updates-article-source.feature +5 -0
  18. data/features/author-views-stuff.pending_feature +52 -0
  19. data/features/bin/quoter +6 -0
  20. data/features/bin/sorter +4 -0
  21. data/features/example_articles/bracketing.rb +27 -0
  22. data/features/example_articles/escaping.txt +13 -0
  23. data/features/example_articles/excerpt_output.rb +16 -0
  24. data/features/example_articles/hello.rb +9 -0
  25. data/features/example_articles/pipelines.txt +25 -0
  26. data/features/example_articles/regexen.rb +24 -0
  27. data/features/example_articles/sample_offsets.rb +18 -0
  28. data/features/example_articles/specials.rb +19 -0
  29. data/features/example_articles/stderr.rb +10 -0
  30. data/features/example_articles/wrapping.rb +8 -0
  31. data/features/example_output/bracketing.out +23 -0
  32. data/features/example_output/code_samples.txt +186 -0
  33. data/features/example_output/escaping.out +5 -0
  34. data/features/example_output/excerpt_output.out +6 -0
  35. data/features/example_output/hello.txt +1 -0
  36. data/features/example_output/pipelines.out +28 -0
  37. data/features/example_output/regexen.txt +22 -0
  38. data/features/example_output/sample_offsets.txt +15 -0
  39. data/features/example_output/specials.txt +40 -0
  40. data/features/example_output/stderr.out +3 -0
  41. data/features/example_output/wrapping.txt +3 -0
  42. data/features/step_definitions/germinate.rb +42 -0
  43. data/features/support/env.rb +20 -0
  44. data/germinate.gemspec +55 -0
  45. data/lib/germinate.rb +54 -0
  46. data/lib/germinate/application.rb +113 -0
  47. data/lib/germinate/article_editor.rb +20 -0
  48. data/lib/germinate/formatter.rb +119 -0
  49. data/lib/germinate/hunk.rb +183 -0
  50. data/lib/germinate/implicit_insertion.rb +9 -0
  51. data/lib/germinate/insertion.rb +29 -0
  52. data/lib/germinate/librarian.rb +293 -0
  53. data/lib/germinate/origin.rb +5 -0
  54. data/lib/germinate/pipeline.rb +13 -0
  55. data/lib/germinate/publisher.rb +57 -0
  56. data/lib/germinate/reader.rb +266 -0
  57. data/lib/germinate/selector.rb +136 -0
  58. data/lib/germinate/shared_style_attributes.rb +54 -0
  59. data/lib/germinate/shell_process.rb +94 -0
  60. data/lib/germinate/shell_publisher.rb +19 -0
  61. data/lib/germinate/simple_publisher.rb +7 -0
  62. data/lib/germinate/source_file.rb +41 -0
  63. data/lib/germinate/text_transforms.rb +119 -0
  64. data/lib/germinate/transform_process.rb +25 -0
  65. data/lib/germinate/variable.rb +23 -0
  66. data/sample.rb +14 -0
  67. data/spec/germinate/application_spec.rb +31 -0
  68. data/spec/germinate/article_editor_spec.rb +97 -0
  69. data/spec/germinate/code_hunk_spec.rb +73 -0
  70. data/spec/germinate/file_hunk_spec.rb +28 -0
  71. data/spec/germinate/formatter_spec.rb +160 -0
  72. data/spec/germinate/hunk_spec.rb +84 -0
  73. data/spec/germinate/implicit_insertion_spec.rb +33 -0
  74. data/spec/germinate/insertion_spec.rb +19 -0
  75. data/spec/germinate/librarian_spec.rb +555 -0
  76. data/spec/germinate/pipeline_spec.rb +34 -0
  77. data/spec/germinate/process_spec.rb +105 -0
  78. data/spec/germinate/publisher_spec.rb +130 -0
  79. data/spec/germinate/reader_spec.rb +385 -0
  80. data/spec/germinate/selector_spec.rb +121 -0
  81. data/spec/germinate/shell_publisher_spec.rb +61 -0
  82. data/spec/germinate/source_file_spec.rb +99 -0
  83. data/spec/germinate/text_hunk_spec.rb +98 -0
  84. data/spec/germinate/text_transforms_spec.rb +242 -0
  85. data/spec/germinate/transform_process_spec.rb +50 -0
  86. data/spec/germinate/variable_spec.rb +14 -0
  87. data/spec/germinate_spec.rb +8 -0
  88. data/spec/spec.opts +1 -0
  89. data/spec/spec_helper.rb +16 -0
  90. data/tasks/ann.rake +80 -0
  91. data/tasks/bones.rake +20 -0
  92. data/tasks/cucumber.rake +5 -0
  93. data/tasks/gem.rake +201 -0
  94. data/tasks/git.rake +40 -0
  95. data/tasks/notes.rake +27 -0
  96. data/tasks/post_load.rake +34 -0
  97. data/tasks/rdoc.rake +51 -0
  98. data/tasks/rubyforge.rake +55 -0
  99. data/tasks/setup.rb +292 -0
  100. data/tasks/spec.rake +54 -0
  101. data/tasks/svn.rake +47 -0
  102. data/tasks/test.rake +40 -0
  103. data/tasks/zentest.rake +36 -0
  104. data/test/test_germinate.rb +0 -0
  105. metadata +228 -0
@@ -0,0 +1,34 @@
1
+ require File.expand_path(
2
+ File.join(File.dirname(__FILE__), %w[.. .. lib germinate]))
3
+
4
+ module Germinate
5
+ describe Pipeline, "given a set of processes" do
6
+ before :each do
7
+ @intput = stub("Input")
8
+ @output1 = stub("Output 1")
9
+ @output2 = stub("Output 2")
10
+ @output3 = stub("Output 3")
11
+ @process1 = stub("Process 1", :call => @output1)
12
+ @process2 = stub("Process 2", :call => @output2)
13
+ @process3 = stub("Process 3", :call => @output3)
14
+ @it = Germinate::Pipeline.new([@process1, @process2, @process3])
15
+ end
16
+
17
+ it "should compose the processes into a pipeline" do
18
+ @process1.should_receive(:call).with(@input).and_return(@output1)
19
+ @process2.should_receive(:call).with(@output1).and_return(@output2)
20
+ @process3.should_receive(:call).with(@output2).and_return(@output3)
21
+ @it.call(@input).should == @output3
22
+ end
23
+ end
24
+
25
+ describe Pipeline, "given no processes" do
26
+ before :each do
27
+ @it = Pipeline.new([])
28
+ end
29
+
30
+ it "should pass input through unchanged" do
31
+ @it.call(["foo", "bar"]).should == ["foo", "bar"]
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,105 @@
1
+ require File.expand_path(
2
+ File.join(File.dirname(__FILE__), %w[.. .. lib germinate]))
3
+
4
+ module Germinate
5
+ describe ShellProcess do
6
+ before :each do
7
+ @input = Germinate::Hunk.new(
8
+ ["line 1\n", "line 2\n"],
9
+ :comment_prefix => "//")
10
+ @output = ["1 enil\n", "2 enil\n"]
11
+ @command = stub("Command", :readlines => @output).as_null_object
12
+ @tempfile = stub("Temp File", :path => "TEMP_PATH").as_null_object
13
+ @status = stub("Child Status", :success => true)
14
+ IO.stub!(:popen).and_yield(@command)
15
+ Tempfile.stub!(:open).and_yield(@tempfile)
16
+ end
17
+
18
+ context "given a command and some variables" do
19
+ before :each do
20
+ @it = Germinate::ShellProcess.new(
21
+ "myproc", "mycommand", { "FOO" => 123, "BAR" => 456 })
22
+ ENV["FOO"] = "xxx"
23
+ end
24
+
25
+ it "should set the variables in the environment before execution" do
26
+ IO.should_receive(:popen) do
27
+ ENV["FOO"].should == "123"
28
+ ENV["BAR"].should == "456"
29
+ end
30
+ @it.call(@input)
31
+ end
32
+
33
+ it "should reset the environment after execution" do
34
+ @it.call(@input)
35
+ ENV["FOO"].should == "xxx"
36
+ ENV["BAR"].should be_nil
37
+ end
38
+ end
39
+
40
+ context "given a command 'mycommand'" do
41
+ before :each do
42
+ @it = Germinate::ShellProcess.new("myproc", "mycommand")
43
+ end
44
+
45
+ context "when called on a hunk of text" do
46
+ it "should pipe the input through the command" do
47
+ @command.should_receive(:<<).with("line 1\n").ordered
48
+ @command.should_receive(:<<).with("line 2\n").ordered
49
+ @command.should_receive(:close_write).ordered
50
+ @command.should_receive(:readlines).ordered.
51
+ and_return(["a\n", "b\n"])
52
+ IO.should_receive(:popen).with("mycommand", "r+").and_yield(@command)
53
+ output = @it.call(@input)
54
+ output.should == ["a\n", "b\n"]
55
+ end
56
+
57
+ it "should preserve hunk attributes" do
58
+ output = @it.call(@input)
59
+ output.comment_prefix.should == "//"
60
+ end
61
+
62
+ end
63
+ end
64
+
65
+ context "given a command 'mycommand %f' and called on some text" do
66
+ before :each do
67
+ @it = Germinate::ShellProcess.new("myproc", "mycommand %f")
68
+ end
69
+
70
+ it "should create a temporary file and pass the name to the command" do
71
+ Tempfile.should_receive(:open).with("germinate_hunk").and_yield(@tempfile)
72
+ @tempfile.should_receive(:<<).with("line 1\n").ordered
73
+ @tempfile.should_receive(:<<).with("line 2\n").ordered
74
+ @tempfile.should_receive(:close).ordered
75
+ IO.should_receive(:popen).
76
+ with("mycommand 'TEMP_PATH'", "r").
77
+ and_yield(@command)
78
+
79
+ @it.call(@input).should == @output
80
+ end
81
+
82
+ it "should preserve hunk attributes" do
83
+ output = @it.call(@input)
84
+ output.comment_prefix.should == "//"
85
+ end
86
+
87
+ end
88
+
89
+ context "given a command 'mycommand %f' and called on a file hunk" do
90
+ before :each do
91
+ @input = Germinate::FileHunk.new(
92
+ ["line 1\n", "line 2\n"],
93
+ {:source_path => "SOURCE_PATH"})
94
+ @it = Germinate::ShellProcess.new("myproc", "mycommand %f")
95
+ end
96
+
97
+ it "should pass the source file path to the command" do
98
+ @path = stub("Source File Path")
99
+ IO.should_receive(:popen).with("mycommand 'SOURCE_PATH'", "r").
100
+ and_yield(@command)
101
+ @it.call(@input).should == @output
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,130 @@
1
+ require File.expand_path(
2
+ File.join(File.dirname(__FILE__), %w[.. .. lib germinate]))
3
+
4
+ module Germinate
5
+ describe Publisher do
6
+ before :each do
7
+ @name = "my_pub"
8
+ @hunk = stub("Input Hunk")
9
+ @output = stub("Pipeline Output")
10
+ @pipeline = stub("Pipeline", :call => @output)
11
+ @librarian = stub("Librarian",
12
+ :make_pipeline => @pipeline,
13
+ :[] => @hunk ).as_null_object
14
+ @options = {:a => 'b'}
15
+ end
16
+
17
+ context "when a new publisher type 'foo' is defined" do
18
+ before :each do
19
+ @it = Germinate::Publisher
20
+ @subclass = Class.new(Publisher) do
21
+ identifier "foo"
22
+ end
23
+ end
24
+
25
+ it "should be able to make 'foo' publishers" do
26
+ @publisher = stub("Publisher")
27
+ @subclass.should_receive(:new).with(@name, @librarian, @options).
28
+ and_return(@publisher)
29
+
30
+ @it.make(@name, "foo", @librarian, @options)
31
+ end
32
+
33
+ end
34
+
35
+ context "when an anonymous publisher subclass is defined" do
36
+ before :each do
37
+ @it = Germinate::Publisher
38
+ @subclass = Class.new(Publisher) do
39
+ self.identifier = nil
40
+ end
41
+ end
42
+
43
+ it "should not make the publisher available as an instantiable type" do
44
+ @librarian = stub("Librarian")
45
+ @options = {:a => 'b'}
46
+ @publisher = stub("Publisher")
47
+
48
+ lambda do
49
+ @it.make("mypub", nil, @librarian, @options)
50
+ end.should raise_error(IndexError)
51
+ end
52
+
53
+ end
54
+
55
+ context "given name, librarian, and options" do
56
+ before :each do
57
+ @name = "frank"
58
+ @librarian = stub("Librarian").as_null_object
59
+ @options = {:foo => "bar"}
60
+ @it = Publisher.new(@name, @librarian, @options)
61
+ end
62
+
63
+ it "should know its name" do
64
+ @it.name.should == @name
65
+ end
66
+
67
+ it "should know its librarian" do
68
+ @it.librarian.should == @librarian
69
+ end
70
+
71
+ it "should know its options" do
72
+ @it.options.should == @options
73
+ end
74
+ end
75
+
76
+ context "given a pipeline option" do
77
+ before :each do
78
+ @name = "frank"
79
+ @librarian = stub("Librarian").as_null_object
80
+ @options = {:pipeline => "foo|bar"}
81
+ end
82
+
83
+ it "should have a pipeline" do
84
+ @it = Publisher.new(@name, @librarian, @options)
85
+ @it.pipeline.should_not be_nil
86
+ end
87
+
88
+ it "should use the librarian to construct a pipeline" do
89
+ @librarian.should_receive(:make_pipeline).with("foo|bar")
90
+ @it = Publisher.new(@name, @librarian, @options)
91
+ end
92
+ end
93
+
94
+ context "with no selector specified" do
95
+ before :each do
96
+ @it = Publisher.new(@name, @librarian, @options)
97
+ end
98
+
99
+ it "should select $TEXT|_transform" do
100
+ @it.selector.should == "$TEXT|_transform"
101
+ end
102
+
103
+ end
104
+
105
+ context "with a custom selector specified" do
106
+ before :each do
107
+ @it = Publisher.new(@name, @librarian, { :selector => "@sec1|myproc" })
108
+ end
109
+
110
+ it "should have the specified selector" do
111
+ @it.selector.should == "@sec1|myproc"
112
+ end
113
+
114
+ it "should use the selector to get a hunk to process" do
115
+ @librarian.should_receive(:[]).
116
+ with("@sec1|myproc", anything)
117
+ @it.input
118
+ end
119
+
120
+ it "should pass the selected hunk through the pipeline to get input" do
121
+ @pipeline.should_receive(:call).with(@hunk)
122
+ @it.input
123
+ end
124
+
125
+ it "should use pipeline output as input to publisher process" do
126
+ @it.input.should == @output
127
+ end
128
+ end
129
+ end
130
+ end
@@ -0,0 +1,385 @@
1
+ require File.expand_path(
2
+ File.join(File.dirname(__FILE__), %w[.. .. lib germinate]))
3
+
4
+ module Germinate
5
+ describe Reader do
6
+ before :each do
7
+ @librarian = stub("Librarian", :comment_prefix_known? => false).
8
+ as_null_object
9
+ @it = Reader.new(@librarian, "SOURCE_PATH")
10
+ end
11
+
12
+ it "should start in the :initial state" do
13
+ @it.state.should == :initial
14
+ end
15
+
16
+ it "should start out with a section count of 0" do
17
+ @it.section_count.should == 0
18
+ end
19
+
20
+ it "should start out with current section SECTION0" do
21
+ @it.current_section.should == "SECTION0"
22
+ end
23
+
24
+ it "should set the librarian's source path" do
25
+ @librarian.should_receive(:source_path=).with(Pathname("SOURCE_PATH"))
26
+ @it = Reader.new(@librarian, "SOURCE_PATH")
27
+ end
28
+
29
+ context "when section count is incremented" do
30
+
31
+ before :each do
32
+ @it.increment_section_count!
33
+ end
34
+
35
+ it "should increment section count by one" do
36
+ @it.section_count.should == 1
37
+ end
38
+
39
+ it "should update current section" do
40
+ @it.current_section.should == "SECTION1"
41
+ end
42
+
43
+ end
44
+
45
+ CONTROL_LINES = [
46
+ # Line Comment Args
47
+ [":TEXT:\n", nil, []],
48
+ ["# :CUT: \n", "# ", []],
49
+ [" ; :TEXT: foo\n", " ; ", ["foo"]],
50
+ ["//:SAMPLE:\n", "//", []],
51
+ ["$>:END: ", "$>", []],
52
+ [":SAMPLE: bar, { a: 1, b: 2 }", nil, ["bar", {"a"=>1, "b"=>2}]],
53
+ [':BRACKET_CODE:', nil, []],
54
+ [':INSERT: @sel', nil, ["@sel"]],
55
+ [':PROCESS: foo, bar', nil, ["foo", "bar"]],
56
+ ]
57
+
58
+ CONTROL_LINES.each do |(line, comment, args)|
59
+ context "when given the line #{line}" do
60
+ if comment
61
+ it "should set the comment character to '#{comment}'" do
62
+ @librarian.should_receive(:comment_prefix=).with(comment)
63
+ @it << line
64
+ end
65
+ else
66
+ it "should not set a comment prefix" do
67
+ @librarian.should_not_receive(:comment_prefix=)
68
+ @it << line
69
+ end
70
+ end
71
+
72
+ it "should store the line as a control line" do
73
+ @librarian.should_receive(:add_control!).with(line)
74
+ @it << line
75
+ end
76
+ end
77
+ end
78
+
79
+ context "given a BRACKET_CODE control line" do
80
+ before :each do
81
+ @line = ':BRACKET_CODE: "<<<", ">>>"'
82
+ end
83
+
84
+ it "should store the brackets" do
85
+ @librarian.should_receive(:code_open_bracket=).with("<<<")
86
+ @librarian.should_receive(:code_close_bracket=).with(">>>")
87
+ @it << @line
88
+ end
89
+
90
+ end
91
+
92
+ context "before the first line of text" do
93
+ it "should treat non-keyword lines as front matter" do
94
+ @librarian.should_receive(:add_front_matter!, "TEST")
95
+ @it << "TEST"
96
+ end
97
+ end
98
+
99
+ context "after an initial line of text" do
100
+ before :each do
101
+ @it << "\n"
102
+ end
103
+
104
+ it "should be in the :front_matter state" do
105
+ @it.state.should == :front_matter
106
+ end
107
+
108
+ it "should record non-keyword lines as more front matter" do
109
+ @librarian.should_receive(:add_front_matter!, "TEST")
110
+ @it << "TEST"
111
+ end
112
+ end
113
+
114
+ context "after the :TEXT: keyword" do
115
+ before :each do
116
+ @it << ":TEXT:\n"
117
+ end
118
+
119
+ it "should be in the :text state" do
120
+ @it.state.should == :text
121
+ end
122
+
123
+ it "should place following text lines into a section" do
124
+ @librarian.should_receive(:add_text!).with("SECTION1", "blah blah blah")
125
+ @it << "blah blah blah"
126
+ end
127
+
128
+ context "given an escaped directive" do
129
+ it "should add the directive line as text" do
130
+ @librarian.should_receive(:add_text!).with("SECTION1", ":TEXT: abc")
131
+ @it << "\\:TEXT: abc"
132
+ end
133
+ end
134
+ end
135
+
136
+ context "after two anonymous :TEXT: sections" do
137
+ before :each do
138
+ @it << ":TEXT:\n"
139
+ @it << ":TEXT:\n"
140
+ end
141
+
142
+ it "should be in SECTION2" do
143
+ @it.current_section.should == "SECTION2"
144
+ end
145
+ end
146
+
147
+ context "after a named :TEXT: keyword" do
148
+ before :each do
149
+ @it << ":TEXT: foo\n"
150
+ end
151
+
152
+ it "should be in the :text state" do
153
+ @it.state.should == :text
154
+ end
155
+
156
+ it "should place following text lines into the named section" do
157
+ @librarian.should_receive(:add_text!).with("foo", "yadda yadda")
158
+ @it << "yadda yadda"
159
+ end
160
+
161
+ it "should name following code lines after the section" do
162
+ @librarian.should_receive(:add_code!).with("foo", "this is code")
163
+ @it << "yadda yadda\n"
164
+ @it << ":SAMPLE:\n"
165
+ @it << "this is code"
166
+ end
167
+ end
168
+
169
+ context "after text is ended by a :CUT:" do
170
+ before :each do
171
+ @it << ":TEXT:\n"
172
+ @it << ":CUT:\n"
173
+ end
174
+
175
+ it "should be in the :code state" do
176
+ @it.state.should == :code
177
+ end
178
+
179
+ it "should add following lines to a code sample" do
180
+ @librarian.should_receive(:add_code!).with("SECTION2", "this is code")
181
+ @it << "this is code"
182
+ end
183
+ end
184
+
185
+ context "after a :TEXT: keyword prefixed with '#'" do
186
+ before :each do
187
+ @it << "# :TEXT:\n"
188
+ end
189
+
190
+ it "should be in the :text state" do
191
+ @it.state.should == :text
192
+ end
193
+
194
+ end
195
+
196
+ context "after a :TEXT: keyword prefixed with ';'" do
197
+ before :each do
198
+ @it << " ; :TEXT:\n"
199
+ end
200
+
201
+ it "should be in the :text state" do
202
+ @it.state.should == :text
203
+ end
204
+
205
+ end
206
+
207
+ context "given a :SAMPLE: keyword with a name" do
208
+ before :each do
209
+ @it << ":SAMPLE: foobar"
210
+ end
211
+
212
+ it "should file following code lines under the given name" do
213
+ @librarian.should_receive(:add_code!).with("foobar", "line 1")
214
+ @librarian.should_receive(:add_code!).with("foobar", "line 2")
215
+
216
+ @it << "line 1"
217
+ @it << "line 2"
218
+ end
219
+
220
+ context "given an escaped directive" do
221
+ it "should add the directive line as code" do
222
+ @librarian.should_receive(:add_code!).with("foobar", " # :TEXT: abc")
223
+ @it << " # \\:TEXT: abc"
224
+ end
225
+ end
226
+ end
227
+
228
+ context "given a :SAMPLE: after a TEXT section with the same name" do
229
+ before :each do
230
+ @it << ":TEXT: foobar\n"
231
+ @it << "This is the text\n"
232
+ end
233
+
234
+ it "should add an implicit insertion to the TEXT section" do
235
+ @librarian.should_receive(:add_insertion!).with("foobar", "@foobar", {})
236
+ @it << ":SAMPLE: foobar\n"
237
+ end
238
+
239
+ end
240
+
241
+ context "given a :SAMPLE: keyword with custom brackets" do
242
+ before :each do
243
+ @line = ':SAMPLE: foobar, { brackets: ["<<", ">>"] }'
244
+ end
245
+
246
+ it "should assign custom bracket attributes to the sample" do
247
+ @librarian.should_receive(:set_code_attributes!).
248
+ with("foobar",
249
+ {
250
+ :code_open_bracket => "<<",
251
+ :code_close_bracket => ">>"
252
+ })
253
+
254
+ @it << @line
255
+ end
256
+ end
257
+
258
+ context "in text section with comment set" do
259
+ before :each do
260
+ @librarian.stub!(:comment_prefix_known?).and_return(true)
261
+ @librarian.stub!(:comment_prefix).and_return("#")
262
+ @it << "# :TEXT:\n"
263
+ @section = @it.current_section
264
+ end
265
+
266
+ it "should treat a commented line as more of the same section" do
267
+ @librarian.should_receive(:add_text!).
268
+ with(@section, "# commented text\n")
269
+ @it << "# commented text\n"
270
+ end
271
+
272
+ it "should treat a commented blank line as more of the same section" do
273
+ @librarian.should_receive(:add_text!).
274
+ with(@section, "# \n")
275
+ @it << "# \n"
276
+ end
277
+
278
+ it "should treat an uncommented blank line as more of the same section" do
279
+ @librarian.should_receive(:add_text!).
280
+ with(@section, " \n")
281
+ @it << " \n"
282
+ end
283
+
284
+ it "should treat an uncommented line as the start of code" do
285
+ @librarian.should_receive(:add_code!).
286
+ with(@section, "uncommented text\n")
287
+ @it << "uncommented text\n"
288
+ end
289
+ end
290
+
291
+ context "given an insertion with an explicit selector" do
292
+ before :each do
293
+ @it << ":TEXT: mysection"
294
+ @line = ":INSERT: foo"
295
+ end
296
+
297
+ it "should add an insertion to the current section" do
298
+ @librarian.should_receive(:add_insertion!).
299
+ with("mysection", anything, anything)
300
+ @it << @line
301
+ end
302
+
303
+ it "should pass a selector object to the librarian" do
304
+ @librarian.should_receive(:add_insertion!) do |section, selector, options|
305
+ selector.should be_a_kind_of(Selector)
306
+ selector.string.should == "foo"
307
+ selector.default_key.should == "mysection"
308
+ end
309
+ @it << @line
310
+ end
311
+ end
312
+
313
+ context "given an insertion with custom attributes" do
314
+ before :each do
315
+ @it << ":TEXT: mysection"
316
+ @line = ":INSERT: foo, { brackets: ['<<', '>>'] } "
317
+ end
318
+
319
+ it "should pass the attributes on to the library" do
320
+ @librarian.should_receive(:add_insertion!).
321
+ with(anything, anything, {
322
+ :code_open_bracket => "<<",
323
+ :code_close_bracket => ">>"
324
+ })
325
+ @it << @line
326
+ end
327
+
328
+ end
329
+
330
+ context "given an insertion with the special disable_transforms attr" do
331
+ before :each do
332
+ @it << ":TEXT: mysection"
333
+ @line = ":INSERT: foo, { disable_transforms: true } "
334
+ end
335
+
336
+ it "should disable all transforms in the options" do
337
+ @librarian.should_receive(:add_insertion!) do
338
+ |section, selector, options|
339
+
340
+ TextTransforms.singleton_methods.each do |transform|
341
+ options[transform.to_sym].should be_false
342
+ end
343
+ end
344
+ @it << @line
345
+ end
346
+
347
+ end
348
+
349
+ context "given a process directive" do
350
+ before :each do
351
+ @line = ' # :PROCESS: sortail, "sort | tail"'
352
+ end
353
+
354
+ it "should add the process to the library" do
355
+ @librarian.should_receive(:add_process!).with("sortail", "sort | tail")
356
+ @it << @line
357
+ end
358
+ end
359
+
360
+ context "given a publisher directive" do
361
+ before :each do
362
+ @line = ' # :PUBLISHER: source, shell, { command: "cat %f" }'
363
+ end
364
+
365
+ it "should add the publisher to the librarian" do
366
+ @librarian.should_receive(:add_publisher!).
367
+ with("source", "shell", { :command => "cat %f" })
368
+ @it << @line
369
+ end
370
+ end
371
+
372
+ context "given a set directive" do
373
+ before :each do
374
+ @line = ' # :SET: name, value'
375
+ end
376
+
377
+ it "should set a variable on the librarian" do
378
+ @librarian.should_receive(:set_variable!).
379
+ with(@line, 1, "name", "value")
380
+ @it << @line
381
+ end
382
+ end
383
+
384
+ end
385
+ end