use of io.cucumber.plugin.event.SnippetsSuggestedEvent.Suggestion in project cucumber-jvm by cucumber.
the class Runner method emitSnippetSuggestedEvent.
private void emitSnippetSuggestedEvent(Pickle pickle, Step step) {
List<String> snippets = generateSnippetsForStep(step);
if (snippets.isEmpty()) {
return;
}
Suggestion suggestion = new Suggestion(step.getText(), snippets);
Location scenarioLocation = pickle.getLocation();
Location stepLocation = step.getLocation();
SnippetsSuggestedEvent event = new SnippetsSuggestedEvent(bus.getInstant(), pickle.getUri(), scenarioLocation, stepLocation, suggestion);
bus.send(event);
}
use of io.cucumber.plugin.event.SnippetsSuggestedEvent.Suggestion in project cucumber-jvm by cucumber.
the class TestCaseResultObserverTest method should_be_failed_for_undefined_result.
@Test
public void should_be_failed_for_undefined_result() {
TestCaseResultObserver resultListener = TestCaseResultObserver.observe(bus);
bus.send(new SnippetsSuggestedEvent(now(), uri, location, location, new Suggestion("some step", singletonList("stub snippet"))));
Result stepResult = new Result(UNDEFINED, ZERO, error);
bus.send(new TestStepFinished(now(), testCase, step, stepResult));
Result testCaseResult = new Result(UNDEFINED, ZERO, error);
bus.send(new TestCaseFinished(now(), testCase, testCaseResult));
Exception exception = expectThrows(Exception.class, resultListener::assertTestCasePassed);
assertThat(exception.getCause(), instanceOf(SkipException.class));
SkipException skipException = (SkipException) exception.getCause();
assertThat(skipException.isSkip(), is(false));
assertThat(skipException.getMessage(), is("" + "The step 'some step' is undefined.\n" + "You can implement this step using the snippet(s) below:\n" + "\n" + "stub snippet\n"));
}
use of io.cucumber.plugin.event.SnippetsSuggestedEvent.Suggestion in project cucumber-jvm by cucumber.
the class UndefinedStepException method createMessage.
private static String createMessage(Collection<Suggestion> suggestions) {
if (suggestions.isEmpty()) {
return "This step is undefined";
}
Suggestion first = suggestions.iterator().next();
StringBuilder sb = new StringBuilder("The step '" + first.getStep() + "'");
if (suggestions.size() == 1) {
sb.append(" is undefined.");
} else {
sb.append(" and ").append(suggestions.size() - 1).append(" other step(s) are undefined.");
}
sb.append("\n");
if (suggestions.size() == 1) {
sb.append("You can implement this step using the snippet(s) below:\n\n");
} else {
sb.append("You can implement these steps using the snippet(s) below:\n\n");
}
String snippets = suggestions.stream().map(Suggestion::getSnippets).flatMap(Collection::stream).distinct().collect(Collectors.joining("\n", "", "\n"));
sb.append(snippets);
return sb.toString();
}
use of io.cucumber.plugin.event.SnippetsSuggestedEvent.Suggestion in project cucumber-jvm by cucumber.
the class TestCaseResultObserverTest method undefined.
@Test
void undefined() {
bus.send(new TestCaseStarted(Instant.now(), testCase));
bus.send(new TestStepStarted(Instant.now(), testCase, testStep));
bus.send(new SnippetsSuggestedEvent(Instant.now(), uri, testCase.getLocation(), testStep.getStep().getLocation(), new Suggestion(testStep.getStep().getText(), asList("mocked snippet 1", "mocked snippet 2", "mocked snippet 3"))));
Result result = new Result(Status.UNDEFINED, Duration.ZERO, null);
bus.send(new TestStepFinished(Instant.now(), testCase, testStep, result));
bus.send(new TestCaseFinished(Instant.now(), testCase, result));
Exception exception = assertThrows(Exception.class, observer::assertTestCasePassed);
assertThat(exception.getCause(), instanceOf(UndefinedStepException.class));
assertThat(exception.getCause().getMessage(), is("" + "The step 'mocked' is undefined.\n" + "You can implement this step using the snippet(s) below:\n" + "\n" + "mocked snippet 1\n" + "mocked snippet 2\n" + "mocked snippet 3\n"));
}
use of io.cucumber.plugin.event.SnippetsSuggestedEvent.Suggestion in project cucumber-jvm by cucumber.
the class TeamCityPlugin method getSnippets.
private String getSnippets(TestCase testCase) {
URI uri = testCase.getUri();
Location location = testCase.getLocation();
List<Suggestion> suggestionForTestCase = suggestions.stream().filter(suggestion -> suggestion.getUri().equals(uri) && suggestion.getTestCaseLocation().equals(location)).map(SnippetsSuggestedEvent::getSuggestion).collect(Collectors.toList());
return createMessage(suggestionForTestCase);
}
Aggregations