File tree Expand file tree Collapse file tree 2 files changed +27
-6
lines changed Expand file tree Collapse file tree 2 files changed +27
-6
lines changed Original file line number Diff line number Diff line change @@ -18,9 +18,7 @@ def view_marker(id = nil)
18
18
# Reads a file from the userspace (Settings.source_dir) and returns
19
19
# its contents. If the file is not found, returns a string with a hint.
20
20
def load_user_file ( file , placeholder : true )
21
- path = "#{ Settings . source_dir } /#{ file } "
22
- ext = ".#{ Settings . partials_extension } "
23
- path += ext unless path . end_with? ext
21
+ path = user_file_path file
24
22
25
23
content = if File . exist? path
26
24
File . read ( path ) . remove_front_matter
@@ -33,6 +31,14 @@ def load_user_file(file, placeholder: true)
33
31
Settings . production? ? content : "#{ view_marker path } \n #{ content } "
34
32
end
35
33
34
+ def user_file_path ( file )
35
+ path = "#{ Settings . source_dir } /#{ file } "
36
+ ext = ".#{ Settings . partials_extension } "
37
+ return path if path . end_with? ext
38
+
39
+ "#{ path } #{ ext } "
40
+ end
41
+
36
42
private
37
43
38
44
def view_path ( view )
Original file line number Diff line number Diff line change 330
330
. to eq "# spec/tmp/src/notfound.sh\n echo \" error: cannot load file\" "
331
331
end
332
332
end
333
+ end
334
+
335
+ describe '#user_file_path' do
336
+ it 'returns the path to the user file' do
337
+ expect ( subject . user_file_path 'test.sh' ) . to eq 'spec/tmp/src/test.sh'
338
+ end
339
+
340
+ context 'when the file argument does not end with .sh extension' do
341
+ it 'returns the path with .sh appended' do
342
+ expect ( subject . user_file_path 'test' ) . to eq 'spec/tmp/src/test.sh'
343
+ end
344
+ end
345
+
346
+ context 'when partials_extension is set and the argument does not end with the selected extension' do
347
+ before { Settings . partials_extension = 'bash' }
348
+ after { Settings . partials_extension = 'sh' }
333
349
334
- context 'when the provided file does not include an extension' do
335
- it 'adds the partials_extension to it' do
336
- expect ( subject . load_user_file ( 'test' ) ) . to eq "# spec/tmp/src/test.sh\n hello Command#load_user_file"
350
+ it 'returns the path with the selected extension appended' do
351
+ expect ( subject . user_file_path 'test' ) . to eq 'spec/tmp/src/test.bash'
337
352
end
338
353
end
339
354
end
You can’t perform that action at this time.
0 commit comments