- Revision
- 736
- Author
- sirenian
- Date
- 2007-05-28 14:54:06 -0500 (Mon, 28 May 2007)
Log Message
[EK] Made it possible to override run() in a story and throw a PendingException without failing a build
Modified Paths
Diff
Modified: trunk/core/src/behaviour/org/jbehave/core/story/StoryRunnerBehaviour.java (735 => 736)
--- trunk/core/src/behaviour/org/jbehave/core/story/StoryRunnerBehaviour.java 2007-05-24 18:02:00 UTC (rev 735) +++ trunk/core/src/behaviour/org/jbehave/core/story/StoryRunnerBehaviour.java 2007-05-28 19:54:06 UTC (rev 736) @@ -3,16 +3,16 @@ import java.io.ByteArrayOutputStream; import java.io.PrintStream; +import org.jbehave.core.Block; import org.jbehave.core.Ensure; +import org.jbehave.core.exception.PendingException; import org.jbehave.core.listener.BehaviourListener; import org.jbehave.core.minimock.UsingMiniMock; import org.jbehave.core.mock.Mock; import org.jbehave.core.story.domain.Narrative; import org.jbehave.core.story.domain.Story; -import org.jbehave.core.story.domain.World; import org.jbehave.core.story.listener.PlainTextScenarioListener; import org.jbehave.core.story.renderer.Renderer; -import org.jbehave.core.story.result.ScenarioResult; public class StoryRunnerBehaviour extends UsingMiniMock { @@ -29,17 +29,31 @@ verifyMocks(); } + + public void shouldOutputPendingExeptionsWithoutFailingTheStory() throws Exception { + final ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + final PrintStream stream = new PrintStream(buffer); + + Exception exception = runAndCatch(Exception.class, new Block() { + public void run() throws Exception { + new StoryRunner().run(PendingStory.class.getName(), stream); + } + }); + + Ensure.that(exception, isNull()); + Ensure.that(buffer.toString(), contains("P")); + Ensure.that(buffer.toString(), contains("Total: 1. Pending: 1.")); + + verifyMocks(); + } - public static class MyStory extends UsingMiniMock implements Story { + public static class PendingStory extends UsingMiniMock implements Story { private Mock mock; - public MyStory() { - ScenarioResult resultA = new ScenarioResult("scenarioA", "MyStory", ScenarioResult.SUCCEEDED); - ScenarioResult resultB = new ScenarioResult("scenarioB", "MyStory", ScenarioResult.SUCCEEDED); - + public PendingStory() { mock = mock(Story.class); mock.expects("addListener").with(isA(PlainTextScenarioListener.class)); - mock.expects("run").with(a(World.class)).will(returnValue(new ScenarioResult[] {resultA, resultB})); + mock.expects("run").will(throwException(new PendingException("TODO"))); } public Narrative narrative() {
Modified: trunk/core/src/java/org/jbehave/core/story/StoryRunner.java (735 => 736)
--- trunk/core/src/java/org/jbehave/core/story/StoryRunner.java 2007-05-24 18:02:00 UTC (rev 735) +++ trunk/core/src/java/org/jbehave/core/story/StoryRunner.java 2007-05-28 19:54:06 UTC (rev 736) @@ -9,8 +9,11 @@ import java.io.OutputStreamWriter; import java.io.PrintStream; +import org.jbehave.core.exception.PendingException; +import org.jbehave.core.result.Result; import org.jbehave.core.story.domain.Story; import org.jbehave.core.story.listener.PlainTextScenarioListener; +import org.jbehave.core.util.CamelCaseConverter; @@ -46,7 +49,14 @@ public void run(Story story, PrintStream printStream) { PlainTextScenarioListener listener = new PlainTextScenarioListener(new OutputStreamWriter(printStream)); story.addListener(listener); - story.run(); + try { + story.run(); + } catch (PendingException pe) { + listener.gotResult( + new Result("", + new CamelCaseConverter(story.getClass()).toPhrase(), + pe)); + } listener.printReport(); succeeded = succeeded && !listener.hasBehaviourFailures(); }
To unsubscribe from this list please visit:
