Skip to content

Commit

Permalink
Updated focused specs PR to address review feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
ezzatron committed Nov 27, 2016
1 parent 4463441 commit 5108a03
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
2 changes: 1 addition & 1 deletion specs/suite.spec.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@
it('should return true even if nested tests are not focused', function() {
$test = new Test("test", function() {});
$this->suite->addTest($test);
assert($this->suite->getFocused(), "suite should not be focused");
assert($this->suite->getFocused(), "suite should be focused");
});
});

Expand Down
33 changes: 16 additions & 17 deletions src/Core/Suite.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,17 @@ class Suite extends AbstractTest
*/
public function getFocused()
{
if ($this->focused === true) {
return $this->focused;
}

foreach ($this->tests as $test) {
if ($test->getFocused()) {
return true;
}
}

return $this->focused;
return false;
}

/**
Expand Down Expand Up @@ -90,7 +94,7 @@ public function run(TestResult $result)
$this->eventEmitter->emit('suite.start', [$this]);
$this->eventEmitter->on('suite.halt', [$this, 'halt']);

foreach ($this->focusedTests() as $test) {
foreach ($this->getTestsToRun() as $test) {
if ($this->halted) {
break;
}
Expand Down Expand Up @@ -128,22 +132,17 @@ protected function runTest(TestInterface $test, TestResult $result)
$test->run($result);
}

private function focusedTests()
/**
* Get the subset of the defined tests that should actually be run.
*
* @return array
*/
protected function getTestsToRun()
{
$tests = [];
$hasFocusedTests = false;

foreach ($this->tests as $test) {
if ($test->getFocused()) {
$hasFocusedTests = true;
$tests[] = $test;
}
}
$tests = array_filter($this->tests, function (TestInterface $test) {
return $test->getFocused();
});

if ($hasFocusedTests) {
return $tests;
}

return $this->tests;
return empty($tests) ? $this->tests : $tests;
}
}
2 changes: 1 addition & 1 deletion src/Dsl.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function describe($description, callable $fn)
*/
function context($description, callable $fn)
{
Context::getInstance()->addSuite($description, $fn);
describe($description, $fn);
}

/**
Expand Down

0 comments on commit 5108a03

Please sign in to comment.