Skip to content

Commit

Permalink
New Snippet text, closes #618.
Browse files Browse the repository at this point in the history
Change to the new Snippet text. Update History.md.
Fix a one off error in JRubySnippet.java.
  • Loading branch information
brasmusson committed Nov 2, 2013
1 parent 72de543 commit fa81ba3
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 31 deletions.
1 change: 1 addition & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## [1-1-6-SNAPSHOT (Git master)](https://github.com/cucumber/cucumber-jvm/compare/v1.1.5...master)

* [Core] New Snippet text. ([#618](https://github.com/cucumber/cucumber-jvm/issues/618) Jeff Nyman, Matt Wynne, Aslak Hellesøy)
* [Android] Add command line option support for Android ([#597](https://github.com/cucumber/cucumber-jvm/pull/597), Frieder Bluemle)
* [Android] Add debug support for eclipse ([#613](https://github.com/cucumber/cucumber-jvm/pull/613) Ian Warwick)
* [Core] Make the RerunFormatter handle failures in background and scenario outline examples correctly ([#589](https://github.com/cucumber/cucumber-jvm/pull/589) Björn Rasmusson)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void generatesPlainSnippet() {
String snippet = new SnippetGenerator(new ClojureSnippet()).getSnippet(step, null);
String expected = "" +
"(Given #\"^I have (\\d+) cukes in my \\\"([^\\\"]*)\\\" belly$\" [arg1 arg2]\n" +
" (comment Express the Regexp above with the code you wish you had )\n" +
" (comment Write code here that turns the phrase above into concrete actions )\n" +
" (throw (cucumber.api.PendingException.)))\n";
assertEquals(expected, snippet);
}
Expand All @@ -33,7 +33,7 @@ public void generatesSnippetWithDataTable() {
String snippet = new SnippetGenerator(new ClojureSnippet()).getSnippet(step, null);
String expected = "" +
"(Given #\"^I have:$\" [arg1]\n" +
" (comment Express the Regexp above with the code you wish you had )\n" +
" (comment Write code here that turns the phrase above into concrete actions )\n" +
" (throw (cucumber.api.PendingException.)))\n";
assertEquals(expected, snippet);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class SnippetGenerator {
Pattern.compile("\\^")
};

private static final String REGEXP_HINT = "Express the Regexp above with the code you wish you had";
private static final String REGEXP_HINT = "Write code here that turns the phrase above into concrete actions";

private final Snippet snippet;

Expand Down
20 changes: 10 additions & 10 deletions groovy/src/test/java/cucumber/runtime/groovy/GroovySnippetTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class GroovySnippetTest {
public void generatesPlainSnippet() {
String expected = "" +
"Given(~'^I have (\\\\d+) cukes in my \"([^\"]*)\" belly$') { int arg1, String arg2 ->\n" +
" // Express the Regexp above with the code you wish you had\n" +
" // Write code here that turns the phrase above into concrete actions\n" +
" throw new PendingException()\n" +
"}\n";
assertEquals(expected, snippetFor("I have 4 cukes in my \"big\" belly"));
Expand All @@ -31,7 +31,7 @@ public void generatesPlainSnippet() {
public void generatesCopyPasteReadyStepSnippetForNumberParameters() throws Exception {
String expected = "" +
"Given(~'^before (\\\\d+) after$') { int arg1 ->\n" +
" // Express the Regexp above with the code you wish you had\n" +
" // Write code here that turns the phrase above into concrete actions\n" +
" throw new PendingException()\n" +
"}\n";
String snippet = snippetFor("before 5 after");
Expand All @@ -42,7 +42,7 @@ public void generatesCopyPasteReadyStepSnippetForNumberParameters() throws Excep
public void generatesCopyPasteReadySnippetWhenStepHasIllegalJavaIdentifierChars() {
String expected = "" +
"Given(~'^I have (\\\\d+) cukes in: my \"([^\"]*)\" red-belly!$') { int arg1, String arg2 ->\n" +
" // Express the Regexp above with the code you wish you had\n" +
" // Write code here that turns the phrase above into concrete actions\n" +
" throw new PendingException()\n" +
"}\n";
assertEquals(expected, snippetFor("I have 4 cukes in: my \"big\" red-belly!"));
Expand All @@ -53,7 +53,7 @@ public void generatesCopyPasteReadySnippetWhenStepHasIllegalJavaIdentifierChars(
public void generatesCopyPasteReadySnippetWhenStepHasIntegersInsideStringParameter() {
String expected = "" +
"Given(~'^the DI system receives a message saying \"([^\"]*)\"$') { String arg1 ->\n" +
" // Express the Regexp above with the code you wish you had\n" +
" // Write code here that turns the phrase above into concrete actions\n" +
" throw new PendingException()\n" +
"}\n";
assertEquals(expected, snippetFor("the DI system receives a message saying \"{ dataIngestion: { feeds: [ feed: { merchantId: 666, feedId: 1, feedFileLocation: feed.csv } ] }\""));
Expand All @@ -63,7 +63,7 @@ public void generatesCopyPasteReadySnippetWhenStepHasIntegersInsideStringParamet
public void generatesSnippetWithEscapedDollarSigns() {
String expected = "" +
"Given(~'^I have \\\\$(\\\\d+)$') { int arg1 ->\n" +
" // Express the Regexp above with the code you wish you had\n" +
" // Write code here that turns the phrase above into concrete actions\n" +
" throw new PendingException()\n" +
"}\n";
assertEquals(expected, snippetFor("I have $5"));
Expand All @@ -73,7 +73,7 @@ public void generatesSnippetWithEscapedDollarSigns() {
public void generatesSnippetWithEscapedParentheses() {
String expected = "" +
"Given(~'^I have (\\\\d+) cukes \\\\(maybe more\\\\)$') { int arg1 ->\n" +
" // Express the Regexp above with the code you wish you had\n" +
" // Write code here that turns the phrase above into concrete actions\n" +
" throw new PendingException()\n" +
"}\n";
assertEquals(expected, snippetFor("I have 5 cukes (maybe more)"));
Expand All @@ -83,7 +83,7 @@ public void generatesSnippetWithEscapedParentheses() {
public void generatesSnippetWithEscapedBrackets() {
String expected = "" +
"Given(~'^I have (\\\\d+) cukes \\\\[maybe more\\\\]$') { int arg1 ->\n" +
" // Express the Regexp above with the code you wish you had\n" +
" // Write code here that turns the phrase above into concrete actions\n" +
" throw new PendingException()\n" +
"}\n";
assertEquals(expected, snippetFor("I have 5 cukes [maybe more]"));
Expand All @@ -93,7 +93,7 @@ public void generatesSnippetWithEscapedBrackets() {
public void generatesSnippetWithDocString() {
String expected = "" +
"Given(~'^I have:$') { String arg1 ->\n" +
" // Express the Regexp above with the code you wish you had\n" +
" // Write code here that turns the phrase above into concrete actions\n" +
" throw new PendingException()\n" +
"}\n";
assertEquals(expected, snippetForDocString("I have:", new DocString("text/plain", "hello", 1)));
Expand All @@ -103,7 +103,7 @@ public void generatesSnippetWithDocString() {
public void generatesSnippetWithDataTable() {
String expected = "" +
"Given(~'^I have:$') { DataTable arg1 ->\n" +
" // Express the Regexp above with the code you wish you had\n" +
" // Write code here that turns the phrase above into concrete actions\n" +
" throw new PendingException()\n" +
"}\n";
List<DataTableRow> dataTable = asList(new DataTableRow(NO_COMMENTS, asList("col1"), 1));
Expand All @@ -114,7 +114,7 @@ public void generatesSnippetWithDataTable() {
public void generateSnippetWithEscapedEscapeCharacter() {
String expected = "" +
"Given(~'^I have (\\\\d+) cukes in my belly$') { int arg1 ->\n" +
" // Express the Regexp above with the code you wish you had\n" +
" // Write code here that turns the phrase above into concrete actions\n" +
" throw new PendingException()\n" +
"}\n";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void generatesPlainSnippet() {
String snippet = new SnippetGenerator(new IokeSnippet()).getSnippet(step, null);
String expected = "" +
"Given(#/^I have ({arg1}\\d+) cukes in my \"({arg2}[^\"]*)\" belly$/,\n" +
" # Express the Regexp above with the code you wish you had\n" +
" # Write code here that turns the phrase above into concrete actions\n" +
")\n";
assertEquals(expected, snippet);
}
Expand Down
24 changes: 12 additions & 12 deletions java/src/test/java/cucumber/runtime/java/JavaSnippetTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void generatesPlainSnippet() {
String expected = "" +
"@Given(\"^I have (\\\\d+) cukes in my \\\"([^\\\"]*)\\\" belly$\")\n" +
"public void i_have_cukes_in_my_belly(int arg1, String arg2) throws Throwable {\n" +
" // Express the Regexp above with the code you wish you had\n" +
" // Write code here that turns the phrase above into concrete actions\n" +
" throw new PendingException();\n" +
"}\n";
assertEquals(expected, snippetFor("I have 4 cukes in my \"big\" belly"));
Expand All @@ -37,7 +37,7 @@ public void generatesCopyPasteReadyStepSnippetForNumberParameters() throws Excep
String expected = "" +
"@Given(\"^before (\\\\d+) after$\")\n" +
"public void before_after(int arg1) throws Throwable {\n" +
" // Express the Regexp above with the code you wish you had\n" +
" // Write code here that turns the phrase above into concrete actions\n" +
" throw new PendingException();\n" +
"}\n";
String snippet = snippetFor("before 5 after");
Expand All @@ -49,7 +49,7 @@ public void generatesCopyPasteReadySnippetWhenStepHasIllegalJavaIdentifierChars(
String expected = "" +
"@Given(\"^I have (\\\\d+) cukes in: my \\\"([^\\\"]*)\\\" red-belly!$\")\n" +
"public void i_have_cukes_in_my_red_belly(int arg1, String arg2) throws Throwable {\n" +
" // Express the Regexp above with the code you wish you had\n" +
" // Write code here that turns the phrase above into concrete actions\n" +
" throw new PendingException();\n" +
"}\n";
assertEquals(expected, snippetFor("I have 4 cukes in: my \"big\" red-belly!"));
Expand All @@ -61,7 +61,7 @@ public void generatesCopyPasteReadySnippetWhenStepHasIntegersInsideStringParamet
String expected = "" +
"@Given(\"^the DI system receives a message saying \\\"([^\\\"]*)\\\"$\")\n" +
"public void the_DI_system_receives_a_message_saying(String arg1) throws Throwable {\n" +
" // Express the Regexp above with the code you wish you had\n" +
" // Write code here that turns the phrase above into concrete actions\n" +
" throw new PendingException();\n" +
"}\n";
assertEquals(expected, snippetFor("the DI system receives a message saying \"{ dataIngestion: { feeds: [ feed: { merchantId: 666, feedId: 1, feedFileLocation: feed.csv } ] }\""));
Expand All @@ -72,7 +72,7 @@ public void generatesSnippetWithEscapedDollarSigns() {
String expected = "" +
"@Given(\"^I have \\\\$(\\\\d+)$\")\n" +
"public void i_have_$(int arg1) throws Throwable {\n" +
" // Express the Regexp above with the code you wish you had\n" +
" // Write code here that turns the phrase above into concrete actions\n" +
" throw new PendingException();\n" +
"}\n";
assertEquals(expected, snippetFor("I have $5"));
Expand All @@ -83,7 +83,7 @@ public void generatesSnippetWithEscapedQuestionMarks() {
String expected = "" +
"@Given(\"^is there an error\\\\?:$\")\n" +
"public void is_there_an_error() throws Throwable {\n" +
" // Express the Regexp above with the code you wish you had\n" +
" // Write code here that turns the phrase above into concrete actions\n" +
" throw new PendingException();\n" +
"}\n";
assertEquals(expected, snippetFor("is there an error?:"));
Expand All @@ -94,7 +94,7 @@ public void generatesSnippetWithLotsOfEscapes() {
String expected = "" +
"@Given(\"^\\\\^\\\\(\\\\[a-z\\\\]\\\\*\\\\)\\\\?\\\\.\\\\+\\\\$$\")\n" +
"public void a_z_$() throws Throwable {\n" +
" // Express the Regexp above with the code you wish you had\n" +
" // Write code here that turns the phrase above into concrete actions\n" +
" throw new PendingException();\n" +
"}\n";
assertEquals(expected, snippetFor("^([a-z]*)?.+$"));
Expand All @@ -105,7 +105,7 @@ public void generatesSnippetWithEscapedParentheses() {
String expected = "" +
"@Given(\"^I have (\\\\d+) cukes \\\\(maybe more\\\\)$\")\n" +
"public void i_have_cukes_maybe_more(int arg1) throws Throwable {\n" +
" // Express the Regexp above with the code you wish you had\n" +
" // Write code here that turns the phrase above into concrete actions\n" +
" throw new PendingException();\n" +
"}\n";
assertEquals(expected, snippetFor("I have 5 cukes (maybe more)"));
Expand All @@ -116,7 +116,7 @@ public void generatesSnippetWithEscapedBrackets() {
String expected = "" +
"@Given(\"^I have (\\\\d+) cukes \\\\[maybe more\\\\]$\")\n" +
"public void i_have_cukes_maybe_more(int arg1) throws Throwable {\n" +
" // Express the Regexp above with the code you wish you had\n" +
" // Write code here that turns the phrase above into concrete actions\n" +
" throw new PendingException();\n" +
"}\n";
assertEquals(expected, snippetFor("I have 5 cukes [maybe more]"));
Expand All @@ -127,7 +127,7 @@ public void generatesSnippetWithDocString() {
String expected = "" +
"@Given(\"^I have:$\")\n" +
"public void i_have(String arg1) throws Throwable {\n" +
" // Express the Regexp above with the code you wish you had\n" +
" // Write code here that turns the phrase above into concrete actions\n" +
" throw new PendingException();\n" +
"}\n";
assertEquals(expected, snippetForDocString("I have:", new DocString("text/plain", "hello", 1)));
Expand All @@ -139,7 +139,7 @@ public void recognisesWordWithNumbers() {
String expected = "" +
"@Given(\"^Then it responds ([^\\\"]*)$\")\n" +
"public void Then_it_responds(String arg1) throws Throwable {\n" +
" // Express the Regexp above with the code you wish you had\n" +
" // Write code here that turns the phrase above into concrete actions\n" +
"}\n";
assertEquals(expected, snippetFor("Then it responds UTF-8"));
}
Expand All @@ -149,7 +149,7 @@ public void generatesSnippetWithDataTable() {
String expected = "" +
"@Given(\"^I have:$\")\n" +
"public void i_have(DataTable arg1) throws Throwable {\n" +
" // Express the Regexp above with the code you wish you had\n" +
" // Write code here that turns the phrase above into concrete actions\n" +
" // For automatic conversion, change DataTable to List<YourType>\n" +
" throw new PendingException();\n" +
"}\n";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public String tableHint() {
public String arguments(List<Class<?>> argumentTypes) {
StringBuilder sb = new StringBuilder(argumentTypes.isEmpty() ? "" : "|");
for (int n = 0; n < argumentTypes.size(); n++) {
if (n > 1) {
if (n > 0) {
sb.append(", ");
}
sb.append("arg").append(n + 1);
Expand Down
32 changes: 32 additions & 0 deletions jruby/src/test/java/cucumber/runtime/jruby/JRubySnippetTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package cucumber.runtime.jruby;

import cucumber.runtime.snippets.SnippetGenerator;
import gherkin.formatter.model.Comment;
import gherkin.formatter.model.Step;
import org.junit.Test;

import java.util.Collections;
import java.util.List;

import static java.util.Arrays.asList;
import static org.junit.Assert.assertEquals;

public class JRubySnippetTest {

private static final List<Comment> NO_COMMENTS = Collections.emptyList();

@Test
public void generatesPlainSnippet() {
String expected = "" +
"Given /^I have (\\d+) cukes in my \"([^\"]*)\" belly$/ do |arg1, arg2|\n" +
" # Write code here that turns the phrase above into concrete actions\n" +
" pending\n" +
"end\n";
assertEquals(expected, snippetFor("I have 4 cukes in my \"big\" belly"));
}

private String snippetFor(String name) {
Step step = new Step(NO_COMMENTS, "Given ", name, 0, null, null);
return new SnippetGenerator(new JRubySnippet()).getSnippet(step, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void generatesSnippetWithTwoArgs() {
String expected = "" +
"@Given('^I have (\\d+) cukes in my \"([^\"]*)\" belly$')\n" +
"def i_have_cukes_in_my_belly(self, arg1, arg2):\n" +
" # Express the Regexp above with the code you wish you had\n" +
" # Write code here that turns the phrase above into concrete actions\n" +
" raise(PendingException())\n" +
"";
assertEquals(expected, snippetFor("I have 4 cukes in my \"big\" belly"));
Expand All @@ -33,7 +33,7 @@ public void generatesSnippetWithZeroArgs() {
String expected = "" +
"@Given('^I have no cukes belly$')\n" +
"def i_have_no_cukes_belly(self):\n" +
" # Express the Regexp above with the code you wish you had\n" +
" # Write code here that turns the phrase above into concrete actions\n" +
" raise(PendingException())\n" +
"";
assertEquals(expected, snippetFor("I have no cukes belly"));
Expand All @@ -44,7 +44,7 @@ public void generatesSnippetWithDataTable() {
String expected = "" +
"@Given('^I have:$')\n" +
"def i_have(self, arg1):\n" +
" # Express the Regexp above with the code you wish you had\n" +
" # Write code here that turns the phrase above into concrete actions\n" +
" # The last argument is a List of List of String\n" +
" raise(PendingException())\n" +
"";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class JavaScriptSnippetTest {
public void generatesPlainSnippet() {
String expected = "" +
"Given(/^I have (\\d+) cukes in my \"([^\"]*)\" belly$/, function(arg1, arg2) {\n" +
" // Express the Regexp above with the code you wish you had\n" +
" // Write code here that turns the phrase above into concrete actions\n" +
" throw new Packages.cucumber.api.PendingException();\n" +
"});\n";
assertEquals(expected, snippetFor("I have 4 cukes in my \"big\" belly"));
Expand Down

0 comments on commit fa81ba3

Please sign in to comment.