Skip to content

Commit

Permalink
Fail if no features are found. Closes cucumber#163
Browse files Browse the repository at this point in the history
  • Loading branch information
aslakhellesoy committed Feb 6, 2012
1 parent 894cf1c commit 287bf9b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 14 deletions.
1 change: 1 addition & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## In Git

* [Core] Fail if no features are found ([#163](https://github.com/cucumber/cucumber-jvm/issues/163) Aslak Hellesøy)
* [Core] Fail if duplicate features are detected ([#165](https://github.com/cucumber/cucumber-jvm/issues/165) Aslak Hellesøy)

## [1.0.0.RC14](https://github.com/cucumber/cucumber-jvm/compare/v1.0.0.RC13...v1.0.0.RC14)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import cucumber.io.Resource;
import cucumber.io.ResourceLoader;
import cucumber.runtime.CucumberException;
import cucumber.runtime.FeatureBuilder;
import gherkin.I18n;
import gherkin.formatter.model.Background;
Expand Down Expand Up @@ -32,6 +33,9 @@ public static List<CucumberFeature> load(ResourceLoader resourceLoader, List<Str
builder.parse(resource, filters);
}
}
if(cucumberFeatures.isEmpty()) {
throw new CucumberException(String.format("No features found at %s", featurePaths));
}
return cucumberFeatures;
}

Expand Down
12 changes: 1 addition & 11 deletions core/src/test/java/cucumber/formatter/HTMLFormatterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,11 @@
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;

public class HTMLFormatterTest {

@Test
public void noFeaturesProduceEmptyReport() throws IOException {
final List<String> noFeatures = emptyList();
final File report = createFormatterJsReport(noFeatures);

assertEquals(0, report.length());
}

@Test
public void oneFeatureProducesValidJavascript() throws IOException {
final File report = createFormatterJsReport(asList("cucumber/formatter/HTMLFormatterTest.feature"));
Expand All @@ -46,8 +37,7 @@ public void oneFeatureProducesValidJavascript() throws IOException {

private File createFormatterJsReport(final List<String> featurePaths) throws IOException {
final File outputDir = runFeaturesWithFormatter(featurePaths);
final File report = new File(outputDir, "report.js");
return report;
return new File(outputDir, "report.js");
}

private File runFeaturesWithFormatter(final List<String> featurePaths) throws IOException {
Expand Down
23 changes: 23 additions & 0 deletions core/src/test/java/cucumber/runtime/model/CucumberFeatureTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package cucumber.runtime.model;

import cucumber.io.Resource;
import cucumber.io.ResourceLoader;
import cucumber.runtime.CucumberException;
import org.junit.Test;

import java.util.Collections;

import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class CucumberFeatureTest {
@Test(expected = CucumberException.class)
public void fails_if_no_features_are_found() {
ResourceLoader resourceLoader = mock(ResourceLoader.class);
when(resourceLoader.resources(anyString(), anyString())).thenReturn(Collections.<Resource>emptyList());
CucumberFeature.load(resourceLoader, asList("does/not/exit"), emptyList());
}
}
6 changes: 3 additions & 3 deletions junit/src/test/java/cucumber/junit/CucumberTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cucumber.junit;

import cucumber.runtime.CucumberException;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -43,10 +44,9 @@ public void finds_features_based_on_explicit_root_package() throws IOException,
assertEquals("Feature: In cucumber.junit", cucumber.getChildren().get(0).getName());
}

@Test
@Test(expected = CucumberException.class)
public void finds_no_features_when_explicit_package_has_nothnig() throws IOException, InitializationError {
Cucumber cucumber = new Cucumber(ExplicitPackageWithNoFeatures.class);
assertEquals(0, cucumber.getChildren().size());
new Cucumber(ExplicitPackageWithNoFeatures.class);
}

private class ImplicitPackage {
Expand Down

0 comments on commit 287bf9b

Please sign in to comment.