1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
Feature: Expand paths with aruba
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.
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"
Scenario: Using a relative 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 "expands relative to Aruba's home directory" do
expected_path = File.join(aruba.config.home_directory, path)
expect(expand_path(path)).to eq expected_path
end
end
"""
When I run `rspec`
Then the specs should all pass
Scenario: Using a relative path after changing directory using cd
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' }
let(:directory) { 'dir1' }
before do
create_directory directory
end
it "expands relative to the new directory" do
cd directory
expected_path = File.join(aruba.config.home_directory, directory, path)
expect(expand_path(path)).to eq expected_path
end
end
"""
When I run `rspec`
Then the specs should all pass
Scenario: Raise error 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 not all pass
And the output should contain:
"""
Aruba's `expand_path` method was called with an absolute path
"""
Scenario: Silence error about using absolute path
You can use config.allow_absolute_paths to silence the error 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:
"""
Aruba's `expand_path` method was called with an absolute path
"""
Scenario: Raise an error if aruba's working directory does not exist
Given a file named "spec/expand_path_spec.rb" with:
"""ruby
require 'spec_helper'
RSpec.describe 'Expand path', :type => :aruba do
before { remove('.') }
let(:path) { 'path/to/dir' }
it { expect { expand_path(path) }.to raise_error(/working directory does not exist/) }
end
"""
When I run `rspec`
Then the specs should all pass
Scenario: Use ~ in path
Aruba sets HOME to `File.join(aruba.config.root_directory,
aruba.config.working_directory)`. If you want HOME have some other value,
you need to configure it explicitly via `Aruba.configure {}`.
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' }
let(:directory) { 'dir1' }
before do
create_directory(directory)
cd directory
end
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
|