- Revision
- 1385
- Author
- mauro
- Date
- 2009-11-05 16:53:00 -0600 (Thu, 05 Nov 2009)
Log Message
JBEHAVE-204: Added flag for embbeded mode in scenario runner, so that before and after story events are reported only once when running given scenarios.
Modified Paths
- trunk/core/jbehave-core/src/behaviour/org/jbehave/scenario/ScenarioBehaviour.java
- trunk/core/jbehave-core/src/behaviour/org/jbehave/scenario/ScenarioRunnerBehaviour.java
- trunk/core/jbehave-core/src/java/org/jbehave/scenario/AbstractScenario.java
- trunk/core/jbehave-core/src/java/org/jbehave/scenario/ScenarioRunner.java
- trunk/core/jbehave-core/src/java/org/jbehave/scenario/definition/StoryDefinition.java
Diff
Modified: trunk/core/jbehave-core/src/behaviour/org/jbehave/scenario/ScenarioBehaviour.java (1384 => 1385)
--- trunk/core/jbehave-core/src/behaviour/org/jbehave/scenario/ScenarioBehaviour.java 2009-11-05 12:46:44 UTC (rev 1384) +++ trunk/core/jbehave-core/src/behaviour/org/jbehave/scenario/ScenarioBehaviour.java 2009-11-05 22:53:00 UTC (rev 1385) @@ -1,74 +1,41 @@ package org.jbehave.scenario; -import static java.util.Collections.EMPTY_LIST; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.stub; import static org.mockito.Mockito.verify; -import org.jbehave.scenario.definition.Blurb; -import org.jbehave.scenario.definition.KeyWords; import org.jbehave.scenario.definition.StoryDefinition; -import org.jbehave.scenario.errors.ErrorStrategy; -import org.jbehave.scenario.errors.PendingErrorStrategy; import org.jbehave.scenario.parser.ScenarioDefiner; -import org.jbehave.scenario.reporters.ScenarioReporter; -import org.jbehave.scenario.reporters.StepdocReporter; import org.jbehave.scenario.steps.CandidateSteps; -import org.jbehave.scenario.steps.StepCreator; -import org.jbehave.scenario.steps.StepdocGenerator; -import org.jbehave.scenario.steps.Steps; import org.junit.Test; - -/** - * The example code bases provide the only examples of the whole of JBehave running. - */ public class ScenarioBehaviour { - @SuppressWarnings("unchecked") @Test public void shouldLoadStoryDefinitionAndRunUsingTheScenarioRunner() throws Throwable { + // Given ScenarioRunner runner = mock(ScenarioRunner.class); - MockedConfiguration configuration = new MockedConfiguration(); - CandidateSteps steps = mock(Steps.class); + ScenarioDefiner scenarioDefiner = mock(ScenarioDefiner.class); + Configuration configuration = mock(Configuration.class); + CandidateSteps steps = mock(CandidateSteps.class); + StoryDefinition storyDefinition = new StoryDefinition(); + stub(configuration.forDefiningScenarios()).toReturn(scenarioDefiner); + stub(scenarioDefiner.loadScenarioDefinitionsFor(MyScenario.class)).toReturn(storyDefinition); + + // When RunnableScenario scenario = new MyScenario(runner, configuration, steps); - - StoryDefinition storyDefinition = new StoryDefinition(Blurb.EMPTY, EMPTY_LIST); - stub(configuration.scenarioDefiner.loadScenarioDefinitionsFor(MyScenario.class)).toReturn(storyDefinition); - scenario.runScenario(); - - verify(runner).run(storyDefinition, configuration, steps); + + // Then + verify(runner).run(storyDefinition, configuration, false, steps); } private class MyScenario extends JUnitScenario { - public MyScenario(ScenarioRunner runner, - MockedConfiguration configuration, CandidateSteps steps) { + public MyScenario(ScenarioRunner runner, Configuration configuration, CandidateSteps steps) { super(runner, configuration, steps); } } - private static class MockedConfiguration implements Configuration { - - private ScenarioDefiner scenarioDefiner = mock(ScenarioDefiner.class); - - public StepCreator forCreatingSteps() { return null; } - - public ScenarioDefiner forDefiningScenarios() { return scenarioDefiner; } - - public ErrorStrategy forHandlingErrors() { return null; } - - public PendingErrorStrategy forPendingSteps() { return null; } - - public ScenarioReporter forReportingScenarios() { return null; } - - public KeyWords keywords() { return null; } - - public StepdocGenerator forGeneratingStepdoc() { return null; } - - public StepdocReporter forReportingStepdoc() { return null; } - - } }
Modified: trunk/core/jbehave-core/src/behaviour/org/jbehave/scenario/ScenarioRunnerBehaviour.java (1384 => 1385)
--- trunk/core/jbehave-core/src/behaviour/org/jbehave/scenario/ScenarioRunnerBehaviour.java 2009-11-05 12:46:44 UTC (rev 1384) +++ trunk/core/jbehave-core/src/behaviour/org/jbehave/scenario/ScenarioRunnerBehaviour.java 2009-11-05 22:53:00 UTC (rev 1385) @@ -32,29 +32,28 @@ import org.mockito.InOrder; public class ScenarioRunnerBehaviour { - + private Map<String, String> tableRow = new HashMap<String, String>(); - - @Test + + @Test public void shouldRunStepsInScenariosAndReportResultsToReporter() throws Throwable { - ScenarioDefinition scenarioDefinition1 = new ScenarioDefinition("my title 1", asList("failingStep", "successfulStep")); + // Given + ScenarioDefinition scenarioDefinition1 = new ScenarioDefinition("my title 1", asList("failingStep", + "successfulStep")); ScenarioDefinition scenarioDefinition2 = new ScenarioDefinition("my title 2", asList("successfulStep")); - ScenarioDefinition scenarioDefinition3 = new ScenarioDefinition("my title 3", asList("successfulStep", "pendingStep")); - StoryDefinition storyDefinition = new StoryDefinition(new Blurb("my blurb"), scenarioDefinition1, scenarioDefinition2, scenarioDefinition3); - - // Given + ScenarioDefinition scenarioDefinition3 = new ScenarioDefinition("my title 3", asList("successfulStep", + "pendingStep")); + StoryDefinition storyDefinition = new StoryDefinition(new Blurb("my blurb"), scenarioDefinition1, + scenarioDefinition2, scenarioDefinition3); CandidateStep[] someCandidateSteps = new CandidateStep[0]; Step step = mock(Step.class); StepResult result = mock(StepResult.class); stub(step.perform()).toReturn(result); - ScenarioReporter reporter = mock(ScenarioReporter.class); StepCreator creator = mock(StepCreator.class); CandidateSteps mySteps = mock(Steps.class); - stub(mySteps.getSteps()).toReturn(someCandidateSteps); IllegalArgumentException anException = new IllegalArgumentException(); - Step pendingStep = mock(Step.class); Step successfulStep = mock(Step.class); Step failingStep = mock(Step.class); @@ -62,16 +61,18 @@ stub(successfulStep.perform()).toReturn(StepResult.success("successfulStep")); stub(successfulStep.doNotPerform()).toReturn(StepResult.notPerformed("successfulStep")); stub(failingStep.perform()).toReturn(StepResult.failure("failingStep", anException)); + stub(creator.createStepsFrom(scenarioDefinition1, tableRow, mySteps)).toReturn( + new Step[] { failingStep, successfulStep }); + stub(creator.createStepsFrom(scenarioDefinition2, tableRow, mySteps)).toReturn(new Step[] { successfulStep }); + stub(creator.createStepsFrom(scenarioDefinition3, tableRow, mySteps)).toReturn( + new Step[] { successfulStep, pendingStep }); - stub(creator.createStepsFrom(scenarioDefinition1, tableRow, mySteps)).toReturn(new Step[] {failingStep, successfulStep}); - stub(creator.createStepsFrom(scenarioDefinition2, tableRow, mySteps)).toReturn(new Step[] {successfulStep}); - stub(creator.createStepsFrom(scenarioDefinition3, tableRow, mySteps)).toReturn(new Step[] {successfulStep, pendingStep}); - + // When ErrorStrategy errorStrategy = mock(ErrorStrategy.class); ScenarioRunner runner = new ScenarioRunner(); - - runner.run(storyDefinition, configurationWith(reporter, creator, errorStrategy), mySteps); - + runner.run(storyDefinition, configurationWith(reporter, creator, errorStrategy), false, mySteps); + + // Then InOrder inOrder = inOrder(reporter, errorStrategy); inOrder.verify(reporter).beforeStory(storyDefinition.getBlurb()); inOrder.verify(reporter).beforeScenario("my title 1"); @@ -88,17 +89,17 @@ inOrder.verify(reporter).afterStory(); inOrder.verify(errorStrategy).handleError(anException); } - - - @Test + + @Test public void shouldRunGivenScenariosBeforeSteps() throws Throwable { + // Given ScenarioDefinition scenarioDefinition1 = new ScenarioDefinition("scenario 1", asList("successfulStep")); List<String> givenScenarios = asList("/path/to/given/scenario1"); - ScenarioDefinition scenarioDefinition2 = new ScenarioDefinition("scenario 2", givenScenarios, asList("anotherSuccessfulStep")); + ScenarioDefinition scenarioDefinition2 = new ScenarioDefinition("scenario 2", givenScenarios, + asList("anotherSuccessfulStep")); StoryDefinition storyDefinition1 = new StoryDefinition(new Blurb("story 1"), scenarioDefinition1); StoryDefinition storyDefinition2 = new StoryDefinition(new Blurb("story 2"), scenarioDefinition2); - - // Given + CandidateStep[] someCandidateSteps = new CandidateStep[0]; Step step = mock(Step.class); StepResult result = mock(StepResult.class); @@ -107,32 +108,33 @@ ScenarioDefiner scenarioDefiner = mock(ScenarioDefiner.class); ScenarioReporter reporter = mock(ScenarioReporter.class); StepCreator creator = mock(StepCreator.class); - CandidateSteps mySteps = mock(Steps.class); + CandidateSteps mySteps = mock(Steps.class); stub(mySteps.getSteps()).toReturn(someCandidateSteps); Step successfulStep = mock(Step.class); stub(successfulStep.perform()).toReturn(StepResult.success("successfulStep")); Step anotherSuccessfulStep = mock(Step.class); stub(anotherSuccessfulStep.perform()).toReturn(StepResult.success("anotherSuccessfulStep")); - - stub(creator.createStepsFrom(scenarioDefinition1, tableRow, mySteps)).toReturn(new Step[] {successfulStep}); - stub(creator.createStepsFrom(scenarioDefinition2, tableRow, mySteps)).toReturn(new Step[] {anotherSuccessfulStep}); - + stub(creator.createStepsFrom(scenarioDefinition1, tableRow, mySteps)).toReturn(new Step[] { successfulStep }); + stub(creator.createStepsFrom(scenarioDefinition2, tableRow, mySteps)).toReturn( + new Step[] { anotherSuccessfulStep }); stub(scenarioDefiner.loadScenarioDefinitionsFor("/path/to/given/scenario1")).toReturn(storyDefinition1); - ErrorStrategy errorStrategy = mock(ErrorStrategy.class); + // When ScenarioRunner runner = new ScenarioRunner(); - - runner.run(storyDefinition2, configurationWith(scenarioDefiner, reporter, creator, errorStrategy), mySteps); - + runner.run(storyDefinition2, configurationWith(scenarioDefiner, reporter, creator, errorStrategy), false, + mySteps); + + // Then InOrder inOrder = inOrder(reporter); inOrder.verify(reporter).beforeStory(storyDefinition2.getBlurb()); inOrder.verify(reporter).givenScenarios(givenScenarios); inOrder.verify(reporter).successful("successfulStep"); inOrder.verify(reporter).successful("anotherSuccessfulStep"); inOrder.verify(reporter).afterStory(); + verify(reporter, never()).beforeStory(storyDefinition1.getBlurb()); } - + @Test public void shouldNotPerformStepsAfterStepsWhichShouldNotContinue() throws Throwable { // Given @@ -141,77 +143,71 @@ Step secondStepPending = mock(Step.class); Step thirdStepNormal = mock(Step.class); Step fourthStepAlsoPending = mock(Step.class); - StepCreator creator = mock(StepCreator.class); Steps mySteps = mock(Steps.class); - - stub(creator.createStepsFrom((ScenarioDefinition)anyObject(), eq(tableRow), eq(mySteps))) - .toReturn(new Step[] {firstStepNormal, secondStepPending, thirdStepNormal, fourthStepAlsoPending}); - - ScenarioRunner runner = new ScenarioRunner(); - + stub(creator.createStepsFrom((ScenarioDefinition) anyObject(), eq(tableRow), eq(mySteps))).toReturn( + new Step[] { firstStepNormal, secondStepPending, thirdStepNormal, fourthStepAlsoPending }); stub(firstStepNormal.perform()).toReturn(StepResult.success("Given I succeed")); stub(secondStepPending.perform()).toReturn(StepResult.pending("When I am pending")); stub(thirdStepNormal.doNotPerform()).toReturn(StepResult.notPerformed("Then I should not be performed")); - stub(fourthStepAlsoPending.doNotPerform()).toReturn(StepResult.notPerformed("Then I should not be performed either")); + stub(fourthStepAlsoPending.doNotPerform()).toReturn( + StepResult.notPerformed("Then I should not be performed either")); // When - runner.run(new StoryDefinition(new ScenarioDefinition("")), configurationWith(reporter, creator), mySteps); - + ScenarioRunner runner = new ScenarioRunner(); + runner.run(new StoryDefinition(new ScenarioDefinition("")), configurationWith(reporter, creator), false, + mySteps); + // Then verify(firstStepNormal).perform(); verify(secondStepPending).perform(); verify(thirdStepNormal).doNotPerform(); verify(fourthStepAlsoPending).doNotPerform(); - + verify(reporter).successful("Given I succeed"); verify(reporter).pending("When I am pending"); verify(reporter).notPerformed("Then I should not be performed"); verify(reporter).notPerformed("Then I should not be performed either"); } - + @Test public void shouldReportAnyThrowablesThenHandleAfterStoryIsFinished() throws Throwable { // Given ScenarioReporter reporter = mock(ScenarioReporter.class); Step firstStepExceptional = mock(Step.class); Step secondStepNotPerformed = mock(Step.class); - StepResult failure = StepResult.failure("When I fail", new IllegalStateException()); StepResult notPerformed = StepResult.notPerformed("Then I should not be performed"); stub(firstStepExceptional.perform()).toReturn(failure); stub(secondStepNotPerformed.doNotPerform()).toReturn(notPerformed); - + ErrorStrategy errorStrategy = mock(ErrorStrategy.class); StepCreator creator = mock(StepCreator.class); Steps mySteps = mock(Steps.class); - ErrorStrategy errorStrategy = mock(ErrorStrategy.class); - - stub(creator.createStepsFrom((ScenarioDefinition)anyObject(), eq(tableRow), eq(mySteps))) - .toReturn(new Step[] {firstStepExceptional, secondStepNotPerformed}); - + stub(creator.createStepsFrom((ScenarioDefinition) anyObject(), eq(tableRow), eq(mySteps))).toReturn( + new Step[] { firstStepExceptional, secondStepNotPerformed }); + + // When ScenarioRunner runner = new ScenarioRunner(); - - // When - runner.run(new StoryDefinition(new ScenarioDefinition("")), configurationWith(reporter, creator, errorStrategy), mySteps); - - // Then scenario should still have finished + runner.run(new StoryDefinition(new ScenarioDefinition("")), + configurationWith(reporter, creator, errorStrategy), false, mySteps); + + // Then verify(firstStepExceptional).perform(); verify(secondStepNotPerformed).doNotPerform(); - // And results should have been described InOrder inOrder = inOrder(reporter, errorStrategy); - inOrder.verify(reporter).beforeStory((Blurb)anyObject()); - inOrder.verify(reporter).beforeScenario((String)anyObject()); + inOrder.verify(reporter).beforeStory((Blurb) anyObject()); + inOrder.verify(reporter).beforeScenario((String) anyObject()); inOrder.verify(reporter).failed("When I fail", failure.getThrowable()); inOrder.verify(reporter).notPerformed("Then I should not be performed"); inOrder.verify(reporter).afterScenario(); inOrder.verify(reporter).afterStory(); inOrder.verify(errorStrategy).handleError(failure.getThrowable()); } - - @Test + + @Test public void shouldResetStateForEachSetOfSteps() throws Throwable { - + // Given ScenarioReporter reporter = mock(ScenarioReporter.class); Step pendingStep = mock(Step.class); Step secondStep = mock(Step.class); @@ -219,83 +215,91 @@ stub(secondStep.perform()).toReturn(StepResult.success("secondStep")); StepCreator creator = mock(StepCreator.class); CandidateSteps mySteps = mock(Steps.class); - ScenarioDefinition scenario1 = mock(ScenarioDefinition.class); ScenarioDefinition scenario2 = mock(ScenarioDefinition.class); + stub(creator.createStepsFrom(scenario1, tableRow, mySteps)).toReturn(new Step[] { pendingStep }); + stub(creator.createStepsFrom(scenario2, tableRow, mySteps)).toReturn(new Step[] { secondStep }); - stub(creator.createStepsFrom(scenario1, tableRow, mySteps)) - .toReturn(new Step[] {pendingStep}); - stub(creator.createStepsFrom(scenario2, tableRow, mySteps)) - .toReturn(new Step[] {secondStep}); + // When + ScenarioRunner runner = new ScenarioRunner(); + runner.run(new StoryDefinition(scenario1, scenario2), configurationWith(reporter, creator), false, mySteps); - ScenarioRunner runner = new ScenarioRunner(); - - runner.run(new StoryDefinition(scenario1, scenario2), configurationWith(reporter, creator), mySteps); - + // Then verify(pendingStep).perform(); verify(secondStep).perform(); verify(secondStep, never()).doNotPerform(); } - - + @Test public void shouldHandlePendingStepsAccordingToStrategy() throws Throwable { + // Given ScenarioReporter reporter = mock(ScenarioReporter.class); Step pendingStep = mock(Step.class); StepResult pendingResult = StepResult.pending("My step isn't defined!"); stub(pendingStep.perform()).toReturn(pendingResult); - PendingErrorStrategy strategy = mock(PendingErrorStrategy.class); - StepCreator creator = mock(StepCreator.class); Steps mySteps = mock(Steps.class); - - stub(creator.createStepsFrom((ScenarioDefinition)anyObject(), eq(tableRow), eq(mySteps))) - .toReturn(new Step[] {pendingStep}); - - new ScenarioRunner().run(new StoryDefinition(new ScenarioDefinition("")), configurationWithPendingStrategy(creator, reporter, strategy), mySteps); - + stub(creator.createStepsFrom((ScenarioDefinition) anyObject(), eq(tableRow), eq(mySteps))).toReturn( + new Step[] { pendingStep }); + + // When + ScenarioRunner runner = new ScenarioRunner(); + runner.run(new StoryDefinition(new ScenarioDefinition("")), configurationWithPendingStrategy(creator, reporter, + strategy), false, mySteps); + + // Then verify(strategy).handleError(pendingResult.getThrowable()); } - - private Configuration configurationWithPendingStrategy(StepCreator creator, - ScenarioReporter reporter, PendingErrorStrategy strategy) { - return configurationWith(new ClasspathScenarioDefiner(), reporter, creator, new ErrorStrategyInWhichWeTrustTheReporter(), strategy); + + private Configuration configurationWithPendingStrategy(StepCreator creator, ScenarioReporter reporter, + PendingErrorStrategy strategy) { + return configurationWith(new ClasspathScenarioDefiner(), reporter, creator, + new ErrorStrategyInWhichWeTrustTheReporter(), strategy); } private Configuration configurationWith(final ScenarioReporter reporter, final StepCreator creator) { return configurationWith(reporter, creator, new ErrorStrategyInWhichWeTrustTheReporter()); } - - private Configuration configurationWith(ScenarioReporter reporter, - StepCreator creator, ErrorStrategy errorStrategy) { - return configurationWith(new ClasspathScenarioDefiner(), reporter, creator, errorStrategy); - } - private Configuration configurationWith(ScenarioDefiner definer, - final ScenarioReporter reporter, final StepCreator creator, final ErrorStrategy errorStrategy) { + private Configuration configurationWith(ScenarioReporter reporter, StepCreator creator, ErrorStrategy errorStrategy) { + return configurationWith(new ClasspathScenarioDefiner(), reporter, creator, errorStrategy); + } + + private Configuration configurationWith(ScenarioDefiner definer, final ScenarioReporter reporter, + final StepCreator creator, final ErrorStrategy errorStrategy) { return configurationWith(definer, reporter, creator, errorStrategy, PendingErrorStrategy.PASSING); } - - private Configuration configurationWith( - final ScenarioDefiner definer, final ScenarioReporter reporter, - final StepCreator creator, - final ErrorStrategy errorStrategy, - final PendingErrorStrategy pendingStrategy) { - - return new PropertyBasedConfiguration() { + + private Configuration configurationWith(final ScenarioDefiner definer, final ScenarioReporter reporter, + final StepCreator creator, final ErrorStrategy errorStrategy, final PendingErrorStrategy pendingStrategy) { + + return new PropertyBasedConfiguration() { @Override - public ScenarioDefiner forDefiningScenarios() { return definer; } - @Override - public StepCreator forCreatingSteps() { return creator; } + public ScenarioDefiner forDefiningScenarios() { + return definer; + } + @Override - public ScenarioReporter forReportingScenarios() { return reporter; } + public StepCreator forCreatingSteps() { + return creator; + } + @Override - public ErrorStrategy forHandlingErrors() { return errorStrategy; } + public ScenarioReporter forReportingScenarios() { + return reporter; + } + @Override - public PendingErrorStrategy forPendingSteps() { return pendingStrategy; } + public ErrorStrategy forHandlingErrors() { + return errorStrategy; + } + + @Override + public PendingErrorStrategy forPendingSteps() { + return pendingStrategy; + } }; } - }
Modified: trunk/core/jbehave-core/src/java/org/jbehave/scenario/AbstractScenario.java (1384 => 1385)
--- trunk/core/jbehave-core/src/java/org/jbehave/scenario/AbstractScenario.java 2009-11-05 12:46:44 UTC (rev 1384) +++ trunk/core/jbehave-core/src/java/org/jbehave/scenario/AbstractScenario.java 2009-11-05 22:53:00 UTC (rev 1385) @@ -8,10 +8,8 @@ import org.jbehave.scenario.definition.KeyWords; import org.jbehave.scenario.definition.StoryDefinition; import org.jbehave.scenario.parser.ScenarioNameResolver; -import org.jbehave.scenario.reporters.StepdocReporter; import org.jbehave.scenario.steps.CandidateSteps; import org.jbehave.scenario.steps.Stepdoc; -import org.jbehave.scenario.steps.StepdocGenerator; /** * <p> @@ -46,51 +44,46 @@ */ public abstract class AbstractScenario implements RunnableScenario { - private final Configuration configuration; - private final ScenarioRunner scenarioRunner; - private final List<CandidateSteps> candidateSteps = new ArrayList<CandidateSteps>(); - private final Class<? extends RunnableScenario> scenarioClass; + private final Configuration configuration; + private final ScenarioRunner scenarioRunner; + private final List<CandidateSteps> candidateSteps = new ArrayList<CandidateSteps>(); + private final Class<? extends RunnableScenario> scenarioClass; - public AbstractScenario(Class<? extends RunnableScenario> scenarioClass, - CandidateSteps... candidateSteps) { - this(scenarioClass, new PropertyBasedConfiguration(), candidateSteps); - } + public AbstractScenario(Class<? extends RunnableScenario> scenarioClass, CandidateSteps... candidateSteps) { + this(scenarioClass, new PropertyBasedConfiguration(), candidateSteps); + } - public AbstractScenario(Class<? extends RunnableScenario> scenarioClass, - Configuration configuration, CandidateSteps... candidateSteps) { - this(scenarioClass, new ScenarioRunner(), configuration, candidateSteps); - } + public AbstractScenario(Class<? extends RunnableScenario> scenarioClass, Configuration configuration, + CandidateSteps... candidateSteps) { + this(scenarioClass, new ScenarioRunner(), configuration, candidateSteps); + } - public AbstractScenario(Class<? extends RunnableScenario> scenarioClass, - ScenarioRunner scenarioRunner, Configuration configuration, - CandidateSteps... candidateSteps) { - this.scenarioClass = scenarioClass; - this.configuration = configuration; - this.scenarioRunner = scenarioRunner; - this.candidateSteps.addAll(asList(candidateSteps)); - } + public AbstractScenario(Class<? extends RunnableScenario> scenarioClass, ScenarioRunner scenarioRunner, + Configuration configuration, CandidateSteps... candidateSteps) { + this.scenarioClass = scenarioClass; + this.configuration = configuration; + this.scenarioRunner = scenarioRunner; + this.candidateSteps.addAll(asList(candidateSteps)); + } - public void runScenario() throws Throwable { - StoryDefinition story = configuration.forDefiningScenarios() - .loadScenarioDefinitionsFor(scenarioClass); - CandidateSteps[] steps = new CandidateSteps[candidateSteps.size()]; - candidateSteps.toArray(steps); - scenarioRunner.run(story, configuration, steps); - } + public void runScenario() throws Throwable { + StoryDefinition story = configuration.forDefiningScenarios().loadScenarioDefinitionsFor(scenarioClass); + CandidateSteps[] steps = candidateSteps.toArray(new CandidateSteps[candidateSteps.size()]); + scenarioRunner.run(story, configuration, false, steps); + } - public void addSteps(CandidateSteps... steps) { - this.candidateSteps.addAll(asList(steps)); - } + public void addSteps(CandidateSteps... steps) { + this.candidateSteps.addAll(asList(steps)); + } - public List<CandidateSteps> getSteps() { - return candidateSteps; - } + public List<CandidateSteps> getSteps() { + return candidateSteps; + } - public void generateStepdoc() { - StepdocGenerator generator = configuration.forGeneratingStepdoc(); - List<Stepdoc> stepdocs = generator.generate(candidateSteps.toArray(new CandidateSteps[candidateSteps.size()])); - StepdocReporter reporter = configuration.forReportingStepdoc(); - reporter.report(stepdocs); - } + public void generateStepdoc() { + CandidateSteps[] steps = candidateSteps.toArray(new CandidateSteps[candidateSteps.size()]); + List<Stepdoc> stepdocs = configuration.forGeneratingStepdoc().generate(steps); + configuration.forReportingStepdoc().report(stepdocs); + } }
Modified: trunk/core/jbehave-core/src/java/org/jbehave/scenario/ScenarioRunner.java (1384 => 1385)
--- trunk/core/jbehave-core/src/java/org/jbehave/scenario/ScenarioRunner.java 2009-11-05 12:46:44 UTC (rev 1384) +++ trunk/core/jbehave-core/src/java/org/jbehave/scenario/ScenarioRunner.java 2009-11-05 22:53:00 UTC (rev 1385) @@ -36,19 +36,25 @@ run(story, configuration, candidateSteps); } - public void run(String scenarioPath, Configuration configuration, CandidateSteps... candidateSteps) throws Throwable { + public void run(String scenarioPath, Configuration configuration, boolean embeddedStory, CandidateSteps... candidateSteps) throws Throwable { StoryDefinition story = configuration.forDefiningScenarios().loadScenarioDefinitionsFor(scenarioPath); - run(story, configuration, candidateSteps); - } + run(story, configuration, embeddedStory, candidateSteps); + } public void run(StoryDefinition story, Configuration configuration, CandidateSteps... candidateSteps) throws Throwable { + run(story, configuration, false, candidateSteps); + } + + public void run(StoryDefinition story, Configuration configuration, boolean embeddedStory, CandidateSteps... candidateSteps) throws Throwable { reporter = configuration.forReportingScenarios(); pendingStepStrategy = configuration.forPendingSteps(); errorStrategy = configuration.forHandlingErrors(); currentStrategy = ErrorStrategy.SILENT; throwable = null; - reporter.beforeStory(story.getBlurb()); + if ( !embeddedStory ){ + reporter.beforeStory(story.getBlurb()); + } for (ScenarioDefinition scenario : story.getScenarios()) { reporter.beforeScenario(scenario.getTitle()); runGivenScenarios(configuration, scenario, candidateSteps); // first run any given scenarios, if any @@ -59,7 +65,9 @@ } reporter.afterScenario(); } - reporter.afterStory(); + if ( !embeddedStory ){ + reporter.afterStory(); + } currentStrategy.handleError(throwable); } @@ -70,7 +78,8 @@ if ( givenScenarios.size() > 0 ){ reporter.givenScenarios(givenScenarios); for ( String scenarioPath : givenScenarios ){ - run(scenarioPath, configuration, candidateSteps); + // run in embedded mode + run(scenarioPath, configuration, true, candidateSteps); } } }
Modified: trunk/core/jbehave-core/src/java/org/jbehave/scenario/definition/StoryDefinition.java (1384 => 1385)
--- trunk/core/jbehave-core/src/java/org/jbehave/scenario/definition/StoryDefinition.java 2009-11-05 12:46:44 UTC (rev 1384) +++ trunk/core/jbehave-core/src/java/org/jbehave/scenario/definition/StoryDefinition.java 2009-11-05 22:53:00 UTC (rev 1385) @@ -1,8 +1,8 @@ package org.jbehave.scenario.definition; import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; -import java.util.Collections; import java.util.List; public class StoryDefinition { @@ -10,9 +10,8 @@ private final Blurb blurb; private final List<ScenarioDefinition> scenarioDefinitions; - public StoryDefinition(Blurb blurb, List<ScenarioDefinition> scenarioDefinitions) { - this.blurb = blurb; - this.scenarioDefinitions = scenarioDefinitions; + public StoryDefinition(ScenarioDefinition... scenarioDefinitions) { + this(asList(scenarioDefinitions)); } public StoryDefinition(List<ScenarioDefinition> scenarioDefinitions) { @@ -23,8 +22,9 @@ this(blurb, asList(scenarioDefinitions)); } - public StoryDefinition(ScenarioDefinition... scenarioDefinitions) { - this(asList(scenarioDefinitions)); + public StoryDefinition(Blurb blurb, List<ScenarioDefinition> scenarioDefinitions) { + this.blurb = blurb; + this.scenarioDefinitions = scenarioDefinitions; } public Blurb getBlurb() { @@ -32,6 +32,6 @@ } public List<ScenarioDefinition> getScenarios() { - return Collections.unmodifiableList(scenarioDefinitions); + return unmodifiableList(scenarioDefinitions); } }
To unsubscribe from this list please visit:
