Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fixed bug where -getSnippet in clj.clj received only the step parameter. #650

Merged
merged 1 commit into from

3 participants

@shaolang

cucumber.runtime.UndefinedStepsTracker actually calls the Backend
instances with 2 parameters--Step and FunctionNameGenerator--but
Clojure's Backend implementation only accepts one.

Instead of testing generation of Clojure Snippet with a test-only
ClojureSnippet instance, ClojureSnippetTest now tests the real
implementation in clj.clj.

Prior this fix, cucumber-clojure throws the following exceptions:

Exception in thread "main" clojure.lang.ArityException: Wrong number of args (3) passed to: clj$-getSnippet
        at clojure.lang.AFn.throwArity(AFn.java:437)
        at clojure.lang.AFn.invoke(AFn.java:47)
        at cucumber.runtime.clj.Backend.getSnippet(Unknown Source)
        at cucumber.runtime.UndefinedStepsTracker.getSnippets(UndefinedStepsTracker.java:32)
        at cucumber.runtime.Runtime.getSnippets(Runtime.java:183)
        at cucumber.runtime.snippets.SummaryPrinter.printSnippets(SummaryPrinter.java:33)
        at cucumber.runtime.snippets.SummaryPrinter.print(SummaryPrinter.java:18)
        at cucumber.runtime.Runtime.printSummary(Runtime.java:125)
        at cucumber.runtime.Runtime.run(Runtime.java:114)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
@shaolang shaolang Fixed bug where -getSnippet in clj.clj received only the step parameter.
cucumber.runtime.UndefinedStepsTracker actually calls the Backend
instances with 2 parameters--Step and FunctionNameGenerator--but
Clojure's Backend implementation only accepts one.

Instead of testing generation of Clojure Snippet with a test-only
ClojureSnippet instance, ClojureSnippetTest now tests the real
implementation in clj.clj.
5e3d2fd
@brasmusson
Collaborator

@aslakhellesoy I have checked this PR and think it is OK to merge (and at the same time remove the now obsolete comment about keeping the snippet templates in clj.clj and the removed ClojureSnippet.java in sync).

  • The getSnippet function of the Clojure Backend needs to conform to the signature of the Backend interface in core (even though the FunctionNameGenerator argument is not used, since Clojure step definitions does not have a function name separate from the step definition regexp).
  • Testing the generated snippets in isolation using a copy of the snippet template in ClojureSnippet is faster (~0.3s instead of ~3s), but testing a copy instead of the real thing also has problems (including hiding this bug), so the solution is the PR seems like an improvement to me.

OK?

@aslakhellesoy

Ok - go ahead and merge!

@brasmusson brasmusson referenced this pull request from a commit
@brasmusson brasmusson Merge #650. Update History.md
Also remove obsolete comment from the Clojure backend.
63dca60
@brasmusson brasmusson merged commit 5e3d2fd into cucumber:master

1 check passed

Details default The Travis CI build passed
@brasmusson
Collaborator

Merged. Thanks for your contribution @shaolang.

@shaolang

@brasmusson You're welcome. :)

@shaolang shaolang deleted the shaolang:clojure-get-snippet-fix branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 19, 2013
  1. @shaolang

    Fixed bug where -getSnippet in clj.clj received only the step parameter.

    shaolang authored
    cucumber.runtime.UndefinedStepsTracker actually calls the Backend
    instances with 2 parameters--Step and FunctionNameGenerator--but
    Clojure's Backend implementation only accepts one.
    
    Instead of testing generation of Clojure Snippet with a test-only
    ClojureSnippet instance, ClojureSnippetTest now tests the real
    implementation in clj.clj.
This page is out of date. Refresh to see the latest.
View
4 clojure/src/main/clj/cucumber/runtime/clj.clj
@@ -57,8 +57,8 @@
(defn- -disposeWorld [cljb])
-(defn- -getSnippet [cljb step]
- (.getSnippet snippet-generator step))
+(defn- -getSnippet [cljb step _]
+ (.getSnippet snippet-generator step nil))
(defn- -setUnreportedStepExecutor [cljb executor]
"executor")
View
45 clojure/src/test/java/cucumber/runtime/clojure/ClojureSnippet.java
@@ -1,45 +0,0 @@
-package cucumber.runtime.clojure;
-
-import cucumber.runtime.snippets.Snippet;
-
-import java.util.List;
-
-import static cucumber.runtime.snippets.SnippetGenerator.untypedArguments;
-
-/**
- * This class is only here to test clojure snippets in isolation.
- * Keep the template in sync with clj.clj
- */
-public class ClojureSnippet implements Snippet {
- @Override
- public String template() {
- return "({0} #\"{1}\" [{3}]\n" +
- " (comment {4} )\n" +
- " (throw (cucumber.api.PendingException.)))\n";
- }
-
- @Override
- public String tableHint() {
- return null;
- }
-
- @Override
- public String arguments(List<Class<?>> argumentTypes) {
- return untypedArguments(argumentTypes).replaceAll(",", "");
- }
-
- @Override
- public String namedGroupStart() {
- return null;
- }
-
- @Override
- public String namedGroupEnd() {
- return null;
- }
-
- @Override
- public String escapePattern(String pattern) {
- return pattern.replace("\"", "\\\"");
- }
-}
View
6 clojure/src/test/java/cucumber/runtime/clojure/ClojureSnippetTest.java
@@ -1,6 +1,6 @@
package cucumber.runtime.clojure;
-import cucumber.runtime.snippets.SnippetGenerator;
+import cucumber.runtime.clj.Backend;
import gherkin.formatter.model.Comment;
import gherkin.formatter.model.DataTableRow;
import gherkin.formatter.model.Step;
@@ -18,7 +18,7 @@
@Test
public void generatesPlainSnippet() {
Step step = new Step(NO_COMMENTS, "Given ", "I have 4 cukes in my \"big\" belly", 0, null, null);
- String snippet = new SnippetGenerator(new ClojureSnippet()).getSnippet(step, null);
+ String snippet = (new Backend(null)).getSnippet(step, null);
String expected = "" +
"(Given #\"^I have (\\d+) cukes in my \\\"([^\\\"]*)\\\" belly$\" [arg1 arg2]\n" +
" (comment Write code here that turns the phrase above into concrete actions )\n" +
@@ -30,7 +30,7 @@ public void generatesPlainSnippet() {
public void generatesSnippetWithDataTable() {
List<DataTableRow> dataTable = asList(new DataTableRow(NO_COMMENTS, asList("col1"), 1));
Step step = new Step(NO_COMMENTS, "Given ", "I have:", 0, dataTable, null);
- String snippet = new SnippetGenerator(new ClojureSnippet()).getSnippet(step, null);
+ String snippet = (new Backend(null)).getSnippet(step, null);
String expected = "" +
"(Given #\"^I have:$\" [arg1]\n" +
" (comment Write code here that turns the phrase above into concrete actions )\n" +
Something went wrong with that request. Please try again.