/
output_spec.rb
117 lines (90 loc) · 4.13 KB
/
output_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
require 'spec_helper'
require 'outputtestdata'
describe Output, 'when having a from and to set' do
before :each do
FileUtils.mkdir(OutputTestData.from) unless File.exists? OutputTestData.from
@o = Output.new
@o.from OutputTestData.from
@o.to OutputTestData.to
end
after :each do
FileUtils.rm_rf OutputTestData.to if File.exists? OutputTestData.to
FileUtils.rm_rf OutputTestData.from if File.exists? OutputTestData.from
end
describe 'and when outputting files' do
before :each do
File.open("#{OutputTestData.from}/test.txt", "w"){|f| f.write "test" }
end
it "should not output a file if not specified so" do
@o.execute
File.exist?("#{OutputTestData.to}/test.txt").should be_false
end
it "should output a file specified" do
@o.file 'test.txt'
@o.execute
File.exist?("#{OutputTestData.to}/test.txt").should be_true
end
end
describe 'and when outputting directories' do
before :each do
subdir = "#{OutputTestData.from}/subdir"
FileUtils.mkdir(subdir) unless File.exists? subdir
File.open("#{OutputTestData.from}/subdir/test.txt", "w"){|f| f.write "test_sub" }
end
it "should not output a directory if not specified so" do
@o.execute
File.exist?("#{OutputTestData.to}/subdir").should be_false
end
it "should output a directory and content if specified" do
@o.dir 'subdir'
@o.execute
File.exist?("#{OutputTestData.to}/subdir").should be_true
File.exist?("#{OutputTestData.to}/subdir/test.txt").should be_true
end
end
describe 'and when outputting nested directories' do
before :each do
subdir = "#{OutputTestData.from}/subdir/foo"
FileUtils.mkdir_p(subdir) unless File.exists? subdir
File.open("#{OutputTestData.from}/subdir/foo/test.txt", "w"){|f| f.write "test_sub" }
end
it "should not output a directory if not specified so" do
@o.execute
File.exist?("#{OutputTestData.to}/subdir/foo").should be_false
end
it "should output a directory and content if specified" do
@o.dir 'subdir'
@o.execute
File.exist?("#{OutputTestData.to}/subdir/foo").should be_true
File.exist?("#{OutputTestData.to}/subdir/foo/test.txt").should be_true
end
end
describe 'and when outputting files with renaming them at target' do
before :each do
subdir = "#{OutputTestData.from}/subdir/foo"
FileUtils.mkdir_p(subdir) unless File.exists? subdir
File.open("#{OutputTestData.from}/subdir/foo/test.txt", "w"){|f| f.write "test_sub" }
end
it "should rename and create entire path if nested deeply" do
@o.file 'subdir/foo/test.txt', :as => 'subdir/foo/hello.txt'
@o.execute
File.exist?("#{OutputTestData.to}/subdir/foo").should be_true
File.exist?("#{OutputTestData.to}/subdir/foo/hello.txt").should be_true
File.exist?("#{OutputTestData.to}/subdir/foo/test.txt").should be_false
end
end
describe 'and when using erb, should have templated output' do
before :each do
subdir = "#{OutputTestData.from}/subdir/foo"
FileUtils.mkdir_p(subdir) unless File.exists? subdir
File.open("#{OutputTestData.from}/subdir/foo/web.config.erb", "w"){|f| f.write "test_sub <%= my_value %>" }
end
it "should rename and create entire path if nested deeply" do
@o.erb 'subdir/foo/web.config.erb', :as => 'subdir/foo/web.config', :locals => { :my_value => 'hello' }
@o.execute
File.exist?("#{OutputTestData.to}/subdir/foo").should be_true
File.exist?("#{OutputTestData.to}/subdir/foo/web.config").should be_true
File.read("#{OutputTestData.to}/subdir/foo/web.config").should == "test_sub hello"
end
end
end