Scala 2.12 Step Parameters

66 views
Skip to first unread message

mi...@providencehr.com

unread,
Jan 13, 2017, 4:08:53 AM1/13/17
to Cukes
Has anyone had success using Scala 2.12? I've followed the instructions here


to get things working but am getting class cast exceptions on any step parameter that isn't a string. For example,

Feature: Scala 2.12 Test

Scenario: Test
Given a is equal to 1

class TestSteps extends ScalaDsl with EN {

Given("""^a is equal to (\d)$""") { (i: Int) =>
if (i == 1) println("Good") else throw new IllegalArgumentException(s"$i did not equal 1")
}

}

Results in 

java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer

at scala.runtime.BoxesRunTime.unboxToInt(BoxesRunTime.java:101)
at TestSteps.$anonfun$new$1$adapted(TestSteps.scala:8)
at cucumber.api.scala.ScalaDsl$StepBody$$anonfun$apply$2.applyOrElse(ScalaDsl.scala:98)
at cucumber.api.scala.ScalaDsl$StepBody$$anonfun$apply$2.applyOrElse(ScalaDsl.scala:96)
at scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:34)
at cucumber.runtime.scala.ScalaStepDefinition.execute(ScalaStepDefinition.scala:71)
at cucumber.runtime.StepDefinitionMatch.runStep(StepDefinitionMatch.java:37)
at cucumber.runtime.Runtime.runStep(Runtime.java:300)
at cucumber.runtime.model.StepContainer.runStep(StepContainer.java:44)
at cucumber.runtime.model.StepContainer.runSteps(StepContainer.java:39)
at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:44)
at cucumber.runtime.junit.ExecutionUnitRunner.run(ExecutionUnitRunner.java:102)
at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:63)
at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:18)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at cucumber.runtime.junit.FeatureRunner.run(FeatureRunner.java:70)
at cucumber.api.junit.Cucumber.runChild(Cucumber.java:95)
at cucumber.api.junit.Cucumber.runChild(Cucumber.java:38)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at cucumber.api.junit.Cucumber.run(Cucumber.java:100)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:237)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
at ✽.Given a is equal to 1(Test.feature:4)

 

Paolo Ambrosio

unread,
Jan 14, 2017, 5:59:15 PM1/14/17
to cu...@googlegroups.com
On Fri, Jan 13, 2017 at 5:10 AM, <mi...@providencehr.com> wrote:
Has anyone had success using Scala 2.12? I've followed the instructions here




Can you try with the scala-2.12-with-java-8 branch on my cucumber-jvm repo?

https://github.com/paoloambrosio/cucumber-jvm/commits/scala-2.12-with-java-8

I've changed the build to compile only cucumber-scala_2.12 and cucumber-java8 as Java 8 bytecode, and the rest as Java 6 bytecode.

I've also upgraded Scala from 2.12.0-M1 to the latest 2.12.1 on cucumber-scala_2.12, and making tests pass.

The scala-calculator example works, so hopefully it will work in your case as well.

Code could be made much better, but I was careful not to change too much at this stage.


Cheers,
Paolo

--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

mi...@providencehr.com

unread,
Jan 15, 2017, 6:25:29 AM1/15/17
to Cukes
Thank you Paulo. Your branch worked perfectly for me at least. 
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+un...@googlegroups.com.

Paolo Ambrosio

unread,
Jan 15, 2017, 8:26:54 AM1/15/17
to cu...@googlegroups.com
Great news!

I've also created a PR to fix Scala 2.12 support: https://github.com/cucumber/cucumber-jvm/pull/1091

To unsubscribe from this group and stop receiving emails from it, send an email to cukes+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages