Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix @no-clobber behavior #535

Merged
merged 3 commits into from
Feb 2, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,61 +8,48 @@ Feature: Cleanup Aruba Working Directory
Background:
Given I use a fixture named "cli-app"

Scenario: Changes in the filesystem

This assumes you use the default configuration, having `tmp/aruba` as your
default working directory in your project root.

Given a file named "tmp/aruba/file.txt" with "content"
And a directory named "tmp/aruba/dir.d"
And a file named "features/flushing.feature" with:
Scenario: Clean up artifacts and pwd from a previous scenario
Given a file named "features/cleanup.feature" with:
"""
Feature: Check
Scenario: Check
Then a file named "file.txt" does not exist
And a directory named "dir.d" does not exist
Scenario: Check #1
Given a file named "file.txt" with "content"
And a directory named "dir.d"
Then a file named "file.txt" should exist
And a directory named "dir.d" should exist
When I cd to "dir.d"
And I run `pwd`
Then the output should match %r</tmp/aruba/dir.d$>

Scenario: Check #2
Then a file named "file.txt" should not exist
And a directory named "dir.d" should not exist
When I run `pwd`
Then the output should match %r</tmp/aruba$>
"""
When I run `cucumber`
Then the features should all pass

Scenario: Do not clobber before run
The `@no-clobber` tag stops Aruba from clearing out its scratch directory.
Other setup steps are still performed, such as setting the current working
directory.

Given a file named "tmp/aruba/file.txt" with "content"
And a directory named "tmp/aruba/dir.d"
And a file named "features/flushing.feature" with:
And a file named "features/cleanup.feature" with:
"""
Feature: Check
@no-clobber
Scenario: Check
Scenario: Check #1
Given a file named "file.txt" with "content"
And a directory named "dir.d"
Then a file named "file.txt" should exist
And a directory named "dir.d" should exist
"""
When I run `cucumber`
Then the features should all pass

Scenario: Cleanup and verify the previous scenario
Given a file named "features/flushing.feature" with:
"""
Feature: Check
Scenario: Check #1
Given a file named "tmp/aruba/file.txt" with "content"
And a directory named "tmp/aruba/dir.d"

@no-clobber
Scenario: Check #2
Then a file named "file.txt" should not exist
And a directory named "dir.d" should not exist
"""
When I run `cucumber`
Then the features should all pass

Scenario: Current directory from previous scenario is reseted
Given a file named "features/non-existence.feature" with:
"""
Feature: Reset
Scenario: Reset #1
Given a directory named "dir1"
When I cd to "dir1"

Scenario: Reset #2
Then a file named "file.txt" should exist
And a directory named "dir.d" should exist
When I run `pwd`
Then the output should match %r</tmp/aruba$>
"""
Expand Down
4 changes: 2 additions & 2 deletions lib/aruba/api/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def aruba
# This will only clean up aruba's working directory to remove all
# artifacts of your tests. This does NOT clean up the current working
# directory.
def setup_aruba
Aruba::Setup.new(aruba).call
def setup_aruba(clobber: true)
Aruba::Setup.new(aruba).call(clobber: clobber)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This syntax is the incompatible one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but it should be fine on master since we dropped support for 1.8.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah bummer, I forgot this won't work with 1.9 either 😞


self
end
Expand Down
4 changes: 4 additions & 0 deletions lib/aruba/cucumber/hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
aruba.command_monitor.clear
end

Before('@no-clobber') do
setup_aruba(clobber: false)
end

Before('~@no-clobber') do
setup_aruba
end
Expand Down
10 changes: 6 additions & 4 deletions lib/aruba/setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ def initialize(runtime)
@runtime = runtime
end

def call
def call(clobber: true)
return if runtime.setup_already_done?

working_directory
working_directory(clobber: clobber)
events

runtime.setup_done
Expand All @@ -23,8 +23,10 @@ def call

private

def working_directory
Aruba.platform.rm File.join(runtime.config.root_directory, runtime.config.working_directory), :force => true
def working_directory(clobber: true)
if clobber
Aruba.platform.rm File.join(runtime.config.root_directory, runtime.config.working_directory), :force => true
end
Aruba.platform.mkdir File.join(runtime.config.root_directory, runtime.config.working_directory)
Aruba.platform.chdir runtime.config.root_directory
end
Expand Down