Skip to content

Commit

Permalink
Fix up tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ergonlogic committed Mar 15, 2016
1 parent e85df13 commit acc4e8b
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 18 deletions.
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ dist: trusty

sudo: false

env:
- BEHAT_TAGS="~@slow"
- BEHAT_TAGS="@slow"

install:
- make behat

script:
- . scripts/hacking.sh
- behat
- behat --tags=BEHAT_TAGS
2 changes: 1 addition & 1 deletion behat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ default:
blackbox: ~
gherkin:
filters:
tags: ~@wip
tags: "~@wip&&~@slow"

45 changes: 30 additions & 15 deletions features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class FeatureContext extends RawDrupalContext implements SnippetAcceptingContext
* context constructor through behat.yml.
*/
public function __construct() {
$this->setOrigDir();
}

/**
Expand All @@ -36,6 +37,16 @@ public function __destruct() {
$this->rmdir($this->tempDir);
}

private function getOrigDir() {
return $this->orig_dir;
}

private function setOrigDir() {
if (!isset($this->orig_dir)) {
$this->orig_dir = getcwd();
}
}

/**
* Run a command in a sub-process, and set its output.
*/
Expand Down Expand Up @@ -76,7 +87,7 @@ private function fail($command) {
* Create a temporary directory
*/
private function makeTempDir() {
$tempfile = tempnam(sys_get_temp_dir(),'behat_cli_');
$tempfile = tempnam(sys_get_temp_dir(), 'behat_cli_');
if (file_exists($tempfile)) {
unlink($tempfile);
}
Expand All @@ -90,8 +101,12 @@ private function makeTempDir() {
private function rmdir($dir) {
if (is_dir($dir)) {
foreach(scandir($dir) as $file) {
if ('.' === $file || '..' === $file) continue;
if (is_dir("$dir/$file")) $this->rmdir("$dir/$file");
if ('.' === $file || '..' === $file) {
continue;
}
if (is_dir("$dir/$file")) {
$this->rmdir("$dir/$file");
}
else unlink("$dir/$file");
}
rmdir($dir);
Expand All @@ -107,6 +122,16 @@ public function setDebugFlag() {
$this->debug = TRUE;
}

/**
* In case we switched to a temporary directory, switch back to the original
* directory before the next scenario.
*
* @AfterScenario
*/
public function returnToOrigDir() {
chdir($this->getOrigDir());
}

/**
* @When I run :command
*/
Expand Down Expand Up @@ -144,26 +169,18 @@ public function iShouldNotGet(PyStringNode $output)
*/
public function iAmInATemporaryDirectory()
{
static $orig_dir;
if (!isset($orig_dir)) {
$orig_dir = getcwd();
}
$this->orig_dir = $orig_dir;
$this->makeTempDir();
chdir($this->tempDir);
}


/**
* Execute a script in our project, even if we've moved to a temporary directory.
*
* @When I execute :script
*/
public function iExecute($script)
{
if (isset($this->orig_dir)) {
$script = $this->orig_dir . DIRECTORY_SEPARATOR . $script;
}
$script = $this->getOrigDir() . DIRECTORY_SEPARATOR . $script;
$this->exec($script);
}

Expand All @@ -172,9 +189,7 @@ public function iExecute($script)
*/
public function executingShouldFail($script)
{
if (isset($this->orig_dir)) {
$script = $this->orig_dir . DIRECTORY_SEPARATOR . $script;
}
$script = $this->getOrigDir() . DIRECTORY_SEPARATOR . $script;
$this->fail($script);
}

Expand Down
2 changes: 1 addition & 1 deletion features/cli_context.feature
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Feature: CLI Context
"""
test.txt
"""
Then I should not get:
And I should not get:
"""
Makefile
"""
1 change: 1 addition & 0 deletions features/install-drush.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Feature: Install Drush locally
As a Drupal developer
I need to be able run Drush

@slow
Scenario: Run 'make drush'
Given I run "make clean-drush"
When I run "make drush"
Expand Down

0 comments on commit acc4e8b

Please sign in to comment.