value should is not a member of String - Scala2.10 - scala

I want to cross compile my project across different Scala versions (2.10, 2.11, 2.12). I get this error message while compiling specs for 2.10 only. 2.11 and 2.12 work fine:
value should is not a member of String
Spec class looks as follows:
class ClassNameSpec extends WordSpec with Matchers {
// ...
}
I have also tried changing WordSpec to FlatSpec and still getting same error.
Using gradle - build.gradle has following related dependencies:
classpath 'gradle.plugin.com.github.maiflai:gradle-scalatest:0.19'
compile "org.scala-lang:scala-library:${scalaVersion}"
compile "org.scalactic:scalactic${scalaVersionSuffix}:3.0.5"
testRuntime 'org.pegdown:pegdown:1.4.2'
How can I make WordSpec or FlatSpec with Matchers work for Scala2.10? If not, what's the best work around?

Related

scalatest - can't expand macros compiled by previous versions of Scala

So we have a Scala program (built using Maven) we want to test using Scalatest. We're running Scala 2.11.8 and Scalatest 3.0.1 (we've tried 3.0.3 to no avail)
When our tests run anything with the assert() macro, we get the following error:
error: can't expand macros compiled by previous versions of Scala
assert(true)
^
It points to the true but the issue is with anything we put into assert(). Our POM has the following dependency for Scalatest:
<dependency>
<groupId>org.scalatest</groupId>
<artifactId>scalatest_2.11</artifactId>
<version>3.0.1</version>
<scope>test</scope>
</dependency>
The code we're trying to execute is:
import org.scalatest.{FlatSpec, _}
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
#RunWith(classOf[JUnitRunner])
class Testing extends FlatSpec {
//test
var number = 0;
"An empty Set" should "have size 0" in {
assert(true)
}
}
Lot's of folks say this is an issue with using Scala 2.11 but including the 2.10 dependency, but we're using the 2.11 one. Any help would be much appreciated. I should also note we tried it using Scala 2.10, and it worked.
Run mvn dependency:tree and find out which dependencies have _2.10 in it.
Use Dependency management to ensure the _2.11 is included, and _2.10
is excluded.

When running tests from "sbt test" the classpath is different than when running from IDEA

I have the following simple test:
class ClasspathTest extends FlatSpec with Matchers {
"The classpath" should "have more than one member" in {
System.getProperty("java.class.path").split(":").length should be > 1
}
}
This resides in an sbt project. When running this from IDEA, this test succeeds because it contains all the libraryDependencies I specified in build.sbt.
However, when doing sbt test it fails because it only contains /opt/sbt/bin/sbt-launch.jar.
Now I have a test which depends on this runtime classpath being fully populated.
Is it possible to populate it somehow?
This is a duplicate of Real SBT Classpath at Runtime
To make it work, I have to include in my build.sbt:
fork in Test := true

Why does 2.11.1 fail with error: not found: type Application?

I'm trying to compile the following code:
object Main extends Application{
println("Hello World");
}
But I'm getting this error:
/Users/xx/JavaProjects/ScalaApplication1/src/scalaapplication1/Main.scala:8: error: not found: type Application
object Main extends Application{
^
one error found
I'm using Scala 2.11.1.
Application has been deprecated from scala 2.9, probably it has been deleted in scala 2.11 (it still exists in scala 2.10) even though at the moment I can't find proofs for that, use App instead.
Proof found, this is the scala 2.11 branch on github which has only an App.scala and this is the 2.10 which has App.scala and Application.scala with a deprecated warning.
You need to extends the App trait, the Application trait doesn't exists.
How i've done compile:
object Main extends App{
println("Hello World");
}

Scalatest and scalamock - dependency trouble involving SuiteMixin

I'm trying to setup my project to use scalatest and scalamock.
I'm using scala version 2.10.0.
However, I cant seem to get the dependencies right.
I've started with this code:
class ControllerTest extends org.scalatest.FunSuite
with org.scalamock.scalatest.MockFactory {}
I've tried two combinations of versions:
1)
org.scalatest : scalatest_2.10 : 1.9.1
org.scalamock: scalamock-scalatest-support_2.10 : 3.0.1
This is what I get:
scala: bad symbolic reference.
A signature in MockFactory.class refers to type SuiteMixin in package org.scalatest which is not available.
It may be completely missing from the current classpath, or the version on the classpath might be incompatible with the version used when compiling MockFactory.class.
Note: in the scalamock documentation, the artifact id is specified without the trailing _2.10, but maven couldn't find any artifact named like this. Also, I couldn't find on their site what scalatest version should be used with scalamock.
2)
org.scalatest : scalatest_2.10 : 1.9.1
org.scalamock: scalamock-scalatest-support_2.10.0-RC5: 3.0-M8
The compiler says:
scala: overriding method nestedSuites in trait SuiteMixin of type => scala.collection.immutable.IndexedSeq[org.scalatest.Suite];
method nestedSuites in trait Suite of type => List[org.scalatest.Suite] has incompatible type
class ControllerTest extends FunSuite with MockFactory {
and
scala: class ControllerTest needs to be abstract, since:
it has 5 unimplemented members.
/** As seen from class ControllerTest, the missing signatures are as follows.
* For convenience, these are usable as stub implementations.
*/
def rerunner: Option[String] = ???
def run(testName: Option[String],args: org.scalatest.Args): org.scalatest.Status = ???
protected def runNestedSuites(args: org.scalatest.Args): org.scalatest.Status = ???
protected def runTest(testName: String,args: org.scalatest.Args): org.scalatest.Status = ???
protected def runTests(testName: Option[String],args: org.scalatest.Args): org.scalatest.Status = ???
So, what's up with this SuiteMixin trait?
If I use scalatest-support_2.10.0-RC5:3.0-M8, it appears to exist in scalatest lib.
If I use scalatest-support_2.10:3.0.1, it seems to have gone from said scalatest lib.
What kind of sorcery is this? And, more importantly, what version combination should I use to make it work?
Thanks!
If you have this dependency
"org.scalamock" %% "scalamock-scalatest-support" % "3.0.1" % "test"
It will automatically download the correct version of scalatest. In this case it's
org.scalatest#scalatest_2.10;2.0.M5b!scalatest_2.10.jar
In most cases where one library depends upon another you just add only that one library as dependency. Sbt-like tools will get the other dependencies.
EECOLOR's answer is correct. To elaborate, the cause of the problem was that the ScalaMock version you chose was compiled against a later version of ScalaTest (2.0.M5b) than the one you were explicitly trying to use (1.9.1).

Error in scala + dispatch

I am trying to GET a response from an API, using scala and dispatch. However, I get this error, after building. I googled for a solution, and tried cleaning, and resarting eclipse, but the error wont go away. What seems to be the problem? I use eclipse Helios (ie 3.6) and Scala v2.8.1, with Scala IDE v1.0.0.201104170033, installed from the Eclipse market.
dispatch{dispatch.type}.Http{object dispatch.Http} of type object dispatch.Http does not take parameters
This is my code.
class getList {
def main(args: Array[String]){
Http("http://foo.com/" >>> System.out)
}
}
What am I doing wrong?
What libraries have you downloaded? Are you sure the dependencies are set correctly? I tried with dispatch_http, version 8.0 for Scala 2.8.1, and it worked.
What imports are you using? I used these imports to make it work:
import dispatch.Http
import dispatch.HandlerVerbs._
Finally... class getList??? I assume this is a result of cut&pasting from actual code, but you should strive to produce a compilable example of your problem. Scala doesn't run programs from class, only from object, and it follows Java style of having classes start with an uppercase letter.
Here's the minimal code I used with SBT to get a working example.
Initializing:
~/test$ sbt
Project does not exist, create new project? (y/N/s) y
Name: test
Organization: test
Version [1.0]:
Scala version [2.7.7]: 2.8.1
sbt version [0.7.4]:
~/test$ cat project/build/TestProject.scala
import sbt._
class TestProject(info: ProjectInfo) extends DefaultProject(info) {
val dvers = "0.8.0"
val http = "net.databinder" %% "dispatch-http" % dvers
}
~/test$ cat src/main/scala/GetList.scala
import dispatch.Http
import dispatch.HandlerVerbs._
object GetList {
def main(args: Array[String]){
Http("http://foo.com/" >>> System.out)
}
}
~/test# sbt update run