Skip to content

Commit

Permalink
Document use of absolute paths in expand_path
Browse files Browse the repository at this point in the history
  • Loading branch information
mvz committed Feb 11, 2018
1 parent ca14739 commit 3bc18cc
Showing 1 changed file with 56 additions and 8 deletions.
64 changes: 56 additions & 8 deletions features/04_aruba_api/core/expand_path.feature
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
Feature: Expand paths with aruba

There are quite a few uses cases why you want to expand a path. `aruba` helps
There are quite a few uses cases why you want to expand a path. Aruba helps
you with this by providing you the `expand_path`-method. This method expands
paths relative to the `aruba.current_directory`-directory.
paths relative to the `aruba.current_directory`-directory. Use of absolute
paths is discouraged, since the intent is to only access the isolated Aruba
working directory.

Background:
Given I use the fixture "cli-app"
Expand All @@ -14,7 +16,7 @@ Feature: Expand paths with aruba
RSpec.describe 'Expand path', :type => :aruba do
let(:path) { 'path/to/dir' }
it { expect(expand_path(path)).to eq File.join(aruba.root_directory, aruba.current_directory, path) }
it { expect(expand_path(path)).to eq File.join(aruba.config.home_directory, path) }
end
"""
When I run `rspec`
Expand All @@ -29,15 +31,56 @@ Feature: Expand paths with aruba
let(:path) { 'path/to/dir' }
let(:directory) { 'dir1' }
before(:each) { create_directory(directory) }
before(:each) { cd(directory) }
before do
create_directory directory
cd directory
end
it { expect(expand_path(path)).to eq File.join(aruba.root_directory, aruba.current_directory, path) }
it { expect(expand_path(path)).to eq File.join(aruba.config.home_directory, directory, path) }
end
"""
When I run `rspec`
Then the specs should all pass

Scenario: Warn when using absolute path
Given a file named "spec/expand_path_spec.rb" with:
"""ruby
require 'spec_helper'
RSpec.describe 'Expand path', :type => :aruba do
let(:path) { '/path/to/dir' }
it { expect(expand_path(path)).to eq path }
end
"""
When I run `rspec`
Then the specs should all pass
And the output should contain:
"""
Using absolute paths in Aruba is not recommended
"""

Scenario: Silence warning about using absolute path

You can use config.allow_absolute_paths to silence the warning about the
use of absolute paths.

Given a file named "spec/expand_path_spec.rb" with:
"""ruby
require 'spec_helper'
RSpec.describe 'Expand path', :type => :aruba do
let(:path) { '/path/to/dir' }
before { aruba.config.allow_absolute_paths = true }
it { expect(expand_path(path)).to eq path }
end
"""
When I run `rspec`
Then the specs should all pass
And the output should not contain:
"""
Using absolute paths in Aruba is not recommended
"""

Scenario: Raise an error if aruba's working directory does not exist
Given a file named "spec/expand_path_spec.rb" with:
"""ruby
Expand Down Expand Up @@ -66,10 +109,15 @@ Feature: Expand paths with aruba
RSpec.describe 'Expand path', :type => :aruba do
let(:path) { '~/path/to/dir' }
let(:directory) { 'dir1' }
before do
create_directory(directory)
cd directory
end
it { expect(expand_path(path)).to eq File.join(aruba.config.root_directory, aruba.config.working_directory, 'path/to/dir') }
it { expect(expand_path(path)).to eq File.join(aruba.config.home_directory, 'path/to/dir') }
end
"""
When I run `rspec`
Then the specs should all pass

0 comments on commit 3bc18cc

Please sign in to comment.