templater 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/templater/actions/file.rb +1 -1
- data/lib/templater/actions/template.rb +1 -1
- data/lib/templater/cli/generator.rb +1 -2
- data/lib/templater/generator.rb +42 -32
- data/lib/templater/proxy.rb +5 -3
- data/lib/templater/spec/helpers.rb +67 -0
- data/lib/templater.rb +1 -1
- data/spec/file_spec.rb +6 -0
- data/spec/generator/{argument_spec.rb → arguments_spec.rb} +81 -0
- data/spec/generator/empty_directories_spec.rb +140 -0
- data/spec/generator/files_spec.rb +161 -0
- data/spec/generator/invocations_spec.rb +110 -1
- data/spec/generator/invoke_spec.rb +0 -88
- data/spec/generator/{option_spec.rb → options_spec.rb} +0 -0
- data/spec/generator/source_root_spec.rb +10 -0
- data/spec/generator/templates_spec.rb +173 -0
- data/spec/spec_helpers_spec.rb +85 -0
- data/spec/template_spec.rb +6 -0
- metadata +8 -14
- data/spec/generator/argument_as_array_spec.rb +0 -40
- data/spec/generator/argument_as_hash_spec.rb +0 -43
- data/spec/generator/empty_directory_spec.rb +0 -20
- data/spec/generator/file_getter_spec.rb +0 -48
- data/spec/generator/file_list_spec.rb +0 -32
- data/spec/generator/file_spec.rb +0 -53
- data/spec/generator/source_root_getter_spec.rb +0 -11
- data/spec/generator/template_getter_spec.rb +0 -48
- data/spec/generator/template_list_spec.rb +0 -32
- data/spec/generator/template_spec.rb +0 -79
@@ -1,5 +1,117 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
2
|
|
3
|
+
describe Templater::Generator, '.file' do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@generator_class = Class.new(Templater::Generator)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should add a file with source and destination" do
|
10
|
+
@generator_class.file(: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.file(:my_template).source.should == '/tmp/source/path/to/source.rbt'
|
16
|
+
@instance.file(:my_template).destination.should == '/tmp/destination/path/to/destination.rb'
|
17
|
+
@instance.file(:my_template).should be_an_instance_of(Templater::Actions::File)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should add a file with source and infer destination " do
|
21
|
+
@generator_class.file(:my_template, 'path/to/file.rb')
|
22
|
+
@instance = @generator_class.new('/tmp/destination')
|
23
|
+
|
24
|
+
@instance.stub!(:source_root).and_return('/tmp/source')
|
25
|
+
|
26
|
+
@instance.file(:my_template).source.should == '/tmp/source/path/to/file.rb'
|
27
|
+
@instance.file(:my_template).destination.should == '/tmp/destination/path/to/file.rb'
|
28
|
+
@instance.file(:my_template).should be_an_instance_of(Templater::Actions::File)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should add a file with a block" do
|
32
|
+
@generator_class.file(:my_file) do
|
33
|
+
source 'blah.rbt'
|
34
|
+
destination "gurr#{Process.pid.to_s}.rb"
|
35
|
+
end
|
36
|
+
@instance = @generator_class.new('/tmp/destination')
|
37
|
+
|
38
|
+
@instance.stub!(:source_root).and_return('/tmp/source')
|
39
|
+
|
40
|
+
@instance.file(:my_file).source.should == '/tmp/source/blah.rbt'
|
41
|
+
@instance.file(:my_file).destination.should == "/tmp/destination/gurr#{Process.pid.to_s}.rb"
|
42
|
+
@instance.file(:my_file).should be_an_instance_of(Templater::Actions::File)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should add a file with a complex block" do
|
46
|
+
@generator_class.file(:my_file) do
|
47
|
+
source 'blah', 'blah.rbt'
|
48
|
+
destination 'gurr', "gurr#{something}.rb"
|
49
|
+
end
|
50
|
+
@instance = @generator_class.new('/tmp/destination')
|
51
|
+
|
52
|
+
@instance.stub!(:something).and_return('anotherthing')
|
53
|
+
@instance.stub!(:source_root).and_return('/tmp/source')
|
54
|
+
|
55
|
+
@instance.file(:my_file).source.should == '/tmp/source/blah/blah.rbt'
|
56
|
+
@instance.file(:my_file).destination.should == "/tmp/destination/gurr/gurranotherthing.rb"
|
57
|
+
@instance.file(:my_file).should be_an_instance_of(Templater::Actions::File)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should add a file and convert an instruction encoded in the destination, but not one encoded in the source" do
|
61
|
+
@generator_class.file(:my_template, 'template/%some_method%.rbt', 'template/%another_method%.rb')
|
62
|
+
@instance = @generator_class.new('/tmp/destination')
|
63
|
+
|
64
|
+
@instance.stub!(:source_root).and_return('/tmp/source')
|
65
|
+
@instance.should_not_receive(:some_method)
|
66
|
+
@instance.should_receive(:another_method).at_least(:once).and_return('beast')
|
67
|
+
|
68
|
+
@instance.file(:my_template).source.should == '/tmp/source/template/%some_method%.rbt'
|
69
|
+
@instance.file(:my_template).destination.should == "/tmp/destination/template/beast.rb"
|
70
|
+
@instance.file(:my_template).should be_an_instance_of(Templater::Actions::File)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should add a file and leave an encoded instruction be if it doesn't exist as a method" do
|
74
|
+
@generator_class.file(:my_template, 'template/blah.rbt', 'template/%some_method%.rb')
|
75
|
+
@instance = @generator_class.new('/tmp/destination')
|
76
|
+
|
77
|
+
@instance.stub!(:source_root).and_return('/tmp/source')
|
78
|
+
|
79
|
+
@instance.file(:my_template).destination.should == "/tmp/destination/template/%some_method%.rb"
|
80
|
+
@instance.file(:my_template).should be_an_instance_of(Templater::Actions::File)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe Templater::Generator, '.file_list' do
|
85
|
+
|
86
|
+
it "should add a series of files given a list as heredoc" do
|
87
|
+
@generator_class = Class.new(Templater::Generator)
|
88
|
+
|
89
|
+
@generator_class.should_receive(:file).with(:app_model_rb, 'app/model.rb')
|
90
|
+
@generator_class.should_receive(:file).with(:spec_model_rb, 'spec/model.rb')
|
91
|
+
@generator_class.should_receive(:file).with(:donkey_poo_css, 'donkey/poo.css')
|
92
|
+
@generator_class.should_receive(:file).with(:john_smith_file_rb, 'john/smith/file.rb')
|
93
|
+
|
94
|
+
@generator_class.file_list <<-LIST
|
95
|
+
app/model.rb
|
96
|
+
spec/model.rb
|
97
|
+
donkey/poo.css
|
98
|
+
john/smith/file.rb
|
99
|
+
LIST
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should add a series of files given a list as array" do
|
103
|
+
@generator_class = Class.new(Templater::Generator)
|
104
|
+
|
105
|
+
@generator_class.should_receive(:file).with(:app_model_rb, 'app/model.rb')
|
106
|
+
@generator_class.should_receive(:file).with(:spec_model_rb, 'spec/model.rb')
|
107
|
+
@generator_class.should_receive(:file).with(:donkey_poo_css, 'donkey/poo.css')
|
108
|
+
@generator_class.should_receive(:file).with(:john_smith_file_rb, 'john/smith/file.rb')
|
109
|
+
|
110
|
+
@generator_class.file_list(%w(app/model.rb spec/model.rb donkey/poo.css john/smith/file.rb))
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
|
3
115
|
describe Templater::Generator, '#files' do
|
4
116
|
|
5
117
|
before do
|
@@ -45,3 +157,52 @@ describe Templater::Generator, '#files' do
|
|
45
157
|
instance.files[0].name.should == :none
|
46
158
|
end
|
47
159
|
end
|
160
|
+
|
161
|
+
|
162
|
+
describe Templater::Generator, '#file' do
|
163
|
+
|
164
|
+
before do
|
165
|
+
@generator_class = Class.new(Templater::Generator)
|
166
|
+
@generator_class.class_eval do
|
167
|
+
def source_root
|
168
|
+
'/tmp/source'
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
it "should find a file by name" do
|
174
|
+
@generator_class.file(:blah1, 'blah.rb')
|
175
|
+
@generator_class.file(:blah2, 'blah2.rb')
|
176
|
+
|
177
|
+
instance = @generator_class.new('/tmp')
|
178
|
+
|
179
|
+
instance.file(:blah1).name.should == :blah1
|
180
|
+
instance.file(:blah1).source.should == '/tmp/source/blah.rb'
|
181
|
+
instance.file(:blah1).destination.should == '/tmp/blah.rb'
|
182
|
+
end
|
183
|
+
|
184
|
+
it "should not return a file with an option that does not match." do
|
185
|
+
@generator_class.send(:attr_accessor, :framework)
|
186
|
+
|
187
|
+
@generator_class.file(:merb, 'blah.rb', :framework => :merb)
|
188
|
+
@generator_class.file(:rails, 'blah2.rb', :framework => :rails)
|
189
|
+
@generator_class.file(:none, 'blah2.rb')
|
190
|
+
|
191
|
+
instance = @generator_class.new('/tmp')
|
192
|
+
|
193
|
+
instance.framework = :rails
|
194
|
+
instance.file(:rails).name.should == :rails
|
195
|
+
instance.file(:merb).should be_nil
|
196
|
+
instance.file(:none).name.should == :none
|
197
|
+
|
198
|
+
instance.framework = :merb
|
199
|
+
instance.file(:rails).should be_nil
|
200
|
+
instance.file(:merb).name.should == :merb
|
201
|
+
instance.file(:none).name.should == :none
|
202
|
+
|
203
|
+
instance.framework = nil
|
204
|
+
instance.file(:rails).should be_nil
|
205
|
+
instance.file(:merb).should be_nil
|
206
|
+
instance.file(:none).name.should == :none
|
207
|
+
end
|
208
|
+
end
|
@@ -1,5 +1,91 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
2
|
|
3
|
+
describe Templater::Generator, '.invoke' do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@generator_class = Class.new(Templater::Generator)
|
7
|
+
@generator_class.first_argument :test1
|
8
|
+
@generator_class.second_argument :test2
|
9
|
+
|
10
|
+
@invoked_generator = mock('an invoked generator')
|
11
|
+
@invoked_instance = mock('an instance of the invoked generator')
|
12
|
+
@invoked_generator.stub!(:new).and_return(@invoked_instance)
|
13
|
+
|
14
|
+
@manifold = mock('a manifold')
|
15
|
+
@manifold.stub!(:generator).with(:test).and_return(@invoked_generator)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should add nothing if there is no manifold" do
|
19
|
+
@generator_class.invoke(:test)
|
20
|
+
@instance = @generator_class.new('/tmp', {}, 'test', 'argument')
|
21
|
+
|
22
|
+
@instance.invocations.should be_empty
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "with no block" do
|
26
|
+
|
27
|
+
before(:each) do
|
28
|
+
@generator_class.stub!(:manifold).and_return(@manifold)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should return the instantiaded template" do
|
32
|
+
@generator_class.invoke(:test)
|
33
|
+
@instance = @generator_class.new('/tmp', {}, 'test', 'argument')
|
34
|
+
|
35
|
+
@instance.invocations.first.should == @invoked_instance
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should ask the manifold for the generator" do
|
39
|
+
@generator_class.should_receive(:manifold).at_least(:once).and_return(@manifold)
|
40
|
+
@manifold.should_receive(:generator).with(:test).and_return(@invoked_generator)
|
41
|
+
@generator_class.invoke(:test)
|
42
|
+
@instance = @generator_class.new('/tmp', {}, 'test', 'argument')
|
43
|
+
|
44
|
+
@instance.invocations.first.should == @invoked_instance
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should instantiate the generator with the correct arguments" do
|
48
|
+
@invoked_generator.should_receive(:new).with('/tmp', {}, 'test', 'argument').and_return(@invoked_instance)
|
49
|
+
@generator_class.invoke(:test)
|
50
|
+
@instance = @generator_class.new('/tmp', {}, 'test', 'argument')
|
51
|
+
|
52
|
+
@instance.invocations.first.should == @invoked_instance
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "with a block" do
|
58
|
+
|
59
|
+
before(:each) do
|
60
|
+
@generator_class.stub!(:manifold).and_return(@manifold)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should pass the generator class to the block and return the result of it" do
|
64
|
+
@generator_class.invoke(:test) do |generator|
|
65
|
+
generator.new(destination_root, options, 'blah', 'monkey', some_method)
|
66
|
+
end
|
67
|
+
@instance = @generator_class.new('/tmp', {}, 'test', 'argument')
|
68
|
+
|
69
|
+
@instance.should_receive(:some_method).and_return('da')
|
70
|
+
@invoked_generator.should_receive(:new).with('/tmp', {}, 'blah', 'monkey', 'da').and_return(@invoked_instance)
|
71
|
+
|
72
|
+
@instance.invocations.first.should == @invoked_instance
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should ask the manifold for the generator" do
|
76
|
+
@generator_class.should_receive(:manifold).at_least(:once).and_return(@manifold)
|
77
|
+
@manifold.should_receive(:generator).with(:test).and_return(@invoked_generator)
|
78
|
+
|
79
|
+
@generator_class.invoke(:test) do |generator|
|
80
|
+
generator.new(destination_root, options, 'blah', 'monkey')
|
81
|
+
end
|
82
|
+
|
83
|
+
@instance = @generator_class.new('/tmp', {}, 'test', 'argument')
|
84
|
+
@instance.invocations.first.should == @invoked_instance
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
3
89
|
describe Templater::Generator, '#invocations' do
|
4
90
|
|
5
91
|
before do
|
@@ -38,7 +124,7 @@ describe Templater::Generator, '#invocations' do
|
|
38
124
|
instance.invocations[1].should == @instance2
|
39
125
|
end
|
40
126
|
|
41
|
-
it "should not return
|
127
|
+
it "should not return invocations with an option that does not match." do
|
42
128
|
@generator_class.option :framework, :default => :rails
|
43
129
|
|
44
130
|
@generator_class.invoke(:merb, :framework => :merb)
|
@@ -61,4 +147,27 @@ describe Templater::Generator, '#invocations' do
|
|
61
147
|
instance.framework = nil
|
62
148
|
instance.invocations[0].should == @instance3
|
63
149
|
end
|
150
|
+
|
151
|
+
it "should not return invocations with blocks with an option that does not match." do
|
152
|
+
@generator_class.send(:attr_accessor, :framework)
|
153
|
+
|
154
|
+
instance1, instance2, instance3 = @instance1, @instance2, @instance3
|
155
|
+
|
156
|
+
@generator_class.invoke(:merb, :framework => :merb) { instance1 }
|
157
|
+
@generator_class.invoke(:rails, :framework => :rails) { instance2 }
|
158
|
+
@generator_class.invoke(:both) { instance3 }
|
159
|
+
|
160
|
+
instance = @generator_class.new('/tmp')
|
161
|
+
|
162
|
+
instance.framework = :merb
|
163
|
+
instance.invocations[0].should == @instance1
|
164
|
+
instance.invocations[1].should == @instance3
|
165
|
+
|
166
|
+
instance.framework = :rails
|
167
|
+
instance.invocations[0].should == @instance2
|
168
|
+
instance.invocations[1].should == @instance3
|
169
|
+
|
170
|
+
instance.framework = nil
|
171
|
+
instance.invocations[0].should == @instance3
|
172
|
+
end
|
64
173
|
end
|
@@ -1,93 +1,5 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
2
|
|
3
|
-
describe Templater::Generator, '.invoke' do
|
4
|
-
|
5
|
-
before do
|
6
|
-
@generator_class = Class.new(Templater::Generator)
|
7
|
-
@generator_class.first_argument :test1
|
8
|
-
@generator_class.second_argument :test2
|
9
|
-
|
10
|
-
@invoked_generator = mock('an invoked generator')
|
11
|
-
@invoked_instance = mock('an instance of the invoked generator')
|
12
|
-
@invoked_generator.stub!(:new).and_return(@invoked_instance)
|
13
|
-
|
14
|
-
@manifold = mock('a manifold')
|
15
|
-
@manifold.stub!(:generator).with(:test).and_return(@invoked_generator)
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should add nothing if there is no manifold" do
|
19
|
-
@generator_class.invoke(:test)
|
20
|
-
@instance = @generator_class.new('/tmp', {}, 'test', 'argument')
|
21
|
-
|
22
|
-
@instance.invocations.should be_empty
|
23
|
-
end
|
24
|
-
|
25
|
-
describe "with no block" do
|
26
|
-
|
27
|
-
before(:each) do
|
28
|
-
@generator_class.stub!(:manifold).and_return(@manifold)
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should return the instantiaded template" do
|
32
|
-
@generator_class.invoke(:test)
|
33
|
-
@instance = @generator_class.new('/tmp', {}, 'test', 'argument')
|
34
|
-
|
35
|
-
@instance.invocations.first.should == @invoked_instance
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should ask the manifold for the generator" do
|
39
|
-
@generator_class.should_receive(:manifold).at_least(:once).and_return(@manifold)
|
40
|
-
@manifold.should_receive(:generator).with(:test).and_return(@invoked_generator)
|
41
|
-
@generator_class.invoke(:test)
|
42
|
-
@instance = @generator_class.new('/tmp', {}, 'test', 'argument')
|
43
|
-
|
44
|
-
@instance.invocations.first.should == @invoked_instance
|
45
|
-
end
|
46
|
-
|
47
|
-
it "should instantiate the generator with the correct arguments" do
|
48
|
-
@invoked_generator.should_receive(:new).with('/tmp', {}, 'test', 'argument').and_return(@invoked_instance)
|
49
|
-
@generator_class.invoke(:test)
|
50
|
-
@instance = @generator_class.new('/tmp', {}, 'test', 'argument')
|
51
|
-
|
52
|
-
@instance.invocations.first.should == @invoked_instance
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
56
|
-
|
57
|
-
describe "with a block" do
|
58
|
-
|
59
|
-
before(:each) do
|
60
|
-
@generator_class.stub!(:manifold).and_return(@manifold)
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should pass the generator class to the block and return the result of it" do
|
64
|
-
@generator_class.invoke(:test) do |generator|
|
65
|
-
generator.new(destination_root, options, 'blah', 'monkey', some_method)
|
66
|
-
end
|
67
|
-
@instance = @generator_class.new('/tmp', {}, 'test', 'argument')
|
68
|
-
|
69
|
-
@instance.should_receive(:some_method).and_return('da')
|
70
|
-
@invoked_generator.should_receive(:new).with('/tmp', {}, 'blah', 'monkey', 'da').and_return(@invoked_instance)
|
71
|
-
|
72
|
-
@instance.invocations.first.should == @invoked_instance
|
73
|
-
end
|
74
|
-
|
75
|
-
it "should ask the manifold for the generator" do
|
76
|
-
@generator_class.should_receive(:manifold).at_least(:once).and_return(@manifold)
|
77
|
-
@manifold.should_receive(:generator).with(:test).and_return(@invoked_generator)
|
78
|
-
|
79
|
-
@generator_class.invoke(:test) do |generator|
|
80
|
-
generator.new(destination_root, options, 'blah', 'monkey')
|
81
|
-
end
|
82
|
-
|
83
|
-
@instance = @generator_class.new('/tmp', {}, 'test', 'argument')
|
84
|
-
@instance.invocations.first.should == @invoked_instance
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
|
90
|
-
|
91
3
|
describe Templater::Generator, '#invoke!' do
|
92
4
|
|
93
5
|
before do
|
File without changes
|
@@ -6,3 +6,13 @@ describe Templater::Generator, '.source_root' do
|
|
6
6
|
lambda { @generator_class.source_root }.should raise_error(Templater::SourceNotSpecifiedError)
|
7
7
|
end
|
8
8
|
end
|
9
|
+
|
10
|
+
describe Templater::Generator, '#source_root' do
|
11
|
+
it "try to retrieve the source root from the class" do
|
12
|
+
@generator_class = Class.new(Templater::Generator)
|
13
|
+
@generator_class.should_receive(:source_root).and_return('/tmp/source')
|
14
|
+
|
15
|
+
instance = @generator_class.new('/tmp')
|
16
|
+
instance.source_root.should == '/tmp/source'
|
17
|
+
end
|
18
|
+
end
|
@@ -1,5 +1,129 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
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::Actions::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::Actions::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::Actions::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::Actions::Template)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should add a template with a complex block" do
|
57
|
+
@generator_class.template(:my_template) do
|
58
|
+
source 'blah', 'blah.rbt'
|
59
|
+
destination 'gurr', "gurr#{something}.rb"
|
60
|
+
end
|
61
|
+
@instance = @generator_class.new('/tmp/destination')
|
62
|
+
|
63
|
+
@instance.stub!(:something).and_return('anotherthing')
|
64
|
+
@instance.stub!(:source_root).and_return('/tmp/source')
|
65
|
+
|
66
|
+
@instance.template(:my_template).source.should == '/tmp/source/blah/blah.rbt'
|
67
|
+
@instance.template(:my_template).destination.should == "/tmp/destination/gurr/gurranotherthing.rb"
|
68
|
+
@instance.template(:my_template).should be_an_instance_of(Templater::Actions::Template)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should add a template and convert an with an instruction encoded in the destination, but not one encoded in the source" do
|
72
|
+
@generator_class.template(:my_template, 'template/%some_method%.rbt', 'template/%another_method%.rb')
|
73
|
+
@instance = @generator_class.new('/tmp/destination')
|
74
|
+
|
75
|
+
@instance.stub!(:source_root).and_return('/tmp/source')
|
76
|
+
@instance.should_not_receive(:some_method)
|
77
|
+
@instance.should_receive(:another_method).at_least(:once).and_return('beast')
|
78
|
+
|
79
|
+
@instance.template(:my_template).source.should == '/tmp/source/template/%some_method%.rbt'
|
80
|
+
@instance.template(:my_template).destination.should == "/tmp/destination/template/beast.rb"
|
81
|
+
@instance.template(:my_template).should be_an_instance_of(Templater::Actions::Template)
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should add a template and leave an encoded instruction be if it doesn't exist as a method" do
|
85
|
+
@generator_class.template(:my_template, 'template/blah.rbt', 'template/%some_method%.rb')
|
86
|
+
@instance = @generator_class.new('/tmp/destination')
|
87
|
+
|
88
|
+
@instance.stub!(:source_root).and_return('/tmp/source')
|
89
|
+
|
90
|
+
@instance.template(:my_template).destination.should == "/tmp/destination/template/%some_method%.rb"
|
91
|
+
@instance.template(:my_template).should be_an_instance_of(Templater::Actions::Template)
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
describe Templater::Generator, '.template_list' do
|
97
|
+
|
98
|
+
it "should add a series of templates given a list as heredoc" do
|
99
|
+
@generator_class = Class.new(Templater::Generator)
|
100
|
+
|
101
|
+
@generator_class.should_receive(:template).with(:app_model_rb, 'app/model.rb')
|
102
|
+
@generator_class.should_receive(:template).with(:spec_model_rb, 'spec/model.rb')
|
103
|
+
@generator_class.should_receive(:template).with(:donkey_poo_css, 'donkey/poo.css')
|
104
|
+
@generator_class.should_receive(:template).with(:john_smith_file_rb, 'john/smith/file.rb')
|
105
|
+
|
106
|
+
@generator_class.template_list <<-LIST
|
107
|
+
app/model.rb
|
108
|
+
spec/model.rb
|
109
|
+
donkey/poo.css
|
110
|
+
john/smith/file.rb
|
111
|
+
LIST
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should add a series of templates given a list as array" do
|
115
|
+
@generator_class = Class.new(Templater::Generator)
|
116
|
+
|
117
|
+
@generator_class.should_receive(:template).with(:app_model_rb, 'app/model.rb')
|
118
|
+
@generator_class.should_receive(:template).with(:spec_model_rb, 'spec/model.rb')
|
119
|
+
@generator_class.should_receive(:template).with(:donkey_poo_css, 'donkey/poo.css')
|
120
|
+
@generator_class.should_receive(:template).with(:john_smith_file_rb, 'john/smith/file.rb')
|
121
|
+
|
122
|
+
@generator_class.template_list(%w(app/model.rb spec/model.rb donkey/poo.css john/smith/file.rb))
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
126
|
+
|
3
127
|
describe Templater::Generator, '#templates' do
|
4
128
|
|
5
129
|
before do
|
@@ -45,3 +169,52 @@ describe Templater::Generator, '#templates' do
|
|
45
169
|
instance.templates[0].name.should == :none
|
46
170
|
end
|
47
171
|
end
|
172
|
+
|
173
|
+
|
174
|
+
describe Templater::Generator, '#template' do
|
175
|
+
|
176
|
+
before do
|
177
|
+
@generator_class = Class.new(Templater::Generator)
|
178
|
+
@generator_class.class_eval do
|
179
|
+
def source_root
|
180
|
+
'/tmp/source'
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
it "should find a template by name" do
|
186
|
+
@generator_class.template(:blah1, 'blah.rb')
|
187
|
+
@generator_class.template(:blah2, 'blah2.rb')
|
188
|
+
|
189
|
+
instance = @generator_class.new('/tmp')
|
190
|
+
|
191
|
+
instance.template(:blah1).name.should == :blah1
|
192
|
+
instance.template(:blah1).source.should == '/tmp/source/blah.rbt'
|
193
|
+
instance.template(:blah1).destination.should == '/tmp/blah.rb'
|
194
|
+
end
|
195
|
+
|
196
|
+
it "should not return a template with an option that does not match." do
|
197
|
+
@generator_class.send(:attr_accessor, :framework)
|
198
|
+
|
199
|
+
@generator_class.template(:merb, 'blah.rb', :framework => :merb)
|
200
|
+
@generator_class.template(:rails, 'blah2.rb', :framework => :rails)
|
201
|
+
@generator_class.template(:none, 'blah2.rb')
|
202
|
+
|
203
|
+
instance = @generator_class.new('/tmp')
|
204
|
+
|
205
|
+
instance.framework = :rails
|
206
|
+
instance.template(:rails).name.should == :rails
|
207
|
+
instance.template(:merb).should be_nil
|
208
|
+
instance.template(:none).name.should == :none
|
209
|
+
|
210
|
+
instance.framework = :merb
|
211
|
+
instance.template(:rails).should be_nil
|
212
|
+
instance.template(:merb).name.should == :merb
|
213
|
+
instance.template(:none).name.should == :none
|
214
|
+
|
215
|
+
instance.framework = nil
|
216
|
+
instance.template(:rails).should be_nil
|
217
|
+
instance.template(:merb).should be_nil
|
218
|
+
instance.template(:none).name.should == :none
|
219
|
+
end
|
220
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
require 'templater/spec/helpers'
|
4
|
+
|
5
|
+
module Gens
|
6
|
+
|
7
|
+
extend Templater::Manifold
|
8
|
+
|
9
|
+
class Gen < Templater::Generator
|
10
|
+
invoke :gen2
|
11
|
+
invoke :gen3 do |g|
|
12
|
+
g.new(destination_root, options, 'blah', 'monkey')
|
13
|
+
end
|
14
|
+
template 'blah.template', 'blah.txt'
|
15
|
+
template 'test.template', 'test.txt'
|
16
|
+
file 'arg.file', 'arg.txt'
|
17
|
+
end
|
18
|
+
add :gen, Gen
|
19
|
+
|
20
|
+
class Gen2 < Templater::Generator
|
21
|
+
end
|
22
|
+
add :gen2, Gen2
|
23
|
+
|
24
|
+
class Gen3 < Templater::Generator
|
25
|
+
first_argument :name
|
26
|
+
second_argument :country
|
27
|
+
end
|
28
|
+
add :gen3, Gen3
|
29
|
+
|
30
|
+
class Gen4 < Templater::Generator
|
31
|
+
end
|
32
|
+
add :gen4, Gen4
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
describe Templater::Spec::Helpers, "#invoke" do
|
37
|
+
|
38
|
+
include Templater::Spec::Helpers
|
39
|
+
|
40
|
+
before do
|
41
|
+
@instance = Gens::Gen.new('/tmp', {})
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should match when the expected generator is listed as an invocation" do
|
45
|
+
@instance.should invoke(Gens::Gen2)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should not match when the expected generator is not listed as an invocation" do
|
49
|
+
@instance.should_not invoke(Gens::Gen4)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should match when the expected generator is listed as an invocation with a block" do
|
53
|
+
@instance.should invoke(Gens::Gen3)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should match when the expected generator, and its arguments are listed as an invocation" do
|
57
|
+
@instance.should invoke(Gens::Gen3).with('blah', 'monkey')
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should match when the expected generator is listed as an invocation with different arguments" do
|
61
|
+
@instance.should_not invoke(Gens::Gen3).with('ape')
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe Templater::Spec::Helpers, "#create" do
|
66
|
+
|
67
|
+
include Templater::Spec::Helpers
|
68
|
+
|
69
|
+
before do
|
70
|
+
@instance = Gens::Gen.new('/tmp', {})
|
71
|
+
@instance.stub!(:source_root).and_return('/source')
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should match when the generator has a template with the expected destination" do
|
75
|
+
@instance.should create('/tmp/blah.txt')
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should match when the generator has a file with the expected destination" do
|
79
|
+
@instance.should create('/tmp/arg.txt')
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should match when the generator has neither a file nor a template with the expected destination" do
|
83
|
+
@instance.should_not create('/tmp/blurns.txt')
|
84
|
+
end
|
85
|
+
end
|
data/spec/template_spec.rb
CHANGED
@@ -128,4 +128,10 @@ describe Templater::Actions::Template, '#revoke!' do
|
|
128
128
|
File.exists?(result_path('test.rbs')).should be_false
|
129
129
|
end
|
130
130
|
|
131
|
+
it "should do nothing when the destination file doesn't exist" do
|
132
|
+
template = Templater::Actions::Template.new(@context, :monkey, template_path('simple_erb.rbt'), result_path('test.rbs'))
|
133
|
+
|
134
|
+
lambda { template.revoke! }.should_not raise_error
|
135
|
+
end
|
136
|
+
|
131
137
|
end
|