Skip to content

Commit 6726788

Browse files
committed
Merge pull request #1 from hungryzi/master
Bubble up exceptions when no throws is defined
2 parents 6c085ad + d69e96d commit 6726788

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

src/Codeception/Specify.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,13 @@ private function specifyExecute($test, $throws = false, $examples = array())
8181
} catch (\PHPUnit_Framework_AssertionFailedError $e) {
8282
if ($throws !== get_class($e)) $result->addFailure(clone($this), $e, $result->time());
8383
} catch (\Exception $e) {
84-
if ($throws and ($throws !== get_class($e))) {
85-
$f = new \PHPUnit_Framework_AssertionFailedError("exception '$throws' was expected, but " . get_class($e) . ' was thrown');
86-
$result->addFailure(clone($this), $f, $result->time());
84+
if ($throws) {
85+
if ($throws !== get_class($e)) {
86+
$f = new \PHPUnit_Framework_AssertionFailedError("exception '$throws' was expected, but " . get_class($e) . ' was thrown');
87+
$result->addFailure(clone($this), $f, $result->time());
88+
}
89+
} else {
90+
throw $e;
8791
}
8892
}
8993

tests/SpecifyTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ public function testExceptions()
7676
}, ['throws' => 'fail']);
7777
}
7878

79+
/**
80+
* @expectedException RuntimeException
81+
*/
82+
public function testFailWhenUnexpectedExceptionHappens()
83+
{
84+
$this->specify('i bubble exception up if no throws is defined', function() {
85+
throw new RuntimeException;
86+
});
87+
}
88+
7989
public function testExamples()
8090
{
8191
$this->specify('specify may contain examples', function($a, $b) {

0 commit comments

Comments
 (0)