templater 0.1.6 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,97 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
-
3
- describe Templater::Actions::EmptyDirectory, '.new' do
4
- it "sets name and destination" do
5
- Templater::Actions::EmptyDirectory.new(:monkey, '/path/to/destination').
6
- name.should == :monkey
7
- end
8
-
9
- it 'sets destination' do
10
- Templater::Actions::EmptyDirectory.new(:monkey, '/path/to/destination').
11
- destination.should == '/path/to/destination'
12
- end
13
- end
14
-
15
-
16
-
17
-
18
- describe Templater::Actions::EmptyDirectory, '#relative_destination' do
19
- it "returns destination relative to the pwd" do
20
- Dir.stub!(:pwd).and_return('/path/to')
21
- file = Templater::Actions::EmptyDirectory.new(:monkey, '/path/to/destination/with/some/more/subdirs')
22
- file.relative_destination.should == 'destination/with/some/more/subdirs'
23
- end
24
- end
25
-
26
-
27
-
28
-
29
- describe Templater::Actions::EmptyDirectory, '#render' do
30
- it 'does nothing for empty directories?'
31
- end
32
-
33
-
34
-
35
-
36
- describe Templater::Actions::EmptyDirectory, '#exists?' do
37
-
38
- it "should exist if the destination file exists" do
39
- file = Templater::Actions::EmptyDirectory.new(:monkey, result_path('erb.rbs'))
40
- file.should be_exists
41
- end
42
-
43
- it "should not exist if the destination file does not exist" do
44
- file = Templater::Actions::EmptyDirectory.new(:monkey, result_path('some_weird_file.rbs'))
45
- file.should_not be_exists
46
- end
47
- end
48
-
49
-
50
-
51
- describe Templater::Actions::EmptyDirectory, '#identical' do
52
- it "should not be identical if the destination file doesn't exist" do
53
- file = Templater::Actions::EmptyDirectory.new(:monkey, result_path('some_weird/path/that_does/not_exist'))
54
- file.should_not be_identical
55
- end
56
-
57
- it "should not be identical if the destination file is not identical to the source file" do
58
- file = Templater::Actions::EmptyDirectory.new(:monkey, result_path('simple_erb.rbs'))
59
- file.should be_exists
60
- file.should be_identical
61
- end
62
-
63
- it "should be identical if the destination file is identical to the source file" do
64
- file= Templater::Actions::EmptyDirectory.new(:monkey, result_path('file.rbs'))
65
- file.should be_exists
66
- file.should be_identical
67
- end
68
- end
69
-
70
-
71
-
72
- describe Templater::Actions::EmptyDirectory, '#invoke!' do
73
- it "should copy the source file to the destination" do
74
- file = Templater::Actions::EmptyDirectory.new(:monkey, result_path('path/to/subdir/test2.rbs'))
75
-
76
- file.invoke!
77
-
78
- File.exists?(result_path('path/to/subdir/test2.rbs')).should be_true
79
-
80
- # cleanup
81
- FileUtils.rm_rf(result_path('path'))
82
- end
83
- end
84
-
85
-
86
-
87
- describe Templater::Actions::EmptyDirectory, '#revoke!' do
88
- it "removes the destination directory" do
89
- file = Templater::Actions::EmptyDirectory.new(:monkey, result_path('path/to/empty/subdir/'))
90
-
91
- file.invoke!
92
- File.exists?(result_path('path/to/empty/subdir/')).should be_true
93
-
94
- file.revoke!
95
- File.exists?(result_path('path/to/empty/subdir/')).should be_false
96
- end
97
- end
data/spec/file_spec.rb DELETED
@@ -1,97 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
-
3
- describe Templater::Actions::File, '.new' do
4
- it "should set name, source and destination" do
5
- file = Templater::Actions::File.new(:monkey, '/path/to/source', '/path/to/destination')
6
- file.name.should == :monkey
7
- file.source.should == '/path/to/source'
8
- file.destination.should == '/path/to/destination'
9
- end
10
- end
11
-
12
- describe Templater::Actions::File, '#relative_destination' do
13
- it "should get the destination relative to the pwd" do
14
- Dir.stub!(:pwd).and_return('/path/to')
15
- file = Templater::Actions::File.new(:monkey, '/path/to/source', '/path/to/destination/with/some/more/subdirs')
16
- file.relative_destination.should == 'destination/with/some/more/subdirs'
17
- end
18
- end
19
-
20
- describe Templater::Actions::File, '#render' do
21
- it "should output the file" do
22
- file = Templater::Actions::File.new(:monkey, template_path('simple_erb.rbt'), '/path/to/destination')
23
- file.render.should == "test<%= 1+1 %>test"
24
- end
25
- end
26
-
27
- describe Templater::Actions::File, '#exists?' do
28
-
29
- it "should exist if the destination file exists" do
30
- file = Templater::Actions::File.new(:monkey, template_path('simple.rbt'), result_path('erb.rbs'))
31
- file.should be_exists
32
- end
33
-
34
- it "should not exist if the destination file does not exist" do
35
- file = Templater::Actions::File.new(:monkey, template_path('simple.rbt'), result_path('some_weird_file.rbs'))
36
- file.should_not be_exists
37
- end
38
-
39
- end
40
-
41
- describe Templater::Actions::File, '#identical' do
42
-
43
- it "should not be identical if the destination file doesn't exist" do
44
- file = Templater::Actions::File.new(:monkey, template_path('simple_erb.rbt'), result_path('some_weird_file.rbs'))
45
- file.should_not be_identical
46
- end
47
-
48
- it "should not be identical if the destination file is not identical to the source file" do
49
- file = Templater::Actions::File.new(:monkey, template_path('simple_erb.rbt'), result_path('simple_erb.rbs'))
50
- file.should be_exists
51
- file.should_not be_identical
52
- end
53
-
54
- it "should be identical if the destination file is identical to the source file" do
55
- file= Templater::Actions::File.new(:monkey, template_path('simple_erb.rbt'), result_path('file.rbs'))
56
- file.should be_exists
57
- file.should be_identical
58
- end
59
- end
60
-
61
- describe Templater::Actions::File, '#invoke!' do
62
-
63
- it "should copy the source file to the destination" do
64
- file = Templater::Actions::File.new(:monkey, template_path('simple_erb.rbt'), result_path('path/to/subdir/test2.rbs'))
65
-
66
- file.invoke!
67
-
68
- File.exists?(result_path('path/to/subdir/test2.rbs')).should be_true
69
- FileUtils.identical?(template_path('simple_erb.rbt'), result_path('path/to/subdir/test2.rbs')).should be_true
70
-
71
- # cleanup
72
- FileUtils.rm_rf(result_path('path'))
73
- end
74
- end
75
-
76
- describe Templater::Actions::File, '#revoke!' do
77
-
78
- it "should remove the destination file" do
79
- file = Templater::Actions::File.new(:monkey, template_path('simple_erb.rbt'), result_path('path/to/subdir/test2.rbs'))
80
-
81
- file.invoke!
82
-
83
- File.exists?(result_path('path/to/subdir/test2.rbs')).should be_true
84
- FileUtils.identical?(template_path('simple_erb.rbt'), result_path('path/to/subdir/test2.rbs')).should be_true
85
-
86
- file.revoke!
87
-
88
- File.exists?(result_path('path/to/subdir/test2.rbs')).should be_false
89
- end
90
-
91
- it "should do nothing when the destination file doesn't exist" do
92
- file = Templater::Actions::File.new(:monkey, template_path('simple_erb.rbt'), result_path('path/to/subdir/test2.rbs'))
93
-
94
- lambda { file.revoke! }.should_not raise_error
95
- end
96
-
97
- end
@@ -1,137 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
-
3
- describe Templater::Actions::Template, '.new' do
4
- it "should set name, source and destination" do
5
- template = Templater::Actions::Template.new('some_context', :monkey, '/path/to/source', '/path/to/destination')
6
- template.context.should == 'some_context'
7
- template.name.should == :monkey
8
- template.source.should == '/path/to/source'
9
- template.destination.should == '/path/to/destination'
10
- end
11
- end
12
-
13
- describe Templater::Actions::Template, '#relative_destination' do
14
- it "should get the destination relative to the pwd" do
15
- Dir.stub!(:pwd).and_return('/path/to')
16
- template = Templater::Actions::Template.new('some_context', :monkey, '/path/to/source', '/path/to/destination/with/some/more/subdirs')
17
- template.relative_destination.should == 'destination/with/some/more/subdirs'
18
- end
19
- end
20
-
21
- describe Templater::Actions::Template, '#render' do
22
- before do
23
- @context = class << self; self end
24
- end
25
-
26
- it "should render a simple template" do
27
- template = Templater::Actions::Template.new(@context, :monkey, template_path('simple.rbt'), '/path/to/destination')
28
- template.render.should == "Hello World"
29
- end
30
-
31
- it "should render some basic erb" do
32
- template = Templater::Actions::Template.new(@context, :monkey, template_path('simple_erb.rbt'), '/path/to/destination')
33
- template.render.should == "test2test"
34
- end
35
-
36
- it "should render some erb and convert erb literals" do
37
- template = Templater::Actions::Template.new(@context, :monkey, template_path('literals_erb.rbt'), '/path/to/destination')
38
- template.render.should == "test2test<%= 1+1 %>blah"
39
- end
40
-
41
- it "should render some erb fetching stuff from the context" do
42
- @context.should_receive(:funkydoodle).and_return('_doodle_')
43
- template = Templater::Actions::Template.new(@context, :monkey, template_path('erb.rbt'), '/path/to/destination')
44
- template.render.should == "test_doodle_blah"
45
- end
46
- end
47
-
48
- describe Templater::Actions::Template, '#exists?' do
49
-
50
- it "should exist if the destination file exists" do
51
- template = Templater::Actions::Template.new(@context, :monkey, template_path('simple.rbt'), result_path('erb.rbs'))
52
- template.should be_exists
53
- end
54
-
55
- it "should not exist if the destination file does not exist" do
56
- template = Templater::Actions::Template.new(@context, :monkey, template_path('simple.rbt'), result_path('some_weird_file.rbs'))
57
- template.should_not be_exists
58
- end
59
-
60
- end
61
-
62
- describe Templater::Actions::Template, '#identical' do
63
- before do
64
- @context = class << self; self end
65
- end
66
-
67
- it "should not be identical if the destination file doesn't exist" do
68
- template = Templater::Actions::Template.new(@context, :monkey, template_path('simple_erb.rbt'), result_path('some_weird_file.rbs'))
69
- template.should_not be_identical
70
- end
71
-
72
- it "should not be identical if the rendered content does not match the content of the file" do
73
- template = Templater::Actions::Template.new(@context, :monkey, template_path('simple_erb.rbt'), result_path('random.rbs'))
74
- template.should be_exists
75
- template.should_not be_identical
76
- end
77
-
78
- it "should be identical if the rendered content matches the content of the file" do
79
- template = Templater::Actions::Template.new(@context, :monkey, template_path('simple_erb.rbt'), result_path('simple_erb.rbs'))
80
- template.should be_exists
81
- template.should be_identical
82
- end
83
- end
84
-
85
- describe Templater::Actions::Template, '#invoke!' do
86
- before do
87
- @context = class << self; self end
88
- end
89
-
90
- it "should render the template and copy it to the destination" do
91
- template = Templater::Actions::Template.new(@context, :monkey, template_path('simple_erb.rbt'), result_path('test.rbs'))
92
-
93
- template.invoke!
94
-
95
- File.exists?(result_path('test.rbs')).should be_true
96
- File.read(result_path('test.rbs')).should == "test2test"
97
-
98
- FileUtils.rm(result_path('test.rbs'))
99
- end
100
-
101
- it "should render the template and copy it to the destination, creating any required subdirectories" do
102
- template = Templater::Actions::Template.new(@context, :monkey, template_path('simple_erb.rbt'), result_path('path/to/subdir/test.rbs'))
103
-
104
- template.invoke!
105
-
106
- File.exists?(result_path('path/to/subdir/test.rbs')).should be_true
107
- File.read(result_path('path/to/subdir/test.rbs')).should == "test2test"
108
-
109
- # cleanup
110
- FileUtils.rm_rf(result_path('path'))
111
- end
112
-
113
- end
114
-
115
-
116
- describe Templater::Actions::Template, '#revoke!' do
117
-
118
- it "should remove the destination file" do
119
- template = Templater::Actions::Template.new(@context, :monkey, template_path('simple_erb.rbt'), result_path('test.rbs'))
120
-
121
- template.invoke!
122
-
123
- File.exists?(result_path('test.rbs')).should be_true
124
- File.read(result_path('test.rbs')).should == "test2test"
125
-
126
- template.revoke!
127
-
128
- File.exists?(result_path('test.rbs')).should be_false
129
- end
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
-
137
- end