templater 0.4.4 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -44,6 +44,6 @@ module Templater
44
44
  class MalformattedArgumentError < ArgumentError #:nodoc:
45
45
  end
46
46
 
47
- VERSION = '0.4.4'
47
+ VERSION = '0.4.5'
48
48
 
49
49
  end
@@ -75,9 +75,11 @@ module Templater
75
75
  step_through_templates
76
76
 
77
77
  # Run hooks
78
- @generator.after_run
79
- @generator.after_generation unless @options[:delete]
80
- @generator.after_deletion if @options[:delete]
78
+ unless @options[:pretend]
79
+ @generator.after_run
80
+ @generator.after_generation unless @options[:delete]
81
+ @generator.after_deletion if @options[:delete]
82
+ end
81
83
  end
82
84
 
83
85
  def step_through_templates
@@ -163,9 +165,9 @@ module Templater
163
165
  def output_diff_line(diff)
164
166
  case diff.action
165
167
  when '-'
166
- say "<%= color('- #{diff.element.chomp}', :red) %>"
168
+ say "<%= color( %(- #{diff.element.chomp}), :red) %>"
167
169
  when '+'
168
- say "<%= color('+ #{diff.element.chomp}', :green) %>"
170
+ say "<%= color( %(+ #{diff.element.chomp}), :green) %>"
169
171
  else
170
172
  say "#{diff.action} #{diff.element.chomp}"
171
173
  end
@@ -15,15 +15,15 @@ describe Templater::Actions::EmptyDirectory do
15
15
  end
16
16
 
17
17
  it 'sets destination' do
18
- Templater::Actions::EmptyDirectory.new(@generator, :monkey, '/path/to/destination').
19
- destination.should == '/path/to/destination'
18
+ Templater::Actions::EmptyDirectory.new(@generator, :monkey, tmp('/path/to/destination')).
19
+ destination.should == tmp('/path/to/destination')
20
20
  end
21
21
  end
22
22
 
23
23
  describe '#relative_destination' do
24
24
  it "returns the destination relative to the generator's destination root" do
25
- @generator.stub!(:destination_root).and_return('/path/to')
26
- file = Templater::Actions::EmptyDirectory.new(@generator, :monkey, '/path/to/destination/with/some/more/subdirs')
25
+ @generator.stub!(:destination_root).and_return(tmp('/path/to'))
26
+ file = Templater::Actions::EmptyDirectory.new(@generator, :monkey, tmp('/path/to/destination/with/some/more/subdirs'))
27
27
  file.relative_destination.should == 'destination/with/some/more/subdirs'
28
28
  end
29
29
  end
@@ -4,23 +4,23 @@ describe Templater::Actions::File do
4
4
 
5
5
  before do
6
6
  @generator = mock('a generator')
7
- @generator.stub!(:source_root).and_return('/tmp/source')
8
- @generator.stub!(:destination_root).and_return('/tmp/destination')
7
+ @generator.stub!(:source_root).and_return(tmp('source'))
8
+ @generator.stub!(:destination_root).and_return(tmp('destination'))
9
9
  end
10
10
 
11
11
  describe '.new' do
12
12
  it "should set name, source and destination" do
13
- file = Templater::Actions::File.new(@generator, :monkey, '/path/to/source', '/path/to/destination')
13
+ file = Templater::Actions::File.new(@generator, :monkey, tmp('/path/to/source'), tmp('/path/to/destination'))
14
14
  file.name.should == :monkey
15
- file.source.should == '/path/to/source'
16
- file.destination.should == '/path/to/destination'
15
+ file.source.should == tmp('/path/to/source')
16
+ file.destination.should == tmp('/path/to/destination')
17
17
  end
18
18
  end
19
19
 
20
20
  describe '#relative_destination' do
21
21
  it "should get the destination relative to the generator's destination root" do
22
- @generator.stub!(:destination_root).and_return('/path/to')
23
- file = Templater::Actions::File.new(@generator, :monkey, '/path/to/source', '/path/to/destination/with/some/more/subdirs')
22
+ @generator.stub!(:destination_root).and_return(tmp('/path/to'))
23
+ file = Templater::Actions::File.new(@generator, :monkey, tmp('/path/to/source'), tmp('/path/to/destination/with/some/more/subdirs'))
24
24
  file.relative_destination.should == 'destination/with/some/more/subdirs'
25
25
  end
26
26
  end
@@ -4,23 +4,23 @@ describe Templater::Actions::Template do
4
4
 
5
5
  before do
6
6
  @generator = mock('a generator')
7
- @generator.stub!(:source_root).and_return('/tmp/source')
8
- @generator.stub!(:destination_root).and_return('/tmp/destination')
7
+ @generator.stub!(:source_root).and_return(tmp('source'))
8
+ @generator.stub!(:destination_root).and_return(tmp('destination'))
9
9
  end
10
10
 
11
11
  describe '.new' do
12
12
  it "should set name, source and destination" do
13
- template = Templater::Actions::Template.new(@generator, :monkey, '/path/to/source', '/path/to/destination')
13
+ template = Templater::Actions::Template.new(@generator, :monkey, tmp('/path/to/source'), tmp('/path/to/destination'))
14
14
  template.name.should == :monkey
15
- template.source.should == '/path/to/source'
16
- template.destination.should == '/path/to/destination'
15
+ template.source.should == tmp('/path/to/source')
16
+ template.destination.should == tmp('/path/to/destination')
17
17
  end
18
18
  end
19
19
 
20
20
  describe '#relative_destination' do
21
21
  it "should get the destination relative to the generator's destination root" do
22
- @generator.stub!(:destination_root).and_return('/path/to')
23
- template = Templater::Actions::Template.new(@generator, :monkey, '/path/to/source', '/path/to/destination/with/some/more/subdirs')
22
+ @generator.stub!(:destination_root).and_return(tmp('/path/to'))
23
+ template = Templater::Actions::Template.new(@generator, :monkey, tmp('/path/to/source'), tmp('/path/to/destination/with/some/more/subdirs'))
24
24
  template.relative_destination.should == 'destination/with/some/more/subdirs'
25
25
  end
26
26
  end
@@ -7,21 +7,21 @@ describe Templater::Generator, ".empty_directory" do
7
7
 
8
8
  it "should add an empty_directory" do
9
9
  @generator_class.empty_directory(:my_empty_directory, 'path/to/destination.rb')
10
- @instance = @generator_class.new('/tmp/destination')
10
+ @instance = @generator_class.new(tmp('destination'))
11
11
 
12
- @instance.stub!(:source_root).and_return('/tmp/source')
12
+ @instance.stub!(:source_root).and_return(tmp('source'))
13
13
 
14
- @instance.empty_directory(:my_empty_directory).destination.should == '/tmp/destination/path/to/destination.rb'
14
+ @instance.empty_directory(:my_empty_directory).destination.should == tmp('/destination/path/to/destination.rb')
15
15
  @instance.empty_directory(:my_empty_directory).should be_an_instance_of(Templater::Actions::EmptyDirectory)
16
16
  end
17
17
 
18
18
  it "should add a empty_directory and convert an instruction encoded in the destination" do
19
19
  @generator_class.empty_directory(:my_empty_directory, 'template/%another_method%.rb')
20
- @instance = @generator_class.new('/tmp/destination')
20
+ @instance = @generator_class.new(tmp('destination'))
21
21
 
22
22
  @instance.should_receive(:another_method).at_least(:once).and_return('beast')
23
23
 
24
- @instance.empty_directory(:my_empty_directory).destination.should == "/tmp/destination/template/beast.rb"
24
+ @instance.empty_directory(:my_empty_directory).destination.should == tmp("/destination/template/beast.rb")
25
25
  @instance.empty_directory(:my_empty_directory).should be_an_instance_of(Templater::Actions::EmptyDirectory)
26
26
  end
27
27
 
@@ -29,9 +29,9 @@ describe Templater::Generator, ".empty_directory" do
29
29
  @generator_class.empty_directory(:my_empty_directory) do |action|
30
30
  action.destination = "gurr#{Process.pid.to_s}.rb"
31
31
  end
32
- @instance = @generator_class.new('/tmp/destination')
32
+ @instance = @generator_class.new(tmp('destination'))
33
33
 
34
- @instance.empty_directory(:my_empty_directory).destination.should == "/tmp/destination/gurr#{Process.pid.to_s}.rb"
34
+ @instance.empty_directory(:my_empty_directory).destination.should == tmp("/destination/gurr#{Process.pid.to_s}.rb")
35
35
  @instance.empty_directory(:my_empty_directory).should be_an_instance_of(Templater::Actions::EmptyDirectory)
36
36
  end
37
37
 
@@ -39,25 +39,25 @@ describe Templater::Generator, ".empty_directory" do
39
39
  @generator_class.empty_directory(:my_empty_directory) do |action|
40
40
  action.destination = 'gurr' / "gurr#{something}.rb"
41
41
  end
42
- @instance = @generator_class.new('/tmp/destination')
42
+ @instance = @generator_class.new(tmp('destination'))
43
43
 
44
44
  @instance.stub!(:something).and_return('anotherthing')
45
45
 
46
- @instance.empty_directory(:my_empty_directory).destination.should == "/tmp/destination/gurr/gurranotherthing.rb"
46
+ @instance.empty_directory(:my_empty_directory).destination.should == tmp("/destination/gurr/gurranotherthing.rb")
47
47
  @instance.empty_directory(:my_empty_directory).should be_an_instance_of(Templater::Actions::EmptyDirectory)
48
48
  end
49
49
 
50
50
  it "should add a empty_directory and leave an encoded instruction be if it doesn't exist as a method" do
51
51
  @generator_class.empty_directory(:my_empty_directory, 'template/%some_method%.rb')
52
- @instance = @generator_class.new('/tmp/destination')
52
+ @instance = @generator_class.new(tmp('destination'))
53
53
 
54
- @instance.empty_directory(:my_empty_directory).destination.should == "/tmp/destination/template/%some_method%.rb"
54
+ @instance.empty_directory(:my_empty_directory).destination.should == tmp("/destination/template/%some_method%.rb")
55
55
  @instance.empty_directory(:my_empty_directory).should be_an_instance_of(Templater::Actions::EmptyDirectory)
56
56
  end
57
57
 
58
58
  it "should pass options on to the empty_directory" do
59
59
  @generator_class.empty_directory(:my_empty_directory, 'path/to/destination.rb', :before => :monkey, :after => :donkey)
60
- @instance = @generator_class.new('/tmp/destination')
60
+ @instance = @generator_class.new(tmp('destination'))
61
61
 
62
62
  @instance.empty_directory(:my_empty_directory).options[:before].should == :monkey
63
63
  @instance.empty_directory(:my_empty_directory).options[:after].should == :donkey
@@ -74,7 +74,7 @@ describe Templater::Generator, '#empty_directories' do
74
74
  @generator_class.empty_directory(:blah1, 'blah.rb')
75
75
  @generator_class.empty_directory(:blah2, 'blah2.rb')
76
76
 
77
- instance = @generator_class.new('/tmp')
77
+ instance = @generator_class.new(tmp('tmp'))
78
78
 
79
79
  instance.empty_directories[0].name.should == :blah1
80
80
  instance.empty_directories[1].name.should == :blah2
@@ -87,7 +87,7 @@ describe Templater::Generator, '#empty_directories' do
87
87
  @generator_class.empty_directory(:rails, 'blah2.rb', :framework => :rails)
88
88
  @generator_class.empty_directory(:none, 'blah2.rb')
89
89
 
90
- instance = @generator_class.new('/tmp')
90
+ instance = @generator_class.new(tmp('tmp'))
91
91
 
92
92
  instance.empty_directories[0].name.should == :rails
93
93
  instance.empty_directories[1].name.should == :none
@@ -115,10 +115,10 @@ describe Templater::Generator, '#empty_directory' do
115
115
  @generator_class.empty_directory(:blah1, 'blah.rb')
116
116
  @generator_class.empty_directory(:blah2, 'blah2.rb')
117
117
 
118
- instance = @generator_class.new('/tmp')
118
+ instance = @generator_class.new(tmp('tmp'))
119
119
 
120
120
  instance.empty_directory(:blah1).name.should == :blah1
121
- instance.empty_directory(:blah1).destination.should == '/tmp/blah.rb'
121
+ instance.empty_directory(:blah1).destination.should == tmp('/tmp/blah.rb')
122
122
  end
123
123
 
124
124
  it "should not return a empty_directory with an option that does not match." do
@@ -128,7 +128,7 @@ describe Templater::Generator, '#empty_directory' do
128
128
  @generator_class.empty_directory(:rails, 'blah2.rb', :framework => :rails)
129
129
  @generator_class.empty_directory(:none, 'blah2.rb')
130
130
 
131
- instance = @generator_class.new('/tmp')
131
+ instance = @generator_class.new(tmp('tmp'))
132
132
 
133
133
  instance.framework = :rails
134
134
  instance.empty_directory(:rails).name.should == :rails
@@ -4,24 +4,24 @@ describe Templater::Generator, '.file' do
4
4
 
5
5
  before do
6
6
  @generator_class = Class.new(Templater::Generator)
7
- @generator_class.stub!(:source_root).and_return('/tmp/source')
7
+ @generator_class.stub!(:source_root).and_return(tmp('source'))
8
8
  end
9
9
 
10
10
  it "should add a file with source and destination" do
11
11
  @generator_class.file(:my_template, 'path/to/source.rbt', 'path/to/destination.rb')
12
- @instance = @generator_class.new('/tmp/destination')
12
+ @instance = @generator_class.new(tmp('destination'))
13
13
 
14
- @instance.file(:my_template).source.should == '/tmp/source/path/to/source.rbt'
15
- @instance.file(:my_template).destination.should == '/tmp/destination/path/to/destination.rb'
14
+ @instance.file(:my_template).source.should == tmp('/source/path/to/source.rbt')
15
+ @instance.file(:my_template).destination.should == tmp('/destination/path/to/destination.rb')
16
16
  @instance.file(:my_template).should be_an_instance_of(Templater::Actions::File)
17
17
  end
18
18
 
19
19
  it "should add a file with source and infer destination " do
20
20
  @generator_class.file(:my_template, 'path/to/file.rb')
21
- @instance = @generator_class.new('/tmp/destination')
21
+ @instance = @generator_class.new(tmp('destination'))
22
22
 
23
- @instance.file(:my_template).source.should == '/tmp/source/path/to/file.rb'
24
- @instance.file(:my_template).destination.should == '/tmp/destination/path/to/file.rb'
23
+ @instance.file(:my_template).source.should == tmp('/source/path/to/file.rb')
24
+ @instance.file(:my_template).destination.should == tmp('/destination/path/to/file.rb')
25
25
  @instance.file(:my_template).should be_an_instance_of(Templater::Actions::File)
26
26
  end
27
27
 
@@ -30,10 +30,10 @@ describe Templater::Generator, '.file' do
30
30
  file.source = 'blah.rbt'
31
31
  file.destination = "gurr#{Process.pid.to_s}.rb"
32
32
  end
33
- @instance = @generator_class.new('/tmp/destination')
33
+ @instance = @generator_class.new(tmp('destination'))
34
34
 
35
- @instance.file(:my_file).source.should == '/tmp/source/blah.rbt'
36
- @instance.file(:my_file).destination.should == "/tmp/destination/gurr#{Process.pid.to_s}.rb"
35
+ @instance.file(:my_file).source.should == tmp('/source/blah.rbt')
36
+ @instance.file(:my_file).destination.should == tmp("/destination/gurr#{Process.pid.to_s}.rb")
37
37
  @instance.file(:my_file).should be_an_instance_of(Templater::Actions::File)
38
38
  end
39
39
 
@@ -42,32 +42,32 @@ describe Templater::Generator, '.file' do
42
42
  file.source = 'blah' / 'blah.rbt'
43
43
  file.destination = 'gurr' / "gurr#{something}.rb"
44
44
  end
45
- @instance = @generator_class.new('/tmp/destination')
45
+ @instance = @generator_class.new(tmp('destination'))
46
46
 
47
47
  @instance.stub!(:something).and_return('anotherthing')
48
48
 
49
- @instance.file(:my_file).source.should == '/tmp/source/blah/blah.rbt'
50
- @instance.file(:my_file).destination.should == "/tmp/destination/gurr/gurranotherthing.rb"
49
+ @instance.file(:my_file).source.should == tmp('/source/blah/blah.rbt')
50
+ @instance.file(:my_file).destination.should == tmp("/destination/gurr/gurranotherthing.rb")
51
51
  @instance.file(:my_file).should be_an_instance_of(Templater::Actions::File)
52
52
  end
53
53
 
54
54
  it "should add a file and convert an instruction encoded in the destination, but not one encoded in the source" do
55
55
  @generator_class.file(:my_template, 'template/%some_method%.rbt', 'template/%another_method%.rb')
56
- @instance = @generator_class.new('/tmp/destination')
56
+ @instance = @generator_class.new(tmp('destination'))
57
57
 
58
58
  @instance.should_not_receive(:some_method)
59
59
  @instance.should_receive(:another_method).at_least(:once).and_return('beast')
60
60
 
61
- @instance.file(:my_template).source.should == '/tmp/source/template/%some_method%.rbt'
62
- @instance.file(:my_template).destination.should == "/tmp/destination/template/beast.rb"
61
+ @instance.file(:my_template).source.should == tmp('/source/template/%some_method%.rbt')
62
+ @instance.file(:my_template).destination.should == tmp("/destination/template/beast.rb")
63
63
  @instance.file(:my_template).should be_an_instance_of(Templater::Actions::File)
64
64
  end
65
65
 
66
66
  it "should add a file and leave an encoded instruction be if it doesn't exist as a method" do
67
67
  @generator_class.file(:my_template, 'template/blah.rbt', 'template/%some_method%.rb')
68
- @instance = @generator_class.new('/tmp/destination')
68
+ @instance = @generator_class.new(tmp('destination'))
69
69
 
70
- @instance.file(:my_template).destination.should == "/tmp/destination/template/%some_method%.rb"
70
+ @instance.file(:my_template).destination.should == tmp("/destination/template/%some_method%.rb")
71
71
  @instance.file(:my_template).should be_an_instance_of(Templater::Actions::File)
72
72
  end
73
73
 
@@ -158,18 +158,18 @@ describe Templater::Generator, '#file' do
158
158
 
159
159
  before do
160
160
  @generator_class = Class.new(Templater::Generator)
161
- @generator_class.stub!(:source_root).and_return('/tmp/source')
161
+ @generator_class.stub!(:source_root).and_return(tmp('source'))
162
162
  end
163
163
 
164
164
  it "should find a file by name" do
165
165
  @generator_class.file(:blah1, 'blah.rb')
166
166
  @generator_class.file(:blah2, 'blah2.rb')
167
167
 
168
- instance = @generator_class.new('/tmp')
168
+ instance = @generator_class.new(tmp('tmp'))
169
169
 
170
170
  instance.file(:blah1).name.should == :blah1
171
- instance.file(:blah1).source.should == '/tmp/source/blah.rb'
172
- instance.file(:blah1).destination.should == '/tmp/blah.rb'
171
+ instance.file(:blah1).source.should == tmp('/source/blah.rb')
172
+ instance.file(:blah1).destination.should == tmp('/tmp/blah.rb')
173
173
  end
174
174
 
175
175
  it "should not return a file with an option that does not match." do
@@ -10,62 +10,62 @@ describe Templater::Generator, '.glob!' do
10
10
  it "should add templates and files in the source_root based on if their extensions are in the template_extensions array" do
11
11
  @generator_class.glob!()
12
12
 
13
- @instance = @generator_class.new('/tmp/destination')
13
+ @instance = @generator_class.new(tmp('destination'))
14
14
 
15
15
  @instance.template(:arg_js).source.should == template_path('glob/arg.js')
16
- @instance.template(:arg_js).destination.should == "/tmp/destination/arg.js"
16
+ @instance.template(:arg_js).destination.should == tmp("/destination/arg.js")
17
17
 
18
18
  @instance.template(:test_rb).source.should == template_path('glob/test.rb')
19
- @instance.template(:test_rb).destination.should == "/tmp/destination/test.rb"
19
+ @instance.template(:test_rb).destination.should == tmp("/destination/test.rb")
20
20
 
21
21
  @instance.file(:subfolder_jessica_alba_jpg).source.should == template_path('glob/subfolder/jessica_alba.jpg')
22
- @instance.file(:subfolder_jessica_alba_jpg).destination.should == '/tmp/destination/subfolder/jessica_alba.jpg'
22
+ @instance.file(:subfolder_jessica_alba_jpg).destination.should == tmp('/destination/subfolder/jessica_alba.jpg')
23
23
  end
24
24
 
25
25
  it "should add templates and files with a different template_extensions array" do
26
26
  @generator_class.glob!(nil, %w(jpg))
27
27
 
28
- @instance = @generator_class.new('/tmp/destination')
28
+ @instance = @generator_class.new(tmp('destination'))
29
29
 
30
30
  @instance.file(:arg_js).source.should == template_path('glob/arg.js')
31
- @instance.file(:arg_js).destination.should == "/tmp/destination/arg.js"
31
+ @instance.file(:arg_js).destination.should == tmp("/destination/arg.js")
32
32
 
33
33
  @instance.file(:test_rb).source.should == template_path('glob/test.rb')
34
- @instance.file(:test_rb).destination.should == "/tmp/destination/test.rb"
34
+ @instance.file(:test_rb).destination.should == tmp("/destination/test.rb")
35
35
 
36
36
  @instance.template(:subfolder_jessica_alba_jpg).source.should == template_path('glob/subfolder/jessica_alba.jpg')
37
- @instance.template(:subfolder_jessica_alba_jpg).destination.should == '/tmp/destination/subfolder/jessica_alba.jpg'
37
+ @instance.template(:subfolder_jessica_alba_jpg).destination.should == tmp('/destination/subfolder/jessica_alba.jpg')
38
38
  end
39
39
 
40
40
  it "should add README and other stuff without an extension as templates if in the template_extensions array" do
41
41
  @generator_class.glob!(nil, %w(README))
42
42
 
43
- @instance = @generator_class.new('/tmp/destination')
43
+ @instance = @generator_class.new(tmp('destination'))
44
44
 
45
45
  @instance.template(:readme).source.should == template_path('glob/README')
46
- @instance.template(:readme).destination.should == "/tmp/destination/README"
46
+ @instance.template(:readme).destination.should == tmp("/destination/README")
47
47
  end
48
48
 
49
49
  it "should glob in a subdirectory" do
50
50
  @generator_class.stub!(:source_root).and_return(template_path(""))
51
51
  @generator_class.glob!('glob', %w(jpg))
52
52
 
53
- @instance = @generator_class.new('/tmp/destination')
53
+ @instance = @generator_class.new(tmp('destination'))
54
54
 
55
55
  @instance.file(:glob_arg_js).source.should == template_path('glob/arg.js')
56
- @instance.file(:glob_arg_js).destination.should == "/tmp/destination/glob/arg.js"
56
+ @instance.file(:glob_arg_js).destination.should == tmp("/destination/glob/arg.js")
57
57
 
58
58
  @instance.file(:glob_test_rb).source.should == template_path('glob/test.rb')
59
- @instance.file(:glob_test_rb).destination.should == "/tmp/destination/glob/test.rb"
59
+ @instance.file(:glob_test_rb).destination.should == tmp("/destination/glob/test.rb")
60
60
 
61
61
  @instance.template(:glob_subfolder_jessica_alba_jpg).source.should == template_path('glob/subfolder/jessica_alba.jpg')
62
- @instance.template(:glob_subfolder_jessica_alba_jpg).destination.should == '/tmp/destination/glob/subfolder/jessica_alba.jpg'
62
+ @instance.template(:glob_subfolder_jessica_alba_jpg).destination.should == tmp('/destination/glob/subfolder/jessica_alba.jpg')
63
63
  end
64
64
 
65
65
  it "should add only the given templates and files" do
66
66
  @generator_class.glob!()
67
67
 
68
- @instance = @generator_class.new('/tmp/destination')
68
+ @instance = @generator_class.new(tmp('destination'))
69
69
 
70
70
  @instance.templates.map { |t| t.name.to_s }.sort.should == [
71
71
  :arg_js,
@@ -83,12 +83,12 @@ describe Templater::Generator, '.glob!' do
83
83
  it "should ignore ending '.%..%' and look at the extension preceding it" do
84
84
  @generator_class.glob!
85
85
 
86
- @instance = @generator_class.new('/tmp/destination')
86
+ @instance = @generator_class.new(tmp('destination'))
87
87
 
88
88
  @instance.template(:hellothar_html_feh_).source.should == template_path("glob/hellothar.html.%feh%")
89
- @instance.template(:hellothar_html_feh_).destination.should == "/tmp/destination/hellothar.html.%feh%"
89
+ @instance.template(:hellothar_html_feh_).destination.should == tmp("/destination/hellothar.html.%feh%")
90
90
 
91
91
  @instance.file(:hellothar_feh_).source.should == template_path("glob/hellothar.%feh%")
92
- @instance.file(:hellothar_feh_).destination.should == "/tmp/destination/hellothar.%feh%"
92
+ @instance.file(:hellothar_feh_).destination.should == tmp("/destination/hellothar.%feh%")
93
93
  end
94
94
  end
@@ -4,33 +4,33 @@ describe Templater::Generator, '.template' do
4
4
 
5
5
  before do
6
6
  @generator_class = Class.new(Templater::Generator)
7
- @generator_class.stub!(:source_root).and_return('/tmp/source')
7
+ @generator_class.stub!(:source_root).and_return(tmp('source'))
8
8
  end
9
9
 
10
10
  it "should add a template with source and destination" do
11
11
  @generator_class.template(:my_template, 'path/to/source.rbt', 'path/to/destination.rb')
12
- @instance = @generator_class.new('/tmp/destination')
12
+ @instance = @generator_class.new(tmp('destination'))
13
13
 
14
- @instance.template(:my_template).source.should == '/tmp/source/path/to/source.rbt'
15
- @instance.template(:my_template).destination.should == '/tmp/destination/path/to/destination.rb'
14
+ @instance.template(:my_template).source.should == tmp('/source/path/to/source.rbt')
15
+ @instance.template(:my_template).destination.should == tmp('/destination/path/to/destination.rb')
16
16
  @instance.template(:my_template).should be_an_instance_of(Templater::Actions::Template)
17
17
  end
18
18
 
19
19
  it "should add a template with absolute source and destination" do
20
- @generator_class.template(:my_template, '/path/to/source.rbt', '/path/to/destination.rb')
21
- @instance = @generator_class.new('/tmp/destination')
20
+ @generator_class.template(:my_template, tmp('/path/to/source.rbt'), tmp('/path/to/destination.rb'))
21
+ @instance = @generator_class.new(tmp('destination'))
22
22
 
23
- @instance.template(:my_template).source.should == '/path/to/source.rbt'
24
- @instance.template(:my_template).destination.should == '/path/to/destination.rb'
23
+ @instance.template(:my_template).source.should == tmp('/path/to/source.rbt')
24
+ @instance.template(:my_template).destination.should == tmp('/path/to/destination.rb')
25
25
  @instance.template(:my_template).should be_an_instance_of(Templater::Actions::Template)
26
26
  end
27
27
 
28
28
  it "should add a template with destination and infer the source" do
29
29
  @generator_class.template(:my_template, 'path/to/destination.rb')
30
- @instance = @generator_class.new('/tmp/destination')
30
+ @instance = @generator_class.new(tmp('destination'))
31
31
 
32
- @instance.template(:my_template).source.should == '/tmp/source/path/to/destination.rbt'
33
- @instance.template(:my_template).destination.should == '/tmp/destination/path/to/destination.rb'
32
+ @instance.template(:my_template).source.should == tmp('/source/path/to/destination.rbt')
33
+ @instance.template(:my_template).destination.should == tmp('/destination/path/to/destination.rb')
34
34
  @instance.template(:my_template).should be_an_instance_of(Templater::Actions::Template)
35
35
  end
36
36
 
@@ -39,10 +39,10 @@ describe Templater::Generator, '.template' do
39
39
  template.source = 'blah.rbt'
40
40
  template.destination = "gurr#{Process.pid.to_s}.rb"
41
41
  end
42
- @instance = @generator_class.new('/tmp/destination')
42
+ @instance = @generator_class.new(tmp('destination'))
43
43
 
44
- @instance.template(:my_template).source.should == '/tmp/source/blah.rbt'
45
- @instance.template(:my_template).destination.should == "/tmp/destination/gurr#{Process.pid.to_s}.rb"
44
+ @instance.template(:my_template).source.should == tmp('/source/blah.rbt')
45
+ @instance.template(:my_template).destination.should == tmp("/destination/gurr#{Process.pid.to_s}.rb")
46
46
  @instance.template(:my_template).should be_an_instance_of(Templater::Actions::Template)
47
47
  end
48
48
 
@@ -51,32 +51,32 @@ describe Templater::Generator, '.template' do
51
51
  template.source = 'blah' / 'blah.rbt'
52
52
  template.destination = 'gurr' / "gurr#{something}.rb"
53
53
  end
54
- @instance = @generator_class.new('/tmp/destination')
54
+ @instance = @generator_class.new(tmp('destination'))
55
55
 
56
56
  @instance.stub!(:something).and_return('anotherthing')
57
57
 
58
- @instance.template(:my_template).source.should == '/tmp/source/blah/blah.rbt'
59
- @instance.template(:my_template).destination.should == "/tmp/destination/gurr/gurranotherthing.rb"
58
+ @instance.template(:my_template).source.should == tmp('/source/blah/blah.rbt')
59
+ @instance.template(:my_template).destination.should == tmp("/destination/gurr/gurranotherthing.rb")
60
60
  @instance.template(:my_template).should be_an_instance_of(Templater::Actions::Template)
61
61
  end
62
62
 
63
63
  it "should add a template and convert an with an instruction encoded in the destination, but not one encoded in the source" do
64
64
  @generator_class.template(:my_template, 'template/%some_method%.rbt', 'template/%another_method%.rb')
65
- @instance = @generator_class.new('/tmp/destination')
65
+ @instance = @generator_class.new(tmp('destination'))
66
66
 
67
67
  @instance.should_not_receive(:some_method)
68
68
  @instance.should_receive(:another_method).at_least(:once).and_return('beast')
69
69
 
70
- @instance.template(:my_template).source.should == '/tmp/source/template/%some_method%.rbt'
71
- @instance.template(:my_template).destination.should == "/tmp/destination/template/beast.rb"
70
+ @instance.template(:my_template).source.should == tmp('/source/template/%some_method%.rbt')
71
+ @instance.template(:my_template).destination.should == tmp("/destination/template/beast.rb")
72
72
  @instance.template(:my_template).should be_an_instance_of(Templater::Actions::Template)
73
73
  end
74
74
 
75
75
  it "should add a template and leave an encoded instruction be if it doesn't exist as a method" do
76
76
  @generator_class.template(:my_template, 'template/blah.rbt', 'template/%some_method%.rb')
77
- @instance = @generator_class.new('/tmp/destination')
77
+ @instance = @generator_class.new(tmp('destination'))
78
78
 
79
- @instance.template(:my_template).destination.should == "/tmp/destination/template/%some_method%.rb"
79
+ @instance.template(:my_template).destination.should == tmp("/destination/template/%some_method%.rb")
80
80
  @instance.template(:my_template).should be_an_instance_of(Templater::Actions::Template)
81
81
  end
82
82
 
@@ -168,18 +168,18 @@ describe Templater::Generator, '#template' do
168
168
 
169
169
  before do
170
170
  @generator_class = Class.new(Templater::Generator)
171
- @generator_class.stub!(:source_root).and_return('/tmp/source')
171
+ @generator_class.stub!(:source_root).and_return(tmp('/tmp/source'))
172
172
  end
173
173
 
174
174
  it "should find a template by name" do
175
175
  @generator_class.template(:blah1, 'blah.rb')
176
176
  @generator_class.template(:blah2, 'blah2.rb')
177
177
 
178
- instance = @generator_class.new('/tmp')
178
+ instance = @generator_class.new(tmp('tmp'))
179
179
 
180
180
  instance.template(:blah1).name.should == :blah1
181
- instance.template(:blah1).source.should == '/tmp/source/blah.rbt'
182
- instance.template(:blah1).destination.should == '/tmp/blah.rb'
181
+ instance.template(:blah1).source.should == tmp('/tmp/source/blah.rbt')
182
+ instance.template(:blah1).destination.should == tmp('/tmp/blah.rb')
183
183
  end
184
184
 
185
185
  it "should not return a template with an option that does not match." do
@@ -14,6 +14,31 @@ require 'rubygems'
14
14
  require 'spec'
15
15
  require 'fileutils'
16
16
 
17
+ # Added a cross-platform temporary directory helper
18
+ # This was taken from MSpec
19
+ # http://github.com/rubyspec/mspec/tree/master
20
+ # http://github.com/rubyspec/mspec/tree/master/lib/mspec/helpers/tmp.rb
21
+ module TmpDirHelper
22
+ def tmp(name)
23
+ unless @spec_temp_directory
24
+ [ "/private/tmp", "/tmp", "/var/tmp", ENV["TMPDIR"], ENV["TMP"],
25
+ ENV["TEMP"], ENV["USERPROFILE"] ].each do |dir|
26
+ if dir and File.directory?(dir) and File.writable?(dir)
27
+ temp = File.expand_path dir
28
+ temp = File.readlink temp if File.symlink? temp
29
+ @spec_temp_directory = temp
30
+ break
31
+ end
32
+ end
33
+ end
34
+
35
+ File.join @spec_temp_directory, name
36
+ end
37
+ end
38
+
39
+ # Add it to Object
40
+ Object.send(:include, TmpDirHelper)
41
+
17
42
  class MatchActionNames
18
43
  def initialize(*names)
19
44
  @names = names.map{|n| n.to_s}
@@ -35,4 +60,5 @@ end
35
60
 
36
61
  def have_names(*names)
37
62
  MatchActionNames.new(*names)
38
- end
63
+ end
64
+
@@ -67,19 +67,19 @@ describe Templater::Spec::Helpers, "#create" do
67
67
  include Templater::Spec::Helpers
68
68
 
69
69
  before do
70
- @instance = Gens::Gen.new('/tmp', {})
70
+ @instance = Gens::Gen.new(tmp('tmp'), {})
71
71
  @instance.stub!(:source_root).and_return('/source')
72
72
  end
73
73
 
74
74
  it "should match when the generator has a template with the expected destination" do
75
- @instance.should create('/tmp/blah.txt')
75
+ @instance.should create(tmp('/tmp/blah.txt'))
76
76
  end
77
77
 
78
78
  it "should match when the generator has a file with the expected destination" do
79
- @instance.should create('/tmp/arg.txt')
79
+ @instance.should create(tmp('/tmp/arg.txt'))
80
80
  end
81
81
 
82
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')
83
+ @instance.should_not create(tmp('/tmp/blurns.txt'))
84
84
  end
85
85
  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.4.4
4
+ version: 0.4.5
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-11-18 00:00:00 +02:00
12
+ date: 2008-11-25 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency