Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
collect NotImplementedErrors in AllExpectations. fixes #298
Conflicts: common/src/main/scala/org/specs2/execute/ResultExecution.scala core/src/main/scala/org/specs2/specification/ResultsContext.scala core/src/main/scala/org/specs2/specification/process/Stats.scala core/src/test/scala/org/specs2/specification/AllExpectationsSpec.scala junit/src/main/scala/org/specs2/matcher/JUnitExpectations.scala junit/src/main/scala/org/specs2/reporter/JUnitReporter.scala matcher/src/main/scala/org/specs2/matcher/MatchResult.scala matcher/src/main/scala/org/specs2/matcher/Matcher.scala matcher/src/main/scala/org/specs2/matcher/StandardMatchResults.scala
- Loading branch information
1 parent
ce5af0e
commit 9a02e38
Showing
16 changed files
with
250 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
core/src/main/scala/org/specs2/specification/ResultsContext.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.specs2 | ||
package specification | ||
|
||
import org.specs2.execute.{Success, ResultExecution, AsResult, Result} | ||
import execute.Result._ | ||
import matcher.StoredExpectations | ||
|
||
/** | ||
* This class is used to evaluate a Context as a sequence of results by side-effects. | ||
* | ||
* @see the AllExpectations trait for its use | ||
*/ | ||
class ResultsContext(results: =>Seq[Result]) extends StoredResultsContext { | ||
def storedResults = results | ||
} | ||
|
||
/** | ||
* This trait can be used when it is not desirable to use the AllExpectations trait, that is, when the specification | ||
* examples must be executed concurrently and not isolated. | ||
* | ||
* @see the UserGuide on how to use this trait | ||
*/ | ||
trait StoredExpectationsContext extends StoredExpectations with StoredResultsContext | ||
|
||
/** | ||
* This trait is a context which will use the results provided by the class inheriting that trait. | ||
* It evaluates the result of an example, which is supposed to create side-effects | ||
* and returns the 'storedResults' as the summary of all results | ||
*/ | ||
trait StoredResultsContext extends Context { this: { def storedResults: Seq[Result]} => | ||
def apply[T : AsResult](r: =>T): Result = { | ||
// evaluate r, triggering side effects | ||
val asResult = AsResult(r) | ||
val results = storedResults | ||
// if the execution returns an Error or a Failure that was created for a thrown | ||
// exception, like a JUnit assertion error or a NotImplementedError | ||
// then add the result as a new issue | ||
if (asResult.isError || asResult.isThrownFailure) issues(results :+ asResult, "\n") | ||
else issues(results, "\n") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
core/src/test/scala/org/specs2/specification/AllExpectationsSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package org.specs2 | ||
package specification | ||
|
||
import _root_.org.specs2.mutable.{Specification => Spec} | ||
import org.specs2.data.Fold | ||
import org.specs2.execute.Result | ||
import org.specs2.main.Arguments | ||
import org.specs2.specification.core.{Env, ContextualSpecificationStructure, SpecificationStructure} | ||
import org.specs2.specification.process.{DefaultSelector, Statistics, Stats, DefaultExecutor} | ||
import reporter._ | ||
import user.specification._ | ||
|
||
class AllExpectationsSpec extends Spec with AllExpectations { | ||
|
||
"A specification with the AllExpectations trait should" >> { | ||
"evaluate all its expectations" >> { | ||
executed.hasIssues must beTrue | ||
executed.expectations === 10 | ||
executed.examples === 4 | ||
executed.failures === 4 | ||
executedIssues.head.message === "'1' is not equal to '2' [AllExpectationsSpecification.scala:8]\n"+ | ||
"'1' is not equal to '3' [AllExpectationsSpecification.scala:9]" | ||
} | ||
"short-circuit the rest of the example if an expectation fails and uses 'orThrow'" >> { | ||
executedIssues.map(_.message).toList must containMatch("'51' is not equal to '52'") | ||
executedIssues.map(_.message) must not containMatch("'13' is not equal to '14'") | ||
} | ||
"short-circuit the rest of the example if an expectation fails and uses 'orSkip'" >> { | ||
executedSuspended.map(_.message).toList must not containMatch("'51' is not equal to '52'") | ||
executedIssues.map(_.message) must not containMatch("'15' is not equal to '16'") | ||
} | ||
"work ok on a specification with selected fragments" >> { | ||
executedSelected.hasIssues must beTrue | ||
executedSelected.expectations === 4 | ||
executedSelected.failures === 2 | ||
} | ||
"work ok on a sequential specification" >> { | ||
executedSequential.hasIssues must beTrue | ||
executedSequential.expectations === 10 | ||
executedSequential.failures === 4 | ||
} | ||
"work ok on a mutable specification with Scopes" >> { | ||
executedWithScope.hasIssues must beTrue | ||
executedWithScope.expectations === 3 | ||
executedWithScope.failures === 1 | ||
executedWithScopeIssues.head.message === "'1' is not equal to '2' [AllExpectationsSpecification.scala:31]\n"+ | ||
"'1' is not equal to '3' [AllExpectationsSpecification.scala:32]" | ||
} | ||
"evaluate an exception" >> { | ||
executedException.hasIssues must beTrue | ||
executedException.expectations === 1 | ||
executedException.examples === 1 | ||
executedException.errors === 1 | ||
} | ||
"evaluate an expression which is not implemented yet" >> { | ||
executedWithNotImplementedError.hasIssues must beTrue | ||
executedWithNotImplementedError.expectations === 2 | ||
executedWithNotImplementedError.examples === 1 | ||
executedWithNotImplementedError.errors === 0 | ||
executedWithNotImplementedError.failures === 1 | ||
} | ||
} | ||
|
||
def stats(spec: ContextualSpecificationStructure)(args: Arguments): Stats = { | ||
val env = Env(arguments = args) | ||
try { | ||
val executed = DefaultExecutor.executeSpecWithoutShutdown(spec.structure(env) |> DefaultSelector.select(env), env) | ||
Statistics.runStats(executed) | ||
} | ||
finally env.shutdown | ||
} | ||
|
||
def results(spec: ContextualSpecificationStructure)(args: Arguments): IndexedSeq[Result] = { | ||
val env = Env(arguments = args) | ||
try DefaultExecutor.executeSpecWithoutShutdown(spec.structure(env), env).fragments.fragments.map(_.executionResult) | ||
finally env.shutdown | ||
} | ||
|
||
def issues(spec: ContextualSpecificationStructure)(args: Arguments): IndexedSeq[Result] = | ||
results(spec)(args).filter(r => r.isError || r.isFailure) | ||
|
||
def suspended(spec: ContextualSpecificationStructure)(args: Arguments): IndexedSeq[Result] = | ||
results(spec)(args).filter(r => r.isSkipped || r.isPending) | ||
|
||
def executed = stats(new AllExpectationsSpecification)(args()) | ||
def executedIssues = issues(new AllExpectationsSpecification)(args()) | ||
def executedSuspended = suspended(new AllExpectationsSpecification)(args()) | ||
def executedException = stats(new AllExpectationsSpecificationWithException)(args()) | ||
def executedSelected = stats(new AllExpectationsSpecification)(args(ex = "It is")) | ||
def executedSequential = stats(new AllExpectationsSpecification)(sequential) | ||
def executedWithScope = stats(new AllExpectationsSpecificationWithScope)(args()) | ||
def executedWithScopeIssues = issues(new AllExpectationsSpecificationWithScope)(args()) | ||
def executedWithNotImplementedError = stats(new AllExpectationsSpecificationWithNotImplementedError)(args()) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.