Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I run Scala + specs2 from the command line?

I'm a completely newbie Scala programmer, and I have no previous experience with Java; I come from ruby. I'm trying to run my first TDD sample program. I'm planning something very small, with maybe 5 or 6 tests. I'm trying to use the specs2 lib. I have no IDE, I usually program with vim and execute stuff from the command line.

How do I work with scala & specs2 on my little .scala file from the command line?

In the Quick Start they mention this:

scala -cp ... specs2.run HelloWorldSpec
  1. I don't have any idea what that elipsis (...) is standing for. What do I have to put there?
  2. That command references (I assume) a file called specs2.run. But on the downloads section I only get a .jar file. Where is specs2.run?
  3. In the dependencies section I'm given between two technologies - sbt and maven (I googled for them, didn't know them before). Do I have to use sbt/maven no matter what? Can't I just use a console command? It's only 1 file with 5 tests.
  4. I'm aware that there is a sample app, but again it comes with no instructions on how to run it. I think it comes prepared to work with sbt and maven. I would rather not have to learn to use any of those just to make a quick test. Is it possible?

Thanks a lot.

like image 468
kikito Avatar asked Oct 22 '11 23:10

kikito


1 Answers

Welcome to scala and specs2!

  1. The ... stands for the paths to all the jars you need to run the specifications, including your own (or a path to a directory containing the .class files). Those jars are listed on the Runners page. For a simple specification you only need scalaz-core, scalaz-concurrent and specs2.

  2. specs2.run is the full name of the class used to run your specification on the command line. So, a full command to run a specification looks like:

    scala -cp scalaz-core.jar:scalaz-concurrent.jar:specs2.jar:your-classes-directory specs2.run YourSpecification

  3. You can indeed use the command line only without sbt or maven if you know where to get the jars you need and how to compile your scala classes (using the scalac command)

  4. yes, the sample app comes with sbt and maven project files so that running the tests just takes sbt test for example. If you do that, sbt installs all the required dependencies, compiles the classes and runs the tests. I think that this is the best way to get started (follow the sbt install guide, it's really fast IMHO) but again, for a simple project you can also do that manually

like image 111
Eric Avatar answered Oct 29 '22 11:10

Eric