Skip to content

Commit

Permalink
Moving from POC to actual implementation, first steps cucumber-rs#50
Browse files Browse the repository at this point in the history
  • Loading branch information
AidaPaul committed May 27, 2020
1 parent 7018734 commit 8daccaa
Showing 1 changed file with 44 additions and 15 deletions.
59 changes: 44 additions & 15 deletions src/output/junit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -28,29 +30,56 @@ impl Default for JunitOutput {
}
}

impl JunitOutput {}
impl JunitOutput {
fn handle_step(&mut self, step: Rc<Step>, 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();
}
}
}
}

0 comments on commit 8daccaa

Please sign in to comment.