Skip to content

Commit

Permalink
Merge pull request #766 from cucumber/improve-some-scenarios
Browse files Browse the repository at this point in the history
Improve some cucumber scenarios
  • Loading branch information
mvz authored Jan 2, 2021
2 parents eaafd16 + 3896672 commit c78d144
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 80 deletions.
26 changes: 18 additions & 8 deletions features/04_aruba_api/core/expand_path.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,33 @@ 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.
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: Use relative path
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 { expect(expand_path(path)).to eq File.join(aruba.config.home_directory, path) }
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: Change directory using cd
Scenario: Using a relative path after changing directory using cd
Given a file named "spec/expand_path_spec.rb" with:
"""ruby
require 'spec_helper'
Expand All @@ -33,10 +39,14 @@ Feature: Expand paths with aruba
before do
create_directory directory
cd directory
end
it { expect(expand_path(path)).to eq File.join(aruba.config.home_directory, directory, path) }
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`
Expand Down
20 changes: 4 additions & 16 deletions features/04_aruba_api/filesystem/check_if_path_is_absolute.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,6 @@ Feature: Check if path is absolute

Use the `#absolute?`-method to check if a path is an absolute path.

```ruby
require 'spec_helper'

RSpec.configure do |config|
config.include Aruba::Api
end

RSpec.describe 'Check if directory or file is absolute' do
let(:path) { '/path/to/file.txt' }

it { expect(absolute?(path)).to be true }
end
```

Background:
Given I use a fixture named "cli-app"

Expand All @@ -24,10 +10,12 @@ Feature: Check if path is absolute
"""ruby
require 'spec_helper'
RSpec.describe 'Check if directory or file is absolute', :type => :aruba do
RSpec.describe 'the absolute? method', :type => :aruba do
let(:path) { '/path/to/file.txt' }
it { expect(absolute?(path)).to be true }
it "returns true for an absolute path" do
expect(absolute?(path)).to be true
end
end
"""
When I run `rspec`
Expand Down
62 changes: 6 additions & 56 deletions features/05_use_rspec_matchers/path/be_an_absolute_path.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,73 +2,23 @@ Feature: Check if path is absolute

If you need to check if a given path is absolute , you can use the
`be_an_absolute_path`-matcher. It doesn't care if the path is a directory or
a path.

```ruby
require 'spec_helper'

RSpec.describe 'Check if path is absolute', :type => :aruba do
let(:path) { 'file.txt' }
before { touch(path) }

it { expect(path).to be_an_absolute_path }
end
```
a file.

Background:
Given I use a fixture named "cli-app"

Scenario: Expect single existing path
Scenario: Checking an absolute path
Given a file named "spec/absolute_path_spec.rb" with:
"""
require 'spec_helper'
RSpec.describe 'Check if path is absolute', :type => :aruba do
RSpec.describe 'an absolute path', :type => :aruba do
let(:path) { '/path/to/file.txt' }
it { expect(path).to be_an_absolute_path }
end
"""
When I run `rspec`
Then the specs should all pass

Scenario: Expect multiple absolute paths
Given a file named "spec/absolute_path_spec.rb" with:
"""
require 'spec_helper'
RSpec.describe 'Check if path is absolute', :type => :aruba do
let(:paths) { %w(/path/to/path1.txt /path/to/path2.txt) }
it { expect(paths).to all be_an_absolute_path }
it "is absolute" do
expect(path).to be_an_absolute_path
end
end
"""
When I run `rspec`
Then the specs should all pass

Scenario: Expect a least one existing path
Given a file named "spec/absolute_path_spec.rb" with:
"""
require 'spec_helper'
RSpec.describe 'Check if path is absolute', :type => :aruba do
let(:paths) { %w(/path/to/path1.txt path2.txt) }
it { expect(paths).to include an_absolute_path }
end
"""
When I run `rspec`
Then the specs should all pass

Scenario: Expect failure on relative path
Given a file named "spec/absolute_path_spec.rb" with:
"""
require 'spec_helper'
RSpec.describe 'Check if path is absolute', :type => :aruba do
let(:paths) { %w(path2.txt) }
it { expect(paths).to be_an_absolute_path }
end
"""
When I run `rspec`
Then the specs should not all pass

0 comments on commit c78d144

Please sign in to comment.