templater 0.1.1 → 0.1.2

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.
@@ -0,0 +1,32 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Templater::Generator, '.template_list' do
4
+
5
+ it "should add a series of templates given a list as heredoc" do
6
+ @generator_class = Class.new(Templater::Generator)
7
+
8
+ @generator_class.should_receive(:template).with(:app_model_rb, 'app/model.rb')
9
+ @generator_class.should_receive(:template).with(:spec_model_rb, 'spec/model.rb')
10
+ @generator_class.should_receive(:template).with(:donkey_poo_css, 'donkey/poo.css')
11
+ @generator_class.should_receive(:template).with(:john_smith_file_rb, 'john/smith/file.rb')
12
+
13
+ @generator_class.template_list <<-LIST
14
+ app/model.rb
15
+ spec/model.rb
16
+ donkey/poo.css
17
+ john/smith/file.rb
18
+ LIST
19
+ end
20
+
21
+ it "should add a series of templates given a list as array" do
22
+ @generator_class = Class.new(Templater::Generator)
23
+
24
+ @generator_class.should_receive(:template).with(:app_model_rb, 'app/model.rb')
25
+ @generator_class.should_receive(:template).with(:spec_model_rb, 'spec/model.rb')
26
+ @generator_class.should_receive(:template).with(:donkey_poo_css, 'donkey/poo.css')
27
+ @generator_class.should_receive(:template).with(:john_smith_file_rb, 'john/smith/file.rb')
28
+
29
+ @generator_class.template_list(%w(app/model.rb spec/model.rb donkey/poo.css john/smith/file.rb))
30
+ end
31
+
32
+ end
@@ -0,0 +1,79 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Templater::Generator, '.template' do
4
+
5
+ before do
6
+ @generator_class = Class.new(Templater::Generator)
7
+ end
8
+
9
+ it "should add a template with source and destination" do
10
+ @generator_class.template(:my_template, 'path/to/source.rbt', 'path/to/destination.rb')
11
+ @instance = @generator_class.new('/tmp/destination')
12
+
13
+ @instance.stub!(:source_root).and_return('/tmp/source')
14
+
15
+ @instance.template(:my_template).source.should == '/tmp/source/path/to/source.rbt'
16
+ @instance.template(:my_template).destination.should == '/tmp/destination/path/to/destination.rb'
17
+ @instance.template(:my_template).should be_an_instance_of(Templater::Template)
18
+ end
19
+
20
+ it "should add a template with absolute source and destination" do
21
+ @generator_class.template(:my_template, '/path/to/source.rbt', '/path/to/destination.rb')
22
+ @instance = @generator_class.new('/tmp/destination')
23
+
24
+ @instance.stub!(:source_root).and_return('/tmp/source')
25
+
26
+ @instance.template(:my_template).source.should == '/path/to/source.rbt'
27
+ @instance.template(:my_template).destination.should == '/path/to/destination.rb'
28
+ @instance.template(:my_template).should be_an_instance_of(Templater::Template)
29
+ end
30
+
31
+ it "should add a template with destination and infer the source" do
32
+ @generator_class.template(:my_template, 'path/to/destination.rb')
33
+ @instance = @generator_class.new('/tmp/destination')
34
+
35
+ @instance.stub!(:source_root).and_return('/tmp/source')
36
+
37
+ @instance.template(:my_template).source.should == '/tmp/source/path/to/destination.rbt'
38
+ @instance.template(:my_template).destination.should == '/tmp/destination/path/to/destination.rb'
39
+ @instance.template(:my_template).should be_an_instance_of(Templater::Template)
40
+ end
41
+
42
+ it "should add a template with a block" do
43
+ @generator_class.template(:my_template) do
44
+ source 'blah.rbt'
45
+ destination "gurr#{Process.pid.to_s}.rb"
46
+ end
47
+ @instance = @generator_class.new('/tmp/destination')
48
+
49
+ @instance.stub!(:source_root).and_return('/tmp/source')
50
+
51
+ @instance.template(:my_template).source.should == '/tmp/source/blah.rbt'
52
+ @instance.template(:my_template).destination.should == "/tmp/destination/gurr#{Process.pid.to_s}.rb"
53
+ @instance.template(:my_template).should be_an_instance_of(Templater::Template)
54
+ end
55
+
56
+ it "should add a template and convert an with an instruction encoded in the destination, but not one encoded in the source" do
57
+ @generator_class.template(:my_template, 'template/%some_method%.rbt', 'template/%another_method%.rb')
58
+ @instance = @generator_class.new('/tmp/destination')
59
+
60
+ @instance.stub!(:source_root).and_return('/tmp/source')
61
+ @instance.should_not_receive(:some_method)
62
+ @instance.should_receive(:another_method).at_least(:once).and_return('beast')
63
+
64
+ @instance.template(:my_template).source.should == '/tmp/source/template/%some_method%.rbt'
65
+ @instance.template(:my_template).destination.should == "/tmp/destination/template/beast.rb"
66
+ @instance.template(:my_template).should be_an_instance_of(Templater::Template)
67
+ end
68
+
69
+ it "should add a template and leave an encoded instruction be if it doesn't exist as a method" do
70
+ @generator_class.template(:my_template, 'template/blah.rbt', 'template/%some_method%.rb')
71
+ @instance = @generator_class.new('/tmp/destination')
72
+
73
+ @instance.stub!(:source_root).and_return('/tmp/source')
74
+
75
+ @instance.template(:my_template).destination.should == "/tmp/destination/template/%some_method%.rb"
76
+ @instance.template(:my_template).should be_an_instance_of(Templater::Template)
77
+ end
78
+
79
+ end
@@ -0,0 +1,47 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Templater::Generator, '#templates' do
4
+
5
+ before do
6
+ @generator_class = Class.new(Templater::Generator)
7
+ @generator_class.class_eval do
8
+ def source_root
9
+ '/tmp/source'
10
+ end
11
+ end
12
+ end
13
+
14
+ it "should return all templates" do
15
+ @generator_class.template(:blah1, 'blah.rb')
16
+ @generator_class.template(:blah2, 'blah2.rb')
17
+
18
+ instance = @generator_class.new('/tmp')
19
+
20
+ instance.templates[0].name.should == :blah1
21
+ instance.templates[1].name.should == :blah2
22
+ end
23
+
24
+ it "should not return templates with an option that does not match." do
25
+ @generator_class.option :framework, :default => :rails
26
+
27
+ @generator_class.template(:merb, 'blah.rb', :framework => :merb)
28
+ @generator_class.template(:rails, 'blah2.rb', :framework => :rails)
29
+ @generator_class.template(:none, 'blah2.rb')
30
+
31
+ instance = @generator_class.new('/tmp')
32
+
33
+ instance.templates[0].name.should == :rails
34
+ instance.templates[1].name.should == :none
35
+
36
+ instance.framework = :merb
37
+ instance.templates[0].name.should == :merb
38
+ instance.templates[1].name.should == :none
39
+
40
+ instance.framework = :rails
41
+ instance.templates[0].name.should == :rails
42
+ instance.templates[1].name.should == :none
43
+
44
+ instance.framework = nil
45
+ instance.templates[0].name.should == :none
46
+ end
47
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: templater
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonas Nicklas
@@ -9,7 +9,7 @@ autorequire: templater
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-07-13 00:00:00 +02:00
12
+ date: 2008-07-22 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -55,6 +55,7 @@ files:
55
55
  - lib/templater/cli/parser.rb
56
56
  - lib/templater/core_ext
57
57
  - lib/templater/core_ext/string.rb
58
+ - lib/templater/empty_directory.rb
58
59
  - lib/templater/file.rb
59
60
  - lib/templater/generator.rb
60
61
  - lib/templater/manifold.rb
@@ -63,8 +64,31 @@ files:
63
64
  - lib/templater.rb
64
65
  - spec/core_ext
65
66
  - spec/core_ext/string_spec.rb
67
+ - spec/empty_directory_spec.rb
66
68
  - spec/file_spec.rb
67
- - spec/generator_spec.rb
69
+ - spec/generator
70
+ - spec/generator/actions_spec.rb
71
+ - spec/generator/argument_as_array_spec.rb
72
+ - spec/generator/argument_as_hash_spec.rb
73
+ - spec/generator/argument_spec.rb
74
+ - spec/generator/desc_spec.rb
75
+ - spec/generator/destination_root_spec.rb
76
+ - spec/generator/empty_directory_spec.rb
77
+ - spec/generator/file_getter_spec.rb
78
+ - spec/generator/file_list_spec.rb
79
+ - spec/generator/file_spec.rb
80
+ - spec/generator/files_spec.rb
81
+ - spec/generator/generators_spec.rb
82
+ - spec/generator/glob_spec.rb
83
+ - spec/generator/invocations_spec.rb
84
+ - spec/generator/invoke_spec.rb
85
+ - spec/generator/option_spec.rb
86
+ - spec/generator/source_root_getter_spec.rb
87
+ - spec/generator/source_root_spec.rb
88
+ - spec/generator/template_getter_spec.rb
89
+ - spec/generator/template_list_spec.rb
90
+ - spec/generator/template_spec.rb
91
+ - spec/generator/templates_spec.rb
68
92
  - spec/manifold_spec.rb
69
93
  - spec/results
70
94
  - spec/results/erb.rbs
@@ -1,1089 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
-
3
- describe Templater::Generator, '.desc' do
4
-
5
- it "should append text when called with an argument, and return it when called with no argument" do
6
- @generator_class = Class.new(Templater::Generator)
7
-
8
- @generator_class.desc "some text"
9
- @generator_class.desc.should == "some text"
10
- end
11
-
12
- end
13
-
14
- describe Templater::Generator, '.argument' do
15
-
16
- before do
17
- @generator_class = Class.new(Templater::Generator)
18
- end
19
-
20
- it "should create accessors" do
21
- @generator_class.argument(0, :monkey)
22
-
23
- instance = @generator_class.new('/tmp')
24
- instance.monkey = 'a test'
25
- instance.monkey.should == 'a test'
26
- end
27
-
28
- it "should pass an initial value to the argument" do
29
- @generator_class.argument(0, :monkey)
30
-
31
- instance = @generator_class.new('/tmp', {}, 'i am a monkey')
32
- instance.monkey.should == 'i am a monkey'
33
- end
34
-
35
- it "should create multiple accessors" do
36
- @generator_class.argument(0, :monkey)
37
- @generator_class.argument(1, :llama)
38
- @generator_class.argument(2, :herd)
39
-
40
- instance = @generator_class.new('/tmp')
41
- instance.monkey = 'a monkey'
42
- instance.monkey.should == 'a monkey'
43
- instance.llama = 'a llama'
44
- instance.llama.should == 'a llama'
45
- instance.herd = 'a herd'
46
- instance.herd.should == 'a herd'
47
- end
48
-
49
- it "should pass an initial value to multiple accessors" do
50
- @generator_class.argument(0, :monkey)
51
- @generator_class.argument(1, :llama)
52
- @generator_class.argument(2, :herd)
53
-
54
- instance = @generator_class.new('/tmp', {}, 'a monkey', 'a llama', 'a herd')
55
- instance.monkey.should == 'a monkey'
56
- instance.llama.should == 'a llama'
57
- instance.herd.should == 'a herd'
58
- end
59
-
60
- it "should set a default value for an argument" do
61
- @generator_class.argument(0, :monkey, :default => 'a revision')
62
-
63
- instance = @generator_class.new('/tmp')
64
- instance.monkey.should == 'a revision'
65
- end
66
-
67
- it "should allow some syntactic sugar declaration" do
68
- @generator_class.first_argument(:monkey)
69
- @generator_class.second_argument(:llama)
70
- @generator_class.third_argument(:herd)
71
- @generator_class.fourth_argument(:elephant)
72
-
73
- instance = @generator_class.new('/tmp', {}, 'a monkey', 'a llama', 'a herd', 'an elephant')
74
- instance.monkey.should == 'a monkey'
75
- instance.llama.should == 'a llama'
76
- instance.herd.should == 'a herd'
77
- instance.elephant.should == 'an elephant'
78
- end
79
-
80
- it "should whine when there are too many arguments" do
81
- @generator_class.argument(0, :monkey)
82
- @generator_class.argument(1, :llama)
83
-
84
- lambda { @generator_class.new('/tmp', {}, 'a monkey', 'a llama', 'a herd') }.should raise_error(Templater::TooManyArgumentsError)
85
- end
86
-
87
- it "should assign arguments if an argument is required and that requirement is fullfilled" do
88
- @generator_class.argument(0, :monkey, :required => true)
89
- @generator_class.argument(1, :elephant, :required => true)
90
- @generator_class.argument(2, :llama)
91
-
92
- instance = @generator_class.new('/tmp', {}, 'enough', 'arguments')
93
- instance.monkey.should == "enough"
94
- instance.elephant.should == "arguments"
95
- instance.llama.should be_nil
96
- end
97
-
98
- it "should raise an error when a required argument is not passed" do
99
- @generator_class.argument(0, :monkey, :required => true)
100
- @generator_class.argument(1, :elephant, :required => true)
101
- @generator_class.argument(2, :llama)
102
-
103
- lambda { @generator_class.new('/tmp', {}, 'too few arguments') }.should raise_error(Templater::TooFewArgumentsError)
104
- end
105
-
106
- it "should raise an error if nil is assigned to a require argument" do
107
- @generator_class.argument(0, :monkey, :required => true)
108
-
109
- instance = @generator_class.new('/tmp', {}, 'test')
110
-
111
- lambda { instance.monkey = nil }.should raise_error(Templater::TooFewArgumentsError)
112
- end
113
-
114
- it "should assign an argument when a block appended to an argument does not throw :invalid" do
115
- @generator_class.argument(0, :monkey) do
116
- 1 + 1
117
- end
118
- @generator_class.argument(1, :elephant) do
119
- false
120
- end
121
- @generator_class.argument(2, :llama)
122
-
123
- instance = @generator_class.new('/tmp', {}, 'blah', 'urgh')
124
- instance.monkey.should == 'blah'
125
- instance.elephant.should == 'urgh'
126
-
127
- instance.monkey = :harr
128
- instance.monkey.should == :harr
129
- end
130
-
131
- it "should raise an error with the throw message, when a block is appended to an argument and throws :invalid" do
132
- @generator_class.argument(0, :monkey) do
133
- throw :invalid, 'this is not a valid monkey, bad monkey!'
134
- end
135
-
136
- lambda { @generator_class.new('/tmp', {}, 'blah') }.should raise_error(Templater::ArgumentError, 'this is not a valid monkey, bad monkey!')
137
-
138
- instance = @generator_class.new('/tmp')
139
-
140
- lambda { instance.monkey = :anything }.should raise_error(Templater::ArgumentError, 'this is not a valid monkey, bad monkey!')
141
- end
142
-
143
- end
144
-
145
- describe Templater::Generator, '.argument as hash' do
146
-
147
- before do
148
- @generator_class = Class.new(Templater::Generator)
149
- @generator_class.argument(0, :monkey)
150
- @generator_class.argument(1, :llama, :as => :hash)
151
- end
152
-
153
- it "should allow assignment of hashes" do
154
- instance = @generator_class.new('/tmp', {}, 'a monkey', { :hash => 'blah' })
155
-
156
- instance.monkey.should == 'a monkey'
157
- instance.llama[:hash].should == 'blah'
158
-
159
- instance.llama = { :me_s_a => :hash }
160
- instance.llama[:me_s_a].should == :hash
161
- end
162
-
163
- it "should convert a key/value pair to a hash" do
164
- instance = @generator_class.new('/tmp', {}, 'a monkey', 'test:unit')
165
- instance.llama['test'].should == 'unit'
166
- end
167
-
168
- it "should consume the remaining arguments and convert them to a hash if they are key/value pairs" do
169
- instance = @generator_class.new('/tmp', {}, 'a monkey', 'test:unit', 'john:silver', 'river:road')
170
- instance.llama['test'].should == 'unit'
171
- instance.llama['john'].should == 'silver'
172
- instance.llama['river'].should == 'road'
173
- end
174
-
175
- it "should raise an error if one of the remaining arguments is not a key/value pair" do
176
- lambda { @generator_class.new('/tmp', {}, 'a monkey', 'a:llama', 'duck:llama', 'not_a_pair', 'pair:blah') }.should raise_error(Templater::MalformattedArgumentError)
177
- end
178
-
179
- it "should raise error if the argument is neither a hash nor a key/value pair" do
180
- lambda { @generator_class.new('/tmp', {}, 'a monkey', 23) }.should raise_error(Templater::MalformattedArgumentError)
181
- instance = @generator_class.new('/tmp')
182
- lambda { instance.llama = :not_a_hash }.should raise_error(Templater::MalformattedArgumentError)
183
- end
184
-
185
- end
186
-
187
- describe Templater::Generator, '.argument as array' do
188
-
189
- before do
190
- @generator_class = Class.new(Templater::Generator)
191
- @generator_class.argument(0, :monkey)
192
- @generator_class.argument(1, :llama, :as => :array)
193
- end
194
-
195
- it "should allow assignment of arrays" do
196
- instance = @generator_class.new('/tmp', {}, 'a monkey', %w(an array))
197
-
198
- instance.monkey.should == 'a monkey'
199
- instance.llama[0].should == 'an'
200
- instance.llama[1].should == 'array'
201
-
202
- instance.llama = %w(another donkey)
203
- instance.llama[0].should == 'another'
204
- instance.llama[1].should == 'donkey'
205
- end
206
-
207
- it "should convert a single argument to an array" do
208
- instance = @generator_class.new('/tmp', {}, 'a monkey', 'test')
209
- instance.llama[0].should == 'test'
210
- end
211
-
212
- it "should consume the remaining arguments and convert them to an array" do
213
- instance = @generator_class.new('/tmp', {}, 'a monkey', 'test', 'silver', 'river')
214
- instance.llama[0].should == 'test'
215
- instance.llama[1].should == 'silver'
216
- instance.llama[2].should == 'river'
217
- end
218
-
219
- it "should raise error if the argument is not an array" do
220
- instance = @generator_class.new('/tmp')
221
- lambda { instance.llama = :not_an_array }.should raise_error(Templater::MalformattedArgumentError)
222
- end
223
-
224
- end
225
-
226
- describe Templater::Generator, '.template' do
227
-
228
- before do
229
- @generator_class = Class.new(Templater::Generator)
230
- end
231
-
232
- it "should add a template with source and destination" do
233
- @generator_class.template(:my_template, 'path/to/source.rbt', 'path/to/destination.rb')
234
- @instance = @generator_class.new('/tmp/destination')
235
-
236
- @instance.stub!(:source_root).and_return('/tmp/source')
237
-
238
- @instance.template(:my_template).source.should == '/tmp/source/path/to/source.rbt'
239
- @instance.template(:my_template).destination.should == '/tmp/destination/path/to/destination.rb'
240
- @instance.template(:my_template).should be_an_instance_of(Templater::Template)
241
- end
242
-
243
- it "should add a template with absolute source and destination" do
244
- @generator_class.template(:my_template, '/path/to/source.rbt', '/path/to/destination.rb')
245
- @instance = @generator_class.new('/tmp/destination')
246
-
247
- @instance.stub!(:source_root).and_return('/tmp/source')
248
-
249
- @instance.template(:my_template).source.should == '/path/to/source.rbt'
250
- @instance.template(:my_template).destination.should == '/path/to/destination.rb'
251
- @instance.template(:my_template).should be_an_instance_of(Templater::Template)
252
- end
253
-
254
- it "should add a template with destination and infer the source" do
255
- @generator_class.template(:my_template, 'path/to/destination.rb')
256
- @instance = @generator_class.new('/tmp/destination')
257
-
258
- @instance.stub!(:source_root).and_return('/tmp/source')
259
-
260
- @instance.template(:my_template).source.should == '/tmp/source/path/to/destination.rbt'
261
- @instance.template(:my_template).destination.should == '/tmp/destination/path/to/destination.rb'
262
- @instance.template(:my_template).should be_an_instance_of(Templater::Template)
263
- end
264
-
265
- it "should add a template with a block" do
266
- @generator_class.template(:my_template) do
267
- source 'blah.rbt'
268
- destination "gurr#{Process.pid.to_s}.rb"
269
- end
270
- @instance = @generator_class.new('/tmp/destination')
271
-
272
- @instance.stub!(:source_root).and_return('/tmp/source')
273
-
274
- @instance.template(:my_template).source.should == '/tmp/source/blah.rbt'
275
- @instance.template(:my_template).destination.should == "/tmp/destination/gurr#{Process.pid.to_s}.rb"
276
- @instance.template(:my_template).should be_an_instance_of(Templater::Template)
277
- end
278
-
279
- it "should add a template with a block, joining multiple arguments" do
280
- @generator_class.template(:my_template) do
281
- source 'test', 'something', 'blah.rbt'
282
- destination 'test', "gurr#{Process.pid.to_s}.rb"
283
- end
284
- @instance = @generator_class.new('/tmp/destination')
285
-
286
- @instance.stub!(:source_root).and_return('/tmp/source')
287
-
288
- @instance.template(:my_template).source.should == '/tmp/source/test/something/blah.rbt'
289
- @instance.template(:my_template).destination.should == "/tmp/destination/test/gurr#{Process.pid.to_s}.rb"
290
- @instance.template(:my_template).should be_an_instance_of(Templater::Template)
291
- end
292
-
293
- it "should add a template and convert an with an instruction encoded in the destination, but not one encoded in the source" do
294
- @generator_class.template(:my_template, 'template/%some_method%.rbt', 'template/%another_method%.rb')
295
- @instance = @generator_class.new('/tmp/destination')
296
-
297
- @instance.stub!(:source_root).and_return('/tmp/source')
298
- @instance.should_not_receive(:some_method)
299
- @instance.should_receive(:another_method).at_least(:once).and_return('beast')
300
-
301
- @instance.template(:my_template).source.should == '/tmp/source/template/%some_method%.rbt'
302
- @instance.template(:my_template).destination.should == "/tmp/destination/template/beast.rb"
303
- @instance.template(:my_template).should be_an_instance_of(Templater::Template)
304
- end
305
-
306
- it "should add a template and leave an encoded instruction be if it doesn't exist as a method" do
307
- @generator_class.template(:my_template, 'template/blah.rbt', 'template/%some_method%.rb')
308
- @instance = @generator_class.new('/tmp/destination')
309
-
310
- @instance.stub!(:source_root).and_return('/tmp/source')
311
-
312
- @instance.template(:my_template).destination.should == "/tmp/destination/template/%some_method%.rb"
313
- @instance.template(:my_template).should be_an_instance_of(Templater::Template)
314
- end
315
-
316
- end
317
-
318
- describe Templater::Generator, '.file' do
319
-
320
- before do
321
- @generator_class = Class.new(Templater::Generator)
322
- end
323
-
324
- it "should add a file with source and destination" do
325
- @generator_class.file(:my_file, 'path/to/source.rbt', 'path/to/destination.rb')
326
- @instance = @generator_class.new('/tmp/destination')
327
-
328
- @instance.stub!(:source_root).and_return('/tmp/source')
329
-
330
- @instance.file(:my_file).source.should == '/tmp/source/path/to/source.rbt'
331
- @instance.file(:my_file).destination.should == '/tmp/destination/path/to/destination.rb'
332
- @instance.file(:my_file).should be_an_instance_of(Templater::File)
333
- end
334
-
335
- it "should add a file with absolute source and destination" do
336
- @generator_class.file(:my_file, '/path/to/source.rbt', '/path/to/destination.rb')
337
- @instance = @generator_class.new('/tmp/destination')
338
-
339
- @instance.stub!(:source_root).and_return('/tmp/source')
340
-
341
- @instance.file(:my_file).source.should == '/path/to/source.rbt'
342
- @instance.file(:my_file).destination.should == '/path/to/destination.rb'
343
- @instance.file(:my_file).should be_an_instance_of(Templater::File)
344
- end
345
-
346
- it "should add a file with source and infer destination " do
347
- @generator_class.file(:my_file, 'path/to/file.rb')
348
- @instance = @generator_class.new('/tmp/destination')
349
-
350
- @instance.stub!(:source_root).and_return('/tmp/source')
351
-
352
- @instance.file(:my_file).source.should == '/tmp/source/path/to/file.rb'
353
- @instance.file(:my_file).destination.should == '/tmp/destination/path/to/file.rb'
354
- @instance.file(:my_file).should be_an_instance_of(Templater::File)
355
- end
356
-
357
- it "should add a file with a block" do
358
- @generator_class.file(:my_file) do
359
- source 'blah.rbt'
360
- destination "gurr#{Process.pid.to_s}.rb"
361
- end
362
- @instance = @generator_class.new('/tmp/destination')
363
-
364
- @instance.stub!(:source_root).and_return('/tmp/source')
365
-
366
- @instance.file(:my_file).source.should == '/tmp/source/blah.rbt'
367
- @instance.file(:my_file).destination.should == "/tmp/destination/gurr#{Process.pid.to_s}.rb"
368
- @instance.file(:my_file).should be_an_instance_of(Templater::File)
369
- end
370
-
371
- it "should add a file with a block, joining multiple arguments" do
372
- @generator_class.file(:my_file) do
373
- source 'test', 'something', 'blah.rbt'
374
- destination 'test', "gurr#{Process.pid.to_s}.rb"
375
- end
376
- @instance = @generator_class.new('/tmp/destination')
377
-
378
- @instance.stub!(:source_root).and_return('/tmp/source')
379
-
380
- @instance.file(:my_file).source.should == '/tmp/source/test/something/blah.rbt'
381
- @instance.file(:my_file).destination.should == "/tmp/destination/test/gurr#{Process.pid.to_s}.rb"
382
- @instance.file(:my_file).should be_an_instance_of(Templater::File)
383
- end
384
-
385
-
386
- it "should add a file and convert an instruction encoded in the destination, but not one encoded in the source" do
387
- @generator_class.file(:my_file, 'template/%some_method%.rbt', 'template/%another_method%.rb')
388
- @instance = @generator_class.new('/tmp/destination')
389
-
390
- @instance.stub!(:source_root).and_return('/tmp/source')
391
- @instance.should_not_receive(:some_method)
392
- @instance.should_receive(:another_method).at_least(:once).and_return('beast')
393
-
394
- @instance.file(:my_file).source.should == '/tmp/source/template/%some_method%.rbt'
395
- @instance.file(:my_file).destination.should == "/tmp/destination/template/beast.rb"
396
- @instance.file(:my_file).should be_an_instance_of(Templater::File)
397
- end
398
-
399
- it "should add a file and leave an encoded instruction be if it doesn't exist as a method" do
400
- @generator_class.file(:my_file, 'template/blah.rbt', 'template/%some_method%.rb')
401
- @instance = @generator_class.new('/tmp/destination')
402
-
403
- @instance.stub!(:source_root).and_return('/tmp/source')
404
-
405
- @instance.file(:my_file).destination.should == "/tmp/destination/template/%some_method%.rb"
406
- @instance.file(:my_file).should be_an_instance_of(Templater::File)
407
- end
408
-
409
-
410
- end
411
-
412
- describe Templater::Generator, '.invoke' do
413
-
414
- before do
415
- @generator_class = Class.new(Templater::Generator)
416
- @generator_class.first_argument :test1
417
- @generator_class.second_argument :test2
418
-
419
- @invoked_generator = mock('an invoked generator')
420
- @invoked_instance = mock('an instance of the invoked generator')
421
- @invoked_generator.stub!(:new).and_return(@invoked_instance)
422
-
423
- @manifold = mock('a manifold')
424
- @manifold.stub!(:generator).with(:test).and_return(@invoked_generator)
425
- end
426
-
427
- it "should add nothing if there is no manifold" do
428
- @generator_class.invoke(:test)
429
- @instance = @generator_class.new('/tmp', {}, 'test', 'argument')
430
-
431
- @instance.invocations.should be_empty
432
- end
433
-
434
- describe "with no block" do
435
-
436
- before(:each) do
437
- @generator_class.stub!(:manifold).and_return(@manifold)
438
- end
439
-
440
- it "should return the instantiaded template" do
441
- @generator_class.invoke(:test)
442
- @instance = @generator_class.new('/tmp', {}, 'test', 'argument')
443
-
444
- @instance.invocations.first.should == @invoked_instance
445
- end
446
-
447
- it "should ask the manifold for the generator" do
448
- @generator_class.should_receive(:manifold).at_least(:once).and_return(@manifold)
449
- @manifold.should_receive(:generator).with(:test).and_return(@invoked_generator)
450
- @generator_class.invoke(:test)
451
- @instance = @generator_class.new('/tmp', {}, 'test', 'argument')
452
-
453
- @instance.invocations.first.should == @invoked_instance
454
- end
455
-
456
- it "should instantiate the generator with the correct arguments" do
457
- @invoked_generator.should_receive(:new).with('/tmp', {}, 'test', 'argument').and_return(@invoked_instance)
458
- @generator_class.invoke(:test)
459
- @instance = @generator_class.new('/tmp', {}, 'test', 'argument')
460
-
461
- @instance.invocations.first.should == @invoked_instance
462
- end
463
-
464
- end
465
-
466
- describe "with a block" do
467
-
468
- before(:each) do
469
- @generator_class.stub!(:manifold).and_return(@manifold)
470
- end
471
-
472
- it "should pass the generator class to the block and return the result of it" do
473
- @generator_class.invoke(:test) do |generator|
474
- generator.new(destination_root, options, 'blah', 'monkey', some_method)
475
- end
476
- @instance = @generator_class.new('/tmp', {}, 'test', 'argument')
477
-
478
- @instance.should_receive(:some_method).and_return('da')
479
- @invoked_generator.should_receive(:new).with('/tmp', {}, 'blah', 'monkey', 'da').and_return(@invoked_instance)
480
-
481
- @instance.invocations.first.should == @invoked_instance
482
- end
483
-
484
- it "should ask the manifold for the generator" do
485
- @generator_class.should_receive(:manifold).at_least(:once).and_return(@manifold)
486
- @manifold.should_receive(:generator).with(:test).and_return(@invoked_generator)
487
-
488
- @generator_class.invoke(:test) do |generator|
489
- generator.new(destination_root, options, 'blah', 'monkey')
490
- end
491
-
492
- @instance = @generator_class.new('/tmp', {}, 'test', 'argument')
493
- @instance.invocations.first.should == @invoked_instance
494
- end
495
-
496
- end
497
-
498
- end
499
-
500
- describe Templater::Generator, '.template_list' do
501
-
502
- it "should add a series of templates given a list as heredoc" do
503
- @generator_class = Class.new(Templater::Generator)
504
-
505
- @generator_class.should_receive(:template).with(:app_model_rb, 'app/model.rb')
506
- @generator_class.should_receive(:template).with(:spec_model_rb, 'spec/model.rb')
507
- @generator_class.should_receive(:template).with(:donkey_poo_css, 'donkey/poo.css')
508
- @generator_class.should_receive(:template).with(:john_smith_file_rb, 'john/smith/file.rb')
509
-
510
- @generator_class.template_list <<-LIST
511
- app/model.rb
512
- spec/model.rb
513
- donkey/poo.css
514
- john/smith/file.rb
515
- LIST
516
- end
517
-
518
- it "should add a series of templates given a list as array" do
519
- @generator_class = Class.new(Templater::Generator)
520
-
521
- @generator_class.should_receive(:template).with(:app_model_rb, 'app/model.rb')
522
- @generator_class.should_receive(:template).with(:spec_model_rb, 'spec/model.rb')
523
- @generator_class.should_receive(:template).with(:donkey_poo_css, 'donkey/poo.css')
524
- @generator_class.should_receive(:template).with(:john_smith_file_rb, 'john/smith/file.rb')
525
-
526
- @generator_class.template_list(%w(app/model.rb spec/model.rb donkey/poo.css john/smith/file.rb))
527
- end
528
-
529
- end
530
-
531
- describe Templater::Generator, '.file_list' do
532
-
533
- it "should add a series of files given a list as heredoc" do
534
- @generator_class = Class.new(Templater::Generator)
535
-
536
- @generator_class.should_receive(:file).with(:app_model_rb, 'app/model.rb')
537
- @generator_class.should_receive(:file).with(:spec_model_rb, 'spec/model.rb')
538
- @generator_class.should_receive(:file).with(:donkey_poo_css, 'donkey/poo.css')
539
- @generator_class.should_receive(:file).with(:john_smith_file_rb, 'john/smith/file.rb')
540
-
541
- @generator_class.file_list <<-LIST
542
- app/model.rb
543
- spec/model.rb
544
- donkey/poo.css
545
- john/smith/file.rb
546
- LIST
547
- end
548
-
549
- it "should add a series of files given a list as array" do
550
- @generator_class = Class.new(Templater::Generator)
551
-
552
- @generator_class.should_receive(:file).with(:app_model_rb, 'app/model.rb')
553
- @generator_class.should_receive(:file).with(:spec_model_rb, 'spec/model.rb')
554
- @generator_class.should_receive(:file).with(:donkey_poo_css, 'donkey/poo.css')
555
- @generator_class.should_receive(:file).with(:john_smith_file_rb, 'john/smith/file.rb')
556
-
557
- @generator_class.file_list(%w(app/model.rb spec/model.rb donkey/poo.css john/smith/file.rb))
558
- end
559
-
560
- end
561
-
562
- describe Templater::Generator, '.glob!' do
563
-
564
- before do
565
- @generator_class = Class.new(Templater::Generator)
566
- @generator_class.stub!(:source_root).and_return(template_path('glob'))
567
- end
568
-
569
- it "should add templates and files in the source_root based on if their extensions are in the template_extensions array" do
570
- @generator_class.glob!()
571
-
572
- @instance = @generator_class.new('/tmp/destination')
573
-
574
- @instance.template(:arg_js).source.should == template_path('glob/arg.js')
575
- @instance.template(:arg_js).destination.should == "/tmp/destination/arg.js"
576
-
577
- @instance.template(:test_rb).source.should == template_path('glob/test.rb')
578
- @instance.template(:test_rb).destination.should == "/tmp/destination/test.rb"
579
-
580
- @instance.file(:subfolder_jessica_alba_jpg).source.should == template_path('glob/subfolder/jessica_alba.jpg')
581
- @instance.file(:subfolder_jessica_alba_jpg).destination.should == '/tmp/destination/subfolder/jessica_alba.jpg'
582
- end
583
-
584
- it "should add templates and files with a different template_extensions array" do
585
- @generator_class.glob!(nil, %w(jpg))
586
-
587
- @instance = @generator_class.new('/tmp/destination')
588
-
589
- @instance.file(:arg_js).source.should == template_path('glob/arg.js')
590
- @instance.file(:arg_js).destination.should == "/tmp/destination/arg.js"
591
-
592
- @instance.file(:test_rb).source.should == template_path('glob/test.rb')
593
- @instance.file(:test_rb).destination.should == "/tmp/destination/test.rb"
594
-
595
- @instance.template(:subfolder_jessica_alba_jpg).source.should == template_path('glob/subfolder/jessica_alba.jpg')
596
- @instance.template(:subfolder_jessica_alba_jpg).destination.should == '/tmp/destination/subfolder/jessica_alba.jpg'
597
- end
598
-
599
- it "should glob in a subdirectory" do
600
- @generator_class.stub!(:source_root).and_return(template_path(""))
601
- @generator_class.glob!('glob', %w(jpg))
602
-
603
- @instance = @generator_class.new('/tmp/destination')
604
-
605
- @instance.file(:glob_arg_js).source.should == template_path('glob/arg.js')
606
- @instance.file(:glob_arg_js).destination.should == "/tmp/destination/glob/arg.js"
607
-
608
- @instance.file(:glob_test_rb).source.should == template_path('glob/test.rb')
609
- @instance.file(:glob_test_rb).destination.should == "/tmp/destination/glob/test.rb"
610
-
611
- @instance.template(:glob_subfolder_jessica_alba_jpg).source.should == template_path('glob/subfolder/jessica_alba.jpg')
612
- @instance.template(:glob_subfolder_jessica_alba_jpg).destination.should == '/tmp/destination/glob/subfolder/jessica_alba.jpg'
613
- end
614
-
615
- it "should add only the given templates and files" do
616
- @generator_class.glob!()
617
-
618
- @instance = @generator_class.new('/tmp/destination')
619
-
620
- @instance.templates.map { |t| t.name }.should == [
621
- :arg_js,
622
- :subfolder_monkey_rb,
623
- :test_rb,
624
- ]
625
- @instance.files.map { |f| f.name }.should == [
626
- :readme,
627
- :subfolder_jessica_alba_jpg
628
- ]
629
- end
630
-
631
- end
632
-
633
- describe Templater::Generator, '.option' do
634
-
635
- before do
636
- @generator_class = Class.new(Templater::Generator)
637
- end
638
-
639
- it "should add accessors" do
640
- @generator_class.option(:test)
641
-
642
- instance = @generator_class.new('/tmp')
643
-
644
- instance.test = "monkey"
645
- instance.test.should == "monkey"
646
-
647
- end
648
-
649
- it "should preset a default value" do
650
- @generator_class.option(:test, :default => 'elephant')
651
-
652
- instance = @generator_class.new('/tmp')
653
-
654
- instance.test.should == "elephant"
655
- end
656
-
657
- it "should allow overwriting of default values" do
658
- @generator_class.option(:test, :default => 'elephant')
659
-
660
- instance = @generator_class.new('/tmp')
661
-
662
- instance.test.should == "elephant"
663
- instance.test = "monkey"
664
- instance.test.should == "monkey"
665
- end
666
-
667
- it "should allow passing in of options on generator creation" do
668
- @generator_class.option(:test, :default => 'elephant')
669
-
670
- instance = @generator_class.new('/tmp', { :test => 'freebird' })
671
-
672
- instance.test.should == "freebird"
673
- instance.test = "monkey"
674
- instance.test.should == "monkey"
675
- end
676
- end
677
-
678
- describe Templater::Generator, '.generators' do
679
-
680
- before do
681
- @generator_class = Class.new(Templater::Generator)
682
-
683
- @g1 = Class.new(Templater::Generator)
684
- @g2 = Class.new(Templater::Generator)
685
- @g3 = Class.new(Templater::Generator)
686
- @g4 = Class.new(Templater::Generator)
687
-
688
- @manifold = mock('a manifold')
689
- @manifold.stub!(:generator).with(:monkey).and_return(@g1)
690
- @manifold.stub!(:generator).with(:blah).and_return(@g2)
691
- @manifold.stub!(:generator).with(:duck).and_return(@g3)
692
- @manifold.stub!(:generator).with(:llama).and_return(@g4)
693
- @manifold.stub!(:generator).with(:i_dont_exist).and_return(nil)
694
-
695
- @generator_class.manifold = @manifold
696
- @g1.manifold = @manifold
697
- @g2.manifold = @manifold
698
- @g3.manifold = @manifold
699
- @g4.manifold = @manifold
700
- end
701
-
702
- it "should return [self] when no manifold or invocations exist" do
703
- @generator_class.manifold = nil
704
- @generator_class.generators.should == [@generator_class]
705
- end
706
-
707
- it "should return [self] when only invocations exist" do
708
- @generator_class.manifold = nil
709
- @generator_class.invoke(:monkey)
710
- @generator_class.invoke(:blah)
711
- @generator_class.generators.should == [@generator_class]
712
- end
713
-
714
- it "should return a list of invoked generators" do
715
- @generator_class.invoke(:monkey)
716
- @generator_class.invoke(:blah)
717
-
718
- @generator_class.generators.should == [@generator_class, @g1, @g2]
719
- end
720
-
721
- it "should return a list of invoked generators recursively" do
722
- @generator_class.invoke(:monkey)
723
- @generator_class.invoke(:blah)
724
- @g1.invoke(:duck)
725
- @g3.invoke(:llama)
726
-
727
- @generator_class.generators.should == [@generator_class, @g1, @g3, @g4, @g2]
728
- end
729
-
730
- it "should ignore invocations that do not exist in the manifold" do
731
- @generator_class.invoke(:monkey)
732
- @generator_class.invoke(:blah)
733
- @g1.invoke(:duck)
734
- @g3.invoke(:i_dont_exist)
735
-
736
- @generator_class.generators.should == [@generator_class, @g1, @g3, @g2]
737
- end
738
- end
739
-
740
- describe Templater::Generator, '.source_root' do
741
- it "should raise an error, complaining that source_root must be overridden" do
742
- @generator_class = Class.new(Templater::Generator)
743
- lambda { @generator_class.source_root }.should raise_error(Templater::SourceNotSpecifiedError)
744
- end
745
- end
746
-
747
- describe Templater::Generator, '#template' do
748
-
749
- before do
750
- @generator_class = Class.new(Templater::Generator)
751
- @generator_class.class_eval do
752
- def source_root
753
- '/tmp/source'
754
- end
755
- end
756
- end
757
-
758
- it "should find a template by name" do
759
- @generator_class.template(:blah1, 'blah.rb')
760
- @generator_class.template(:blah2, 'blah2.rb')
761
-
762
- instance = @generator_class.new('/tmp')
763
-
764
- instance.template(:blah1).name.should == :blah1
765
- instance.template(:blah1).source.should == '/tmp/source/blah.rbt'
766
- instance.template(:blah1).destination.should == '/tmp/blah.rb'
767
- end
768
-
769
- it "should not return a template with an option that does not match." do
770
- @generator_class.option :framework, :default => :rails
771
-
772
- @generator_class.template(:merb, 'blah.rb', :framework => :merb)
773
- @generator_class.template(:rails, 'blah2.rb', :framework => :rails)
774
- @generator_class.template(:none, 'blah2.rb')
775
-
776
- instance = @generator_class.new('/tmp')
777
-
778
- instance.template(:rails).name.should == :rails
779
- instance.template(:merb).should be_nil
780
- instance.template(:none).name.should == :none
781
-
782
- instance.framework = :merb
783
- instance.template(:rails).should be_nil
784
- instance.template(:merb).name.should == :merb
785
- instance.template(:none).name.should == :none
786
-
787
- instance.framework = nil
788
- instance.template(:rails).should be_nil
789
- instance.template(:merb).should be_nil
790
- instance.template(:none).name.should == :none
791
- end
792
- end
793
-
794
- describe Templater::Generator, '#templates' do
795
-
796
- before do
797
- @generator_class = Class.new(Templater::Generator)
798
- @generator_class.class_eval do
799
- def source_root
800
- '/tmp/source'
801
- end
802
- end
803
- end
804
-
805
- it "should return all templates" do
806
- @generator_class.template(:blah1, 'blah.rb')
807
- @generator_class.template(:blah2, 'blah2.rb')
808
-
809
- instance = @generator_class.new('/tmp')
810
-
811
- instance.templates[0].name.should == :blah1
812
- instance.templates[1].name.should == :blah2
813
- end
814
-
815
- it "should not return templates with an option that does not match." do
816
- @generator_class.option :framework, :default => :rails
817
-
818
- @generator_class.template(:merb, 'blah.rb', :framework => :merb)
819
- @generator_class.template(:rails, 'blah2.rb', :framework => :rails)
820
- @generator_class.template(:none, 'blah2.rb')
821
-
822
- instance = @generator_class.new('/tmp')
823
-
824
- instance.templates[0].name.should == :rails
825
- instance.templates[1].name.should == :none
826
-
827
- instance.framework = :merb
828
- instance.templates[0].name.should == :merb
829
- instance.templates[1].name.should == :none
830
-
831
- instance.framework = :rails
832
- instance.templates[0].name.should == :rails
833
- instance.templates[1].name.should == :none
834
-
835
- instance.framework = nil
836
- instance.templates[0].name.should == :none
837
- end
838
- end
839
-
840
- describe Templater::Generator, '#file' do
841
-
842
- before do
843
- @generator_class = Class.new(Templater::Generator)
844
- @generator_class.class_eval do
845
- def source_root
846
- '/tmp/source'
847
- end
848
- end
849
- end
850
-
851
- it "should find a file by name" do
852
- @generator_class.file(:blah1, 'blah.rb')
853
- @generator_class.file(:blah2, 'blah2.rb')
854
-
855
- instance = @generator_class.new('/tmp')
856
-
857
- instance.file(:blah1).name.should == :blah1
858
- instance.file(:blah1).source.should == '/tmp/source/blah.rb'
859
- instance.file(:blah1).destination.should == '/tmp/blah.rb'
860
- end
861
-
862
- it "should not return a file with an option that does not match." do
863
- @generator_class.option :framework, :default => :rails
864
-
865
- @generator_class.file(:merb, 'blah.rb', :framework => :merb)
866
- @generator_class.file(:rails, 'blah2.rb', :framework => :rails)
867
- @generator_class.file(:none, 'blah2.rb')
868
-
869
- instance = @generator_class.new('/tmp')
870
-
871
- instance.file(:rails).name.should == :rails
872
- instance.file(:merb).should be_nil
873
- instance.file(:none).name.should == :none
874
-
875
- instance.framework = :merb
876
- instance.file(:rails).should be_nil
877
- instance.file(:merb).name.should == :merb
878
- instance.file(:none).name.should == :none
879
-
880
- instance.framework = nil
881
- instance.file(:rails).should be_nil
882
- instance.file(:merb).should be_nil
883
- instance.file(:none).name.should == :none
884
- end
885
- end
886
-
887
- describe Templater::Generator, '#files' do
888
-
889
- before do
890
- @generator_class = Class.new(Templater::Generator)
891
- @generator_class.class_eval do
892
- def source_root
893
- '/tmp/source'
894
- end
895
- end
896
- end
897
-
898
- it "should return all files" do
899
- @generator_class.file(:blah1, 'blah.rb')
900
- @generator_class.file(:blah2, 'blah2.rb')
901
-
902
- instance = @generator_class.new('/tmp')
903
-
904
- instance.files[0].name.should == :blah1
905
- instance.files[1].name.should == :blah2
906
- end
907
-
908
- it "should not return files with an option that does not match." do
909
- @generator_class.option :framework, :default => :rails
910
-
911
- @generator_class.file(:merb, 'blah.rb', :framework => :merb)
912
- @generator_class.file(:rails, 'blah2.rb', :framework => :rails)
913
- @generator_class.file(:none, 'blah2.rb')
914
-
915
- instance = @generator_class.new('/tmp')
916
-
917
- instance.files[0].name.should == :rails
918
- instance.files[1].name.should == :none
919
-
920
- instance.framework = :merb
921
- instance.files[0].name.should == :merb
922
- instance.files[1].name.should == :none
923
-
924
- instance.framework = :rails
925
- instance.files[0].name.should == :rails
926
- instance.files[1].name.should == :none
927
-
928
- instance.framework = nil
929
- instance.files[0].name.should == :none
930
- end
931
- end
932
-
933
- describe Templater::Generator, '#invocations' do
934
-
935
- before do
936
- @generator_class = Class.new(Templater::Generator)
937
- @generator_class.class_eval do
938
- def source_root
939
- '/tmp/source'
940
- end
941
- end
942
-
943
- @generator1 = mock('a generator for merb')
944
- @instance1 = mock('an instance of the generator for merb')
945
- @generator1.stub!(:new).and_return(@instance1)
946
- @generator2 = mock('a generator for rails')
947
- @instance2 = mock('an instance of the generator for rails')
948
- @generator2.stub!(:new).and_return(@instance2)
949
- @generator3 = mock('a generator for both')
950
- @instance3 = mock('an instance of the generator for both')
951
- @generator3.stub!(:new).and_return(@instance3)
952
-
953
- @manifold = mock('a manifold')
954
- @manifold.stub!(:generator).with(:merb).and_return(@generator1)
955
- @manifold.stub!(:generator).with(:rails).and_return(@generator2)
956
- @manifold.stub!(:generator).with(:both).and_return(@generator3)
957
-
958
- @generator_class.stub!(:manifold).and_return(@manifold)
959
- end
960
-
961
- it "should return all invocations" do
962
- @generator_class.invoke(:merb)
963
- @generator_class.invoke(:rails)
964
-
965
- instance = @generator_class.new('/tmp')
966
-
967
- instance.invocations[0].should == @instance1
968
- instance.invocations[1].should == @instance2
969
- end
970
-
971
- it "should not return templates with an option that does not match." do
972
- @generator_class.option :framework, :default => :rails
973
-
974
- @generator_class.invoke(:merb, :framework => :merb)
975
- @generator_class.invoke(:rails, :framework => :rails)
976
- @generator_class.invoke(:both)
977
-
978
- instance = @generator_class.new('/tmp')
979
-
980
- instance.invocations[0].should == @instance2
981
- instance.invocations[1].should == @instance3
982
-
983
- instance.framework = :merb
984
- instance.invocations[0].should == @instance1
985
- instance.invocations[1].should == @instance3
986
-
987
- instance.framework = :rails
988
- instance.invocations[0].should == @instance2
989
- instance.invocations[1].should == @instance3
990
-
991
- instance.framework = nil
992
- instance.invocations[0].should == @instance3
993
- end
994
- end
995
-
996
- describe Templater::Generator, '#actions' do
997
-
998
- before do
999
- @generator_class = Class.new(Templater::Generator)
1000
- @generator_class.class_eval do
1001
- def source_root
1002
- '/tmp/source'
1003
- end
1004
- end
1005
-
1006
- @generator1 = mock('a generator')
1007
- @instance1 = mock('an instance of the generator')
1008
- @generator1.stub!(:new).and_return(@instance1)
1009
- @generator2 = mock('another generator')
1010
- @instance2 = mock('an instance of another generator')
1011
- @generator2.stub!(:new).and_return(@instance2)
1012
-
1013
- @manifold = mock('a manifold')
1014
- @manifold.stub!(:generator).with(:one).and_return(@generator1)
1015
- @manifold.stub!(:generator).with(:two).and_return(@generator2)
1016
- @manifold.stub!(:generator).with(:three).and_return(@generator3)
1017
-
1018
- @generator_class.stub!(:manifold).and_return(@manifold)
1019
- end
1020
-
1021
- it "should return all templates and files" do
1022
- instance = @generator_class.new('/tmp')
1023
- instance.should_receive(:templates).at_least(:once).and_return(['template1', 'template2'])
1024
- instance.should_receive(:files).at_least(:once).and_return(['file1', 'file2'])
1025
-
1026
- instance.actions.should include('template1')
1027
- instance.actions.should include('template2')
1028
- instance.actions.should include('file1')
1029
- instance.actions.should include('file2')
1030
- end
1031
-
1032
- it "should return all templates and files recursively for all invocations" do
1033
- instance = @generator_class.new('/tmp')
1034
- instance.should_receive(:templates).at_least(:once).and_return(['template1', 'template2'])
1035
- instance.should_receive(:files).at_least(:once).and_return(['file1', 'file2'])
1036
- instance.should_receive(:invocations).at_least(:once).and_return([@instance1, @instance2])
1037
-
1038
- @instance1.should_receive(:actions).at_least(:once).and_return(['subtemplate1', 'subfile1'])
1039
- @instance2.should_receive(:actions).at_least(:once).and_return(['subtemplate2', 'subfile2'])
1040
-
1041
- instance.actions.should include('template1')
1042
- instance.actions.should include('template2')
1043
- instance.actions.should include('subtemplate1')
1044
- instance.actions.should include('subtemplate2')
1045
- instance.actions.should include('file1')
1046
- instance.actions.should include('file2')
1047
- instance.actions.should include('subfile1')
1048
- instance.actions.should include('subfile2')
1049
- end
1050
-
1051
- end
1052
-
1053
- describe Templater::Generator, '#invoke!' do
1054
-
1055
- before do
1056
- @generator_class = Class.new(Templater::Generator)
1057
- end
1058
-
1059
- it "should invoke all templates" do
1060
- template1 = mock('a template')
1061
- template2 = mock('another template')
1062
-
1063
- instance = @generator_class.new('/tmp')
1064
-
1065
- instance.should_receive(:templates).and_return([template1, template2])
1066
- template1.should_receive(:invoke!)
1067
- template2.should_receive(:invoke!)
1068
-
1069
- instance.invoke!
1070
- end
1071
- end
1072
-
1073
- describe Templater::Generator, '#destination_root' do
1074
- it "should be remembered" do
1075
- @generator_class = Class.new(Templater::Generator)
1076
- instance = @generator_class.new('/path/to/destination')
1077
- instance.destination_root.should == '/path/to/destination'
1078
- end
1079
- end
1080
-
1081
- describe Templater::Generator, '#source_root' do
1082
- it "try to retrieve the source root from the class" do
1083
- @generator_class = Class.new(Templater::Generator)
1084
- @generator_class.should_receive(:source_root).and_return('/tmp/source')
1085
-
1086
- instance = @generator_class.new('/tmp')
1087
- instance.source_root.should == '/tmp/source'
1088
- end
1089
- end