Skip to content

Commit

Permalink
Adding smoke test running command at CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
ciaranmcnulty committed Jan 18, 2015
1 parent f65d8ef commit 34a2808
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 1 deletion.
3 changes: 3 additions & 0 deletions behat.yml.dist
Expand Up @@ -2,5 +2,8 @@ default:
suites:
application:
contexts: [ ApplicationContext, FilesystemContext ]
smoke:
contexts: [ IsolatedProcessContext, FilesystemContext ]
filters: { tags: @smoke }
formatters:
progress: ~
3 changes: 2 additions & 1 deletion composer.json
Expand Up @@ -34,7 +34,8 @@
"behat/behat": "^3.0.11",
"bossa/phpspec2-expect": "~1.0",
"symfony/filesystem": "~2.1",
"phpunit/phpunit": "~4.4"
"symfony/process": "~2.1",
"phpunit/phpunit": "~4.4"
},

"suggest": {
Expand Down
72 changes: 72 additions & 0 deletions features/bootstrap/IsolatedProcessContext.php
@@ -0,0 +1,72 @@
<?php

use Behat\Behat\Tester\Exception\PendingException;
use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;
use PhpSpec\Exception\Example\SkippingException;
use Symfony\Component\Process\Process;

/**
* Defines application features from the specific context.
*/
class IsolatedProcessContext implements Context, SnippetAcceptingContext
{
private $lastOutput;

/**
* @Given I have started describing the :class class
*/
public function iHaveStartedDescribingTheClass($class)
{
$process = new Process($this->buildPhpSpecCmd() . ' describe '. escapeshellarg($class));
$process->run();

expect($process->getExitCode())->toBe(0);
}

/**
* @When I run phpspec and answer :answer when asked if I want to generate the code
*/
public function iRunPhpspecAndAnswerWhenAskedIfIWantToGenerateTheCode($answer)
{
if (!`which expect`) {
throw new SkippingException('Cannot test interactive scripts on this platform');
}

$process = new Process(
"exec expect -c '\n" .
"set timeout 10\n" .
"spawn {$this->buildPhpSpecCmd()} run\n" .
"expect \"Y/n\"\n" .
"sleep 0.1\n" .
"send \"$answer\n\"\n" .
"sleep 0.5\n" .
"interact\n" .
"'"
);

$process->run();

$this->lastOutput = $process->getOutput();

expect($process->getErrorOutput())->toBe(null);
}

/**
* @return string
*/
protected function buildPhpSpecCmd()
{
return escapeshellcmd(__DIR__ . '/../../bin/phpspec');
}

/**
* @Then the tests should be rerun
*/
public function theTestsShouldBeRerun()
{
expect(substr_count($this->lastOutput, 'Y/n'))->toBe(2);
}
}
1 change: 1 addition & 0 deletions features/code_generation/developer_generates_class.feature
Expand Up @@ -3,6 +3,7 @@ Feature: Developer generates a class
I want to automate creating classes
In order to avoid repetitive tasks and interruptions in development flow

@smoke
Scenario: Generating a class
Given I have started describing the "CodeGeneration/ClassExample1/Markdown" class
When I run phpspec and answer "y" when asked if I want to generate the code
Expand Down
1 change: 1 addition & 0 deletions features/code_generation/developer_reruns_features.feature
Expand Up @@ -3,6 +3,7 @@ Feature: Developer generates a class
I want the tests to automatically rerun after code generation events
In order to avoid repetitive tasks and interruptions in development flow

@smoke
Scenario: Rerun after class generation
Given I have started describing the "CodeGeneration/RerunExample1/Markdown" class
When I run phpspec and answer "y" when asked if I want to generate the code
Expand Down

0 comments on commit 34a2808

Please sign in to comment.