diff --git a/lib/wraith/helpers/utilities.rb b/lib/wraith/helpers/utilities.rb index 767e98ac..e98e1aa0 100644 --- a/lib/wraith/helpers/utilities.rb +++ b/lib/wraith/helpers/utilities.rb @@ -6,6 +6,9 @@ def convert_to_absolute(filepath) elsif filepath[0] == "/" # filepath is already absolute. return unchanged filepath + elsif filepath.match(/^[A-Z]:\/(.+)$/) + # filepath is an absolute Windows path, e.g. C:/Code/Wraith/javascript/global.js. return unchanged + filepath else # filepath is relative. it must be converted to absolute "#{Dir.pwd}/#{filepath}" diff --git a/spec/helper_spec.rb b/spec/helper_spec.rb new file mode 100644 index 00000000..20566862 --- /dev/null +++ b/spec/helper_spec.rb @@ -0,0 +1,31 @@ +require "_helpers" + +describe "Wraith helpers classes and functions" do + + describe "the convert_to_absolute function" do + it "should return false if no filepath provided" do + expect(convert_to_absolute(nil)).to eq 'false' + end + + it "should convert a relative path to absolute" do + relative = 'my/filepath' + absolute = convert_to_absolute relative + expect(absolute[0]).to eq '/' + expect(absolute.length).to be > relative.length + expect(absolute).to match(/\/(.+)\/(.+)\/my\/filepath/) + end + + it "should leave an absolute path unchanged" do + relative = '/my/filepath' + absolute = convert_to_absolute relative + expect(absolute).to eq relative + end + + it "should leave a Windows-flavoured absolute path unchanged" do + relative = 'C:/Code/Wraith/javascript/global.js' + absolute = convert_to_absolute relative + expect(absolute).to eq relative + end + end + +end