pointrb 0.0.1 → 0.1.0
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.
- data/.gitignore +16 -0
- data/.rspec +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +2 -1
- data/Gemfile.lock +40 -26
- data/README.md +1 -86
- data/Rakefile +5 -0
- data/TODO.md +35 -1
- data/bin/pointrb +35 -0
- data/cucumber.yml +3 -0
- data/features/create_layout.feature +96 -0
- data/features/create_new_project.feature +29 -0
- data/features/pointrb_setup.feature +22 -0
- data/features/step_definitions.rb +96 -0
- data/features/support/env.rb +26 -0
- data/features/support/helper.rb +62 -0
- data/features/test.feature +0 -0
- data/gemfiles/Gemfile.default +2 -1
- data/lib/bob_the_helper/command/command_result.rb +12 -0
- data/lib/bob_the_helper/command.rb +49 -0
- data/lib/bob_the_helper/environment.rb +27 -0
- data/lib/bob_the_helper/file_system/exceptions.rb +11 -0
- data/lib/bob_the_helper/file_system.rb +245 -0
- data/lib/bob_the_helper.rb +5 -0
- data/lib/pointrb/actions/check_if_pointrb_has_already_been_initialized.rb +15 -0
- data/lib/pointrb/actions/check_project_path.rb +15 -0
- data/lib/pointrb/actions/create_layout.rb +16 -0
- data/lib/pointrb/actions/create_project_wrapper.rb +15 -0
- data/lib/pointrb/actions/determine_layout_directory.rb +14 -0
- data/lib/pointrb/actions/error_handler_commandline.rb +39 -0
- data/lib/pointrb/actions/initialize_pointrb.rb +15 -0
- data/lib/pointrb/actions/retrieve_layout_files.rb +16 -0
- data/lib/pointrb/actions/retrieve_parsed_layout.rb +17 -0
- data/lib/pointrb/actions/set_project_name.rb +15 -0
- data/lib/pointrb/actions/show_pointrb_version.rb +14 -0
- data/lib/pointrb/api.rb +36 -0
- data/lib/pointrb/directory.rb +25 -0
- data/lib/pointrb/exceptions.rb +22 -0
- data/lib/pointrb/layout.rb +16 -0
- data/lib/pointrb/layout_constructor.rb +58 -0
- data/lib/pointrb/layout_file.rb +24 -0
- data/lib/pointrb/layout_manager.rb +32 -0
- data/lib/pointrb/layout_storage_manager.rb +40 -0
- data/lib/pointrb/layout_tree.rb +45 -0
- data/lib/pointrb/pointrb_file.rb +33 -0
- data/lib/pointrb/project.rb +11 -0
- data/lib/pointrb/version.rb +1 -1
- data/lib/pointrb.rb +32 -0
- data/pointrb.gemspec +3 -2
- data/script/terminal +1 -0
- data/spec/bob_the_helper/command/command_spec.rb +55 -0
- data/spec/bob_the_helper/environment/environment_spec.rb +15 -0
- data/spec/bob_the_helper/file_system/file_system_spec.rb +279 -0
- data/spec/directory/directory_spec.rb +30 -0
- data/spec/hooks.rb +5 -0
- data/spec/layout/layout_spec.rb +20 -0
- data/spec/layout_constructor/layout_constructor_spec.rb +122 -0
- data/spec/layout_file/layout_file_spec.rb +49 -0
- data/spec/layout_manager/layout_manager_spec.rb +47 -0
- data/spec/layout_storage_manager/layout_storage_manager_spec.rb +58 -0
- data/spec/layout_tree/layout_tree_spec.rb +70 -0
- data/spec/pointrb_file/pointrb_file_spec.rb +34 -0
- data/spec/project/project_spec.rb +19 -0
- data/spec/spec_helper.rb +9 -13
- data/spec/support/capture.rb +19 -0
- data/spec/support/env.rb +0 -0
- data/spec/support/helper.rb +8 -0
- data/spec/support/hooks.rb +5 -0
- metadata +104 -5
@@ -0,0 +1,279 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe BobTheHelper::FileSystem do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
cleanup_working_directory
|
7
|
+
end
|
8
|
+
|
9
|
+
it "returns the root directory for the project" do
|
10
|
+
path = File.expand_path('../../../../', __FILE__)
|
11
|
+
expect(root_directory).to eq(path)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "returns the tmp directory for tests for the project: <root>/tmp/test'" do
|
15
|
+
path = File.expand_path('../../../../tmp/test', __FILE__)
|
16
|
+
expect(working_directory).to eq(path)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "switches to the temporary directory" do
|
20
|
+
path = ''
|
21
|
+
switch_to_working_directory do
|
22
|
+
path = Dir.pwd
|
23
|
+
end
|
24
|
+
expect(path).to eq(working_directory)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "creates a directory in the tmp directory" do
|
28
|
+
directory_to_be_created = 'blub'
|
29
|
+
path = File.expand_path('../../../../tmp/test/blub', __FILE__)
|
30
|
+
|
31
|
+
created_directory = create_directory(directory_to_be_created)
|
32
|
+
|
33
|
+
expect(created_directory).to eq(path)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "supports creating multiple directories" do
|
37
|
+
directory_to_be_created = %w[ blub bla test123]
|
38
|
+
paths = directory_to_be_created.map { |d| File.expand_path("../../../../tmp/test/#{d}", __FILE__) }
|
39
|
+
|
40
|
+
created_directories = create_directory(*directory_to_be_created)
|
41
|
+
|
42
|
+
expect(created_directories).to eq(paths)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "creates a file in the tmp directory" do
|
46
|
+
file = 'bla.txt'
|
47
|
+
content = 'this is content'
|
48
|
+
|
49
|
+
created_file = create_file(file, content)
|
50
|
+
|
51
|
+
file_content = ''
|
52
|
+
switch_to_working_directory do
|
53
|
+
file_content = File.read(created_file).chomp
|
54
|
+
end
|
55
|
+
|
56
|
+
expect(file_content).to eq(content)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "creates an empty file in the tmp directory" do
|
60
|
+
file = 'bla.txt'
|
61
|
+
created_file = create_file(file)
|
62
|
+
|
63
|
+
file_content = ''
|
64
|
+
switch_to_working_directory do
|
65
|
+
file_content = File.read(created_file).chomp
|
66
|
+
end
|
67
|
+
|
68
|
+
expect(file_content).to eq('')
|
69
|
+
end
|
70
|
+
|
71
|
+
it "creates a file in a subdirectory in the tmp directory" do
|
72
|
+
file = 'test_dir/bla.txt'
|
73
|
+
content = 'this is content'
|
74
|
+
|
75
|
+
created_file = create_file(file, content)
|
76
|
+
|
77
|
+
file_content = ''
|
78
|
+
switch_to_working_directory do
|
79
|
+
file_content = File.read(created_file).chomp
|
80
|
+
end
|
81
|
+
|
82
|
+
expect(file_content).to eq(content)
|
83
|
+
end
|
84
|
+
|
85
|
+
it "reads files from the tmp directory" do
|
86
|
+
file = 'blub123.txt'
|
87
|
+
content = "test 12 3"
|
88
|
+
|
89
|
+
switch_to_working_directory do
|
90
|
+
File.open(file, "wb") do |f|
|
91
|
+
f.write content
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
file_content = read_file(file)
|
96
|
+
expect(file_content).to eq(content)
|
97
|
+
end
|
98
|
+
|
99
|
+
it "checks if a directory/file exists" do
|
100
|
+
file = 'blub123.txt'
|
101
|
+
|
102
|
+
switch_to_working_directory do
|
103
|
+
File.open(file, "wb") do |f|
|
104
|
+
f.write ''
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
result = path_exists? file
|
109
|
+
expect(result).to eq(true)
|
110
|
+
|
111
|
+
result = path_exists? 'asfdasdfsadf.txt'
|
112
|
+
expect(result).to eq(false)
|
113
|
+
end
|
114
|
+
|
115
|
+
it "checks existance for multiple files" do
|
116
|
+
files = %w[ blub123.txt asdf.txt asdfe2.txt ]
|
117
|
+
|
118
|
+
switch_to_working_directory do
|
119
|
+
files.each do |file|
|
120
|
+
File.open(file, "wb") do |f|
|
121
|
+
f.write ''
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
result = path_exists? *files
|
127
|
+
expect(result).to eq(true)
|
128
|
+
end
|
129
|
+
|
130
|
+
it "checks absence for multiple files" do
|
131
|
+
files = %w[ blub123.txt asdf.txt asdfe2.txt ]
|
132
|
+
|
133
|
+
result = path_does_not_exist? *files
|
134
|
+
expect(result).to eq(true)
|
135
|
+
end
|
136
|
+
|
137
|
+
it "deletes existing directories" do
|
138
|
+
directory_to_be_deleted = 'blub'
|
139
|
+
path = File.expand_path('../../../../tmp/test/blub', __FILE__)
|
140
|
+
|
141
|
+
switch_to_working_directory do
|
142
|
+
FileUtils.mkdir_p 'blub'
|
143
|
+
end
|
144
|
+
|
145
|
+
deleted_directory = delete_directory(directory_to_be_deleted)
|
146
|
+
expect(deleted_directory).to eq(path)
|
147
|
+
end
|
148
|
+
|
149
|
+
it "supports deleting multiple directories" do
|
150
|
+
directories_to_be_deleted = %w[ blub bla test123]
|
151
|
+
paths = directories_to_be_deleted.map { |d| File.expand_path("../../../../tmp/test/#{d}", __FILE__) }
|
152
|
+
|
153
|
+
switch_to_working_directory do
|
154
|
+
directories_to_be_deleted.each do |d|
|
155
|
+
FileUtils.mkdir_p d
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
deleted_directories = delete_directory(*directories_to_be_deleted)
|
160
|
+
|
161
|
+
expect(deleted_directories).to eq(paths)
|
162
|
+
end
|
163
|
+
|
164
|
+
it "deletes existing single file" do
|
165
|
+
file_to_be_deleted = 'blub.txt_123'
|
166
|
+
path = File.expand_path('../../../../tmp/test/blub.txt_123', __FILE__)
|
167
|
+
|
168
|
+
switch_to_working_directory do
|
169
|
+
File.open(file_to_be_deleted, "wb") do |f|
|
170
|
+
f.write ''
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
deleted_file = delete_file(file_to_be_deleted)
|
175
|
+
expect(deleted_file).to eq(path)
|
176
|
+
end
|
177
|
+
|
178
|
+
it "deletes existing multiple files" do
|
179
|
+
files = %w[ blub.txt_123 blub.txt_456 ]
|
180
|
+
|
181
|
+
paths = files.map {|f| File.expand_path("../../../../tmp/test/#{f}", __FILE__) }
|
182
|
+
|
183
|
+
switch_to_working_directory do
|
184
|
+
files.each do |p|
|
185
|
+
File.open(p, "wb") do |f|
|
186
|
+
f.write ''
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
deleted_files = delete_file files
|
192
|
+
expect(deleted_files).to eq(paths)
|
193
|
+
end
|
194
|
+
|
195
|
+
it "let you create the temporary directory" do
|
196
|
+
create_working_directory
|
197
|
+
expect(File.exists? working_directory).to eq(true)
|
198
|
+
end
|
199
|
+
|
200
|
+
it "let you delete the temporary directory" do
|
201
|
+
delete_working_directory
|
202
|
+
expect(File.exists? working_directory).to eq(false)
|
203
|
+
end
|
204
|
+
|
205
|
+
it "let you cleanup the temp directory" do
|
206
|
+
cleanup_working_directory
|
207
|
+
|
208
|
+
pattern = File.join(working_directory, '*' )
|
209
|
+
entries = Dir.glob(pattern)
|
210
|
+
|
211
|
+
expect(entries.blank?).to eq(true)
|
212
|
+
end
|
213
|
+
|
214
|
+
it "expand paths to temporary directory" do
|
215
|
+
files = %w[ blub.txt_123 blub.txt_456 /path/abc ./path/abc ]
|
216
|
+
new_path_via_lib = expand_path(files)
|
217
|
+
|
218
|
+
files.each do |f|
|
219
|
+
this_path = new_path_via_lib.shift
|
220
|
+
expect(File.join(working_directory, f)).to eq(this_path)
|
221
|
+
end
|
222
|
+
|
223
|
+
end
|
224
|
+
|
225
|
+
it "checks forbidden paths during remove operations" do
|
226
|
+
good_paths = %w[ blub.txt_123 /path/to/x /home/user/y ]
|
227
|
+
bad_paths = [
|
228
|
+
'/'
|
229
|
+
]
|
230
|
+
|
231
|
+
bad_paths.each do |p|
|
232
|
+
expect {
|
233
|
+
raise_if_forbidden_path_for_delete_operation(p)
|
234
|
+
}.to raise_error BobTheHelper::FileSystem::Exceptions::InvalidPath
|
235
|
+
end
|
236
|
+
|
237
|
+
good_paths.each do |p|
|
238
|
+
expect {
|
239
|
+
raise_if_forbidden_path_for_delete_operation(p)
|
240
|
+
}.to_not raise_error
|
241
|
+
end
|
242
|
+
|
243
|
+
expect {
|
244
|
+
raise_if_forbidden_path_for_delete_operation(bad_paths)
|
245
|
+
}.to raise_error BobTheHelper::FileSystem::Exceptions::InvalidPath
|
246
|
+
|
247
|
+
expect {
|
248
|
+
raise_if_forbidden_path_for_delete_operation(good_paths)
|
249
|
+
}.to_not raise_error
|
250
|
+
|
251
|
+
end
|
252
|
+
|
253
|
+
it "checks forbidden paths during create operations" do
|
254
|
+
good_paths = %w[ blub.txt_123 /path/to/x /home/user/y ]
|
255
|
+
bad_paths = [
|
256
|
+
'/path/with/../',
|
257
|
+
]
|
258
|
+
|
259
|
+
bad_paths.each do |p|
|
260
|
+
expect {
|
261
|
+
raise_if_forbidden_path_for_create_operation(p)
|
262
|
+
}.to raise_error BobTheHelper::FileSystem::Exceptions::InvalidPath
|
263
|
+
end
|
264
|
+
|
265
|
+
good_paths.each do |p|
|
266
|
+
expect {
|
267
|
+
raise_if_forbidden_path_for_create_operation(p)
|
268
|
+
}.to_not raise_error
|
269
|
+
end
|
270
|
+
|
271
|
+
expect {
|
272
|
+
raise_if_forbidden_path_for_create_operation(bad_paths)
|
273
|
+
}.to raise_error BobTheHelper::FileSystem::Exceptions::InvalidPath
|
274
|
+
|
275
|
+
expect {
|
276
|
+
raise_if_forbidden_path_for_create_operation(good_paths)
|
277
|
+
}.to_not raise_error
|
278
|
+
end
|
279
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Directory do
|
4
|
+
|
5
|
+
it "has a path and a base dir" do
|
6
|
+
Directory.new('path', 'basedir')
|
7
|
+
end
|
8
|
+
|
9
|
+
it "can be created" do
|
10
|
+
dir = Directory.new('path', working_directory)
|
11
|
+
dir.create
|
12
|
+
|
13
|
+
dir_path = File.join(working_directory, 'path')
|
14
|
+
result = File.exists?(dir_path)
|
15
|
+
|
16
|
+
expect(result).to eq(true)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns the full path" do
|
20
|
+
dir = Directory.new('path', working_directory)
|
21
|
+
check = File.join(working_directory, 'path')
|
22
|
+
expect(dir.full_path).to eq(check)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "returns path if it starts with '/'" do
|
26
|
+
path = '/path'
|
27
|
+
dir = Directory.new(path)
|
28
|
+
expect(dir.full_path).to eq(path)
|
29
|
+
end
|
30
|
+
end
|
data/spec/hooks.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Layout do
|
4
|
+
it "creates the directory structure" do
|
5
|
+
action = Class.new do
|
6
|
+
def create
|
7
|
+
puts "hey, create"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
layout = Layout.new
|
12
|
+
layout.actions << action.new
|
13
|
+
|
14
|
+
result = capture(:stdout) do
|
15
|
+
layout.create
|
16
|
+
end
|
17
|
+
|
18
|
+
expect(result.chomp).to eq('hey, create')
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe LayoutConstructor do
|
4
|
+
let(:project) do
|
5
|
+
Class.new do
|
6
|
+
def name
|
7
|
+
'new_project'
|
8
|
+
end
|
9
|
+
|
10
|
+
def path
|
11
|
+
File.join(working_directory, name)
|
12
|
+
end
|
13
|
+
end.new
|
14
|
+
end
|
15
|
+
let(:layout_constructor) { LayoutConstructor.new(project) }
|
16
|
+
|
17
|
+
it "parses a layout with a name" do
|
18
|
+
layout = "layout :name do; end"
|
19
|
+
file = 'blub.layout'
|
20
|
+
result = layout_constructor.parse_dsl(layout, file)
|
21
|
+
expect(result.name).to eq(:name)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "parses a layout with a directory" do
|
25
|
+
layout = <<-EOB
|
26
|
+
layout :name do
|
27
|
+
directory 'path'
|
28
|
+
end
|
29
|
+
EOB
|
30
|
+
file = 'blub.layout'
|
31
|
+
result = layout_constructor.parse_dsl(layout, file)
|
32
|
+
#root directory + directory 'path'
|
33
|
+
expect(result.actions.size).to eq(2)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "parses a layout with a nested directory" do
|
37
|
+
layout = <<-EOB
|
38
|
+
layout :name do
|
39
|
+
directory 'path' do
|
40
|
+
directory 'subpath'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
EOB
|
44
|
+
|
45
|
+
paths = [
|
46
|
+
project.path,
|
47
|
+
File.join(project.path, 'path'),
|
48
|
+
File.join(project.path, 'path', 'subpath'),
|
49
|
+
]
|
50
|
+
file = 'blub.layout'
|
51
|
+
parsed_layout = layout_constructor.parse_dsl(layout,file)
|
52
|
+
result = parsed_layout.actions.all? { |node| node.full_path == paths.shift }
|
53
|
+
|
54
|
+
expect(result).to eq(true)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "parses a layout with a file" do
|
58
|
+
layout = <<-EOB
|
59
|
+
layout :name do
|
60
|
+
file 'path' do
|
61
|
+
'content'
|
62
|
+
end
|
63
|
+
end
|
64
|
+
EOB
|
65
|
+
|
66
|
+
paths = [
|
67
|
+
project.path,
|
68
|
+
File.join(project.path, 'path'),
|
69
|
+
]
|
70
|
+
file = 'blub.layout'
|
71
|
+
parsed_layout = layout_constructor.parse_dsl(layout, file)
|
72
|
+
|
73
|
+
result = parsed_layout.actions.all? { |node| node.full_path == paths.shift }
|
74
|
+
expect(result).to eq(true)
|
75
|
+
|
76
|
+
content = [
|
77
|
+
'content'
|
78
|
+
]
|
79
|
+
|
80
|
+
result = parsed_layout.actions.find_all{ |a| a.kind_of? PointRbFile}.all?{ |node| node.content == content.shift }
|
81
|
+
expect(result).to eq(true)
|
82
|
+
end
|
83
|
+
|
84
|
+
it "parses a layout with a file and multiple lines" do
|
85
|
+
layout = <<-EOB
|
86
|
+
layout :name do
|
87
|
+
file 'path' do
|
88
|
+
<<-HERE
|
89
|
+
content
|
90
|
+
content
|
91
|
+
content
|
92
|
+
content
|
93
|
+
content
|
94
|
+
content
|
95
|
+
HERE
|
96
|
+
end
|
97
|
+
end
|
98
|
+
EOB
|
99
|
+
|
100
|
+
file = 'blub.layout'
|
101
|
+
parsed_layout = layout_constructor.parse_dsl(layout, file)
|
102
|
+
|
103
|
+
file_content = [
|
104
|
+
'content
|
105
|
+
content
|
106
|
+
content
|
107
|
+
content
|
108
|
+
content
|
109
|
+
content
|
110
|
+
'
|
111
|
+
]
|
112
|
+
|
113
|
+
result = parsed_layout.actions.find_all{ |a| a.kind_of? PointRbFile}.all?{ |node| node.content == file_content.first}
|
114
|
+
expect(result).to eq(true)
|
115
|
+
end
|
116
|
+
|
117
|
+
it "returns the file name of the parsed layout when an error occured" do
|
118
|
+
layout = "garbage"
|
119
|
+
file = 'blub.layout'
|
120
|
+
expect { parsed_layout = layout_constructor.parse_dsl(layout, file) }.to raise_error(Exceptions::SyntaxErrorInLayout, 'Syntax error in layout-file "blub.layout" at line 1')
|
121
|
+
end
|
122
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe LayoutFile do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
@file = 'layouts/new_layout1.layout'
|
7
|
+
|
8
|
+
@content = <<-EOF
|
9
|
+
layout :name1 do
|
10
|
+
end
|
11
|
+
EOF
|
12
|
+
|
13
|
+
create_file @file, @content
|
14
|
+
|
15
|
+
@full_path = File.join(working_directory, @file )
|
16
|
+
@layout_file = LayoutFile.new(@full_path)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns the path of the layout" do
|
20
|
+
expect(@layout_file.path).to eq(@full_path)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "returns the content of the layout file" do
|
24
|
+
expect(@layout_file.content).to eq(@content)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "raises an Error if an unexisting layout file is given" do
|
28
|
+
expect {
|
29
|
+
LayoutFile.new('invalid path')
|
30
|
+
}.to raise_error Exceptions::FileNotFound
|
31
|
+
end
|
32
|
+
|
33
|
+
it "let you compare instances by path" do
|
34
|
+
file1 = 'layouts/layout1.layout'
|
35
|
+
file2 = 'layouts/layout2.layout'
|
36
|
+
|
37
|
+
create_file file1
|
38
|
+
create_file file2
|
39
|
+
|
40
|
+
layout_file1 = LayoutFile.new(File.join(working_directory, file1))
|
41
|
+
layout_file2 = LayoutFile.new(File.join(working_directory, file2))
|
42
|
+
|
43
|
+
result = ( layout_file1 == layout_file1 )
|
44
|
+
expect(result).to eq(true)
|
45
|
+
|
46
|
+
result = ( layout_file1 == layout_file2 )
|
47
|
+
expect(result).to eq(false)
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe LayoutManager do
|
4
|
+
|
5
|
+
let(:layout_file) do
|
6
|
+
Class.new do
|
7
|
+
def path
|
8
|
+
"file/path/to/source"
|
9
|
+
end
|
10
|
+
|
11
|
+
def content
|
12
|
+
<<-EOF
|
13
|
+
layout :name do
|
14
|
+
directory "path/to/directory"
|
15
|
+
end
|
16
|
+
EOF
|
17
|
+
end
|
18
|
+
end.new
|
19
|
+
end
|
20
|
+
|
21
|
+
let(:project) do
|
22
|
+
Class.new do
|
23
|
+
def name
|
24
|
+
'blub'
|
25
|
+
end
|
26
|
+
|
27
|
+
def path
|
28
|
+
File.join(working_directory, name)
|
29
|
+
end
|
30
|
+
end.new
|
31
|
+
end
|
32
|
+
|
33
|
+
it "retrieves a layout by name" do
|
34
|
+
|
35
|
+
layout_manager = LayoutManager.new([layout_file], project)
|
36
|
+
layout = layout_manager.retrieve(:name)
|
37
|
+
|
38
|
+
expect(layout.name).to eq(:name)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "raises an exception if requested layout was not found" do
|
42
|
+
layout_manager = LayoutManager.new([layout_file], project)
|
43
|
+
expect {
|
44
|
+
layout_manager.retrieve(:name_abc_def)
|
45
|
+
}.to raise_error Exceptions::LayoutNotFound
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe LayoutStorageManager do
|
5
|
+
let(:layout_directory) { File.join(working_directory, 'layouts') }
|
6
|
+
let(:layout_file_klass) do
|
7
|
+
Class.new do
|
8
|
+
attr_reader :path
|
9
|
+
|
10
|
+
def initialize(p)
|
11
|
+
@path = p
|
12
|
+
end
|
13
|
+
|
14
|
+
def content
|
15
|
+
File.read(@path)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
before(:each) do
|
21
|
+
create_directory layout_directory
|
22
|
+
end
|
23
|
+
|
24
|
+
it "takes a path to look for layouts" do
|
25
|
+
LayoutStorageManager.new(layout_directory)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "finds a specific template" do
|
29
|
+
file1 = 'layouts/new_layout1.layout'
|
30
|
+
file2 = 'layouts/new_layout2.layout'
|
31
|
+
|
32
|
+
create_file file1, "I'm content1"
|
33
|
+
create_file file2, "I'm content2"
|
34
|
+
|
35
|
+
mgr = LayoutStorageManager.new(layout_directory, layout_file_klass)
|
36
|
+
layout_file = File.join(working_directory, file1)
|
37
|
+
|
38
|
+
layout = mgr.retrieve(layout_file)
|
39
|
+
expect(layout.path).to eq(layout_file)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "finds a specific template" do
|
43
|
+
file1 = 'layouts/new_layout1.layout'
|
44
|
+
file2 = 'layouts/new_layout2.layout'
|
45
|
+
file3 = 'layouts/new_layout3.layout'
|
46
|
+
|
47
|
+
create_file file1, "I'm content1"
|
48
|
+
create_file file2, "I'm content2"
|
49
|
+
create_file file3, "I'm content3"
|
50
|
+
|
51
|
+
mgr = LayoutStorageManager.new(layout_directory, layout_file_klass)
|
52
|
+
layout_file = File.join(working_directory, file1)
|
53
|
+
|
54
|
+
layouts = mgr.retrieve_all
|
55
|
+
expect(layouts.first.respond_to?(:content)).to eq(true)
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Tree do
|
4
|
+
before(:each) do
|
5
|
+
@tree = LayoutTree.new('root_node')
|
6
|
+
end
|
7
|
+
|
8
|
+
it "takes a root node" do
|
9
|
+
LayoutTree.new('root_node')
|
10
|
+
end
|
11
|
+
|
12
|
+
it "adds a child node" do
|
13
|
+
@tree.add_node('child_node')
|
14
|
+
|
15
|
+
expect(@tree.tree.size).to eq(2)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "is possible to serialize the whole tree (default action)" do
|
19
|
+
test_node = 'child_node'
|
20
|
+
|
21
|
+
@tree.add_node(test_node)
|
22
|
+
@tree.add_node('child_node')
|
23
|
+
@tree.add_node('child_node')
|
24
|
+
@tree.add_node('child_node')
|
25
|
+
|
26
|
+
serialized_tree = @tree.serialize
|
27
|
+
|
28
|
+
expect(serialized_tree[1]).to eq(test_node)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "is possible to serialize the whole tree (customized action)" do
|
32
|
+
test_node = 'child_node'
|
33
|
+
|
34
|
+
@tree.add_node(test_node)
|
35
|
+
@tree.add_node('child_node')
|
36
|
+
@tree.add_node('child_node')
|
37
|
+
@tree.add_node('child_node')
|
38
|
+
|
39
|
+
serialized_tree = @tree.serialize do |node|
|
40
|
+
node.content
|
41
|
+
end
|
42
|
+
|
43
|
+
expect(serialized_tree[1]).to eq(test_node)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "is possible to set the active node" do
|
47
|
+
test_node = 'child_node'
|
48
|
+
|
49
|
+
@tree.add_node(test_node)
|
50
|
+
@tree.up
|
51
|
+
@tree.add_node('child_node')
|
52
|
+
@tree.up
|
53
|
+
@tree.add_node('child_node')
|
54
|
+
|
55
|
+
check = <<-EOF
|
56
|
+
* node0
|
57
|
+
|---> node1
|
58
|
+
|---> node2
|
59
|
+
+---> node3
|
60
|
+
EOF
|
61
|
+
result = capture(:stdout) do
|
62
|
+
@tree.tree.print_tree
|
63
|
+
end
|
64
|
+
expect(result).to eq(check)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "returns the active node in tree" do
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|