From 8daccaa547b471187436336da4c065ffef19ccef Mon Sep 17 00:00:00 2001 From: Tymoteusz Paul Date: Wed, 27 May 2020 19:27:35 +0100 Subject: [PATCH] Moving from POC to actual implementation, first steps #50 --- src/output/junit.rs | 59 +++++++++++++++++++++++++++++++++------------ 1 file changed, 44 insertions(+), 15 deletions(-) diff --git a/src/output/junit.rs b/src/output/junit.rs index 4cac2490..7322174f 100644 --- a/src/output/junit.rs +++ b/src/output/junit.rs @@ -7,12 +7,14 @@ // except according to those terms. use junit_report::{Duration, Report, TestCase, TestSuite}; -use crate::event::FeatureEvent; +use crate::event::{FeatureEvent, ScenarioEvent, StepEvent, CucumberEvent}; use crate::{ - event::{CucumberEvent}, EventHandler, }; +use gherkin::{Feature, Rule, Scenario, Step}; use std::io::stdout; +use std::rc::Rc; +use std::borrow::Borrow; pub struct JunitOutput { report: Report, @@ -28,29 +30,56 @@ impl Default for JunitOutput { } } -impl JunitOutput {} +impl JunitOutput { + fn handle_step(&mut self, step: Rc, event: StepEvent) { + let test_case = TestCase::success( + step.value.as_ref(), + Duration::seconds(5), + Some(step.value.to_string()), + ); + self.test_suite.add_testcase(test_case); + } +} impl EventHandler for JunitOutput { fn handle_event(&mut self, event: CucumberEvent) { match event { - CucumberEvent::Starting => {} + CucumberEvent::Starting => { + } CucumberEvent::Feature(feature, event) => match event { - FeatureEvent::Starting => self.test_suite = TestSuite::new(feature.name.as_ref()), - FeatureEvent::Scenario(scenario, _event) => { - let test_case = TestCase::success( - scenario.name.as_ref(), - Duration::seconds(5), - Some("you-tell-me".parse().unwrap()), - ); - self.test_suite.add_testcase(test_case); + FeatureEvent::Starting => { + self.report = Report::new(); + } + FeatureEvent::Scenario(scenario, event) => { + match event { + ScenarioEvent::Starting => { + self.test_suite = TestSuite::new(scenario.name.as_ref()); + }, + ScenarioEvent::Background(step, event) => { + self.handle_step(step, event); + }, + ScenarioEvent::Step(step, event) => { + self.handle_step(step, event); + }, + ScenarioEvent::Skipped => { + self.report.add_testsuite(self.test_suite.clone()); + }, + ScenarioEvent::Passed => { + self.report.add_testsuite(self.test_suite.clone()); + }, + ScenarioEvent::Failed => { + self.report.add_testsuite(self.test_suite.clone()); + }, + } } FeatureEvent::Rule(_rule, _event) => {} FeatureEvent::Finished => { - self.report.add_testsuite(self.test_suite.clone()); - self.report.write_xml(stdout()).unwrap(); + // self.report.add_testsuite(self.test_suite.clone()); } }, - CucumberEvent::Finished => {} + CucumberEvent::Finished => { + self.report.write_xml(stdout()).unwrap(); + } } } }