Issue Type: Bug Bug
Affects Versions: 3.8
Assignee: Unassigned
Attachments: StatsCorrect.png, StatsError.png
Components: Core
Created: 26/Jun/13 4:32 AM
Description:

Execute a story with a given story:
The given story contains 2 scenarios, where one of them fails
The acutal story contains only 1 scenario

Expected: The stats look like can be seen from StatsCorrect.png

Reveived: The stats look like can be seen from StatsError.png

Cause can be found in PostStoryStatisticsCollector:

The method writeData uses the output OutputStream to write the properties to the stats file.
This method is called for both stories: the given and the actual one.
However the output Outputstream is closed after the first writingData call and therefore cannot write any other data to the stats file.
Moreover in the afterStory method there is call to add("scenarioFailed") for a given story, which also causes wrong stats. This should be commented out.
It would also be nice to change the access modifier of methods like add, has, .. to public in order to let people easily add their own statistics.

Suggestions for closing the bug:

PostStoryStatisticsCollector.java
private boolean isClosed = false;

private void writeData() {
	if(isClosed){
		//Recreate outputstream if already closed .... getOutputFile() has to be created also
		output = new FilePrintStreamFactory.FilePrintStream(output.getOutputFile(), false); 
		isClosed = false;
	}
	
	Properties p = new Properties();
	for(String event : data.keySet()) {
	   if (!event.startsWith("current")) {
			p.setProperty(event, data.get(event).toString());
		}
	}
	try {
		p.store(output, this.getClass().getName());
	} catch (IOException e) {
		e.printStackTrace();
	} finally {
		//Put close to finally in order to also close the stream in case of an error
		output.close();
		isClosed = true;
	}
}

public void afterStory(boolean givenStory) {
	boolean write = false;
	if (givenStory) {
		this.givenStories--;
		if ( has("stepsFailed") ){
			// What is this used for? --> causes stats error --> at least givenStoryScenarioFailed should be called?
			//add("scenariosFailed");
			write = true;
		}
		....
	}
}
Environment: Windows 7
Java 6u41
Maven 3.0.4
Project: JBehave
Labels: stats
Priority: Major Major
Reporter: Stefan Leonhartsberger
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
--------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email

Reply via email to