Skip to content

Commit

Permalink
Merge pull request #535 from cucumber/issue-527-fix-no-clobber
Browse files Browse the repository at this point in the history
Fix @no-clobber behavior
  • Loading branch information
mvz authored Feb 2, 2018
2 parents 3c4b463 + 1f933b0 commit f134e1f
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 46 deletions.
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)

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(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)
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

0 comments on commit f134e1f

Please sign in to comment.