Skip to content

Commit

Permalink
Merge pull request #389 from BBC-News/issue369
Browse files Browse the repository at this point in the history
fix #369
  • Loading branch information
ChrisBAshton committed Feb 28, 2016
2 parents c0d5107 + 7d51033 commit 7b70901
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/wraith/helpers/utilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
31 changes: 31 additions & 0 deletions spec/helper_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 7b70901

Please sign in to comment.