Perl 6 language design documents Perl 6 Design Documents

Scala testing: What's the status and relationship of SUnit, ScalaTest, ScalaCheck, Specs and ParTest?

Scala provides a choice of different testing frameworks, but I wonder if there are differences in the maturity and stability they have and which distinct features they provide.

Is there a specific one which should fit for all kinds of development?

Can the different frameworks inter-operate with each other or with test runners targeted for other languages?

Source: (StackOverflow)

Guide to writing specs in Erlang

In open source projects I see the following two ways of writing specs:

Specs in comments

@spec start_link() -> {ok, pid()}

Specs in source code

-spec start_link() -> {ok, pid()}

What's the difference? Is one preferred over the other?

Source: (StackOverflow)

What specs does one need for a good iPhone app development environment?

I'm going to buy a new mac to develop iPhone apps (previously been programming them at work on their iMac).

What do you think the minimum and recommended specs are?

Is 2 GB of RAM plenty for XCode, interface builder and the simulator to all run simultaneously? What if I'm also running a browser with 10 tabs and Photoshop with a few smallish images open?

The fact that I haven't found any recommendations elsewhere suggests that I have little to worry about, but as a student this is a large purchase for me. I need to be careful.


Source: (StackOverflow)

In Scala Specs, what is the "must" function?

I'm working with some Specs tests and I'm trying to understand what the "must" function is, and what it does.

I am unable to find its declaration or implementation anywhere in the specs source, and I'm trying to understand what it does.

Here are some example usages of it:

"hello world".size must be equalTo(11)
"hello world" must be matching("h.* w.*")
stack.push(11) must throwAn[Error]

It looks to me like "must" takes a function as an argument, but I'd like to know the actual signature of "must", and what it does with its argument.

Can anyone point me in the right direction?


Source: (StackOverflow)

Selenium, specs and scala

I'm looking an info or some project for selenium testing with scala specs. How can I call selenium tests from my scala specs code?

Source: (StackOverflow)

Unit-testing Spring applications using Scala's Specs

We have a large infrastructure that's highly dependent on Spring Framework. Recently I began writing code in Scala and test it using Specs. This is all great but at some point I need to use Spring-dependent features (Such as a HibernateDaoSupport-based DAO).

Has anyone managed to use the SpringJUnit4ClassRunner class to run Specs tests? Does anyone have a different direction as to how to achieve this goal?


Source: (StackOverflow)

BDD tool for Scala supporting reusable parameterized Gherkin clauses

Is there any BDD tool for Scala supporting reusable parameterized Gherkin clauses?

I would like to be able to have the ability to use specs like these:

Given number 4 is entered
When "+" is pressed
And number -1 is entered
And "*" is pressed
And number 2 is entered
And "=" is pressed
Then result is 6

And I would like to define fixtures to Gherkin clauses differing by a parameter only once, something like:

scenario("(4+(-1)) * 2 = 6") {

  given("number 4 is entered")
  when("'+' is pressed")
  and("number -1 is entered")
  and("'*' is pressed")
  and("number 2 is entered")
  and("'=' is pressed")
  then("result is 0")

Given definitions of clauses looking like as follows:

"number $number is entered" {
"'$key' is pressed" {
"result is $number" {
    assert(calculator.getDisplayedNumber === number)

I looked through ScalaTest and Specs manuals but I didn't find such feature. ScalaTest seems to be able to reuse the defined clause in a different scenario, but looks like it is not parameterised.

Do you know some tools that does support what I want, or e.g. some extensions to ScalaTest, or a way to extend it myself with such result?

Source: (StackOverflow)

Using the "should NOT produce [exception]" syntax in ScalaTest

I'am toying with Specs2 and ScalaTest for BDD in Scala. I've written expectations in Specs2 when I am asserting that a given exception should not be thrown.

"do something" in {
 } must not(throwA[MyException])

I was hoping to be able to write the equivalent in ScalaTest like:

"do something" in {
 evaluating {
 } should not produce[MyException]

But this does not compile and I could not find way of doing it. Is that even possible?

Many thanks in advance.

Source: (StackOverflow)

Is there a specs matcher that will unbox Option and Either

I've created a specs test, to validate some JSON parsing. Although the test works perfecly well, it feels rather noisy.

I wonder if there is existing code in Specifications to unbox Option and Either?

"twitter json to Scala class mapper" should {
    "parsing a tweet" in {
      TwitterJsonMapper.tweetP(tweetS) match {
        case Right(t: Tweet) => {
          implicit def unOption[T](t: Option[T]): T = t.get
          implicit def unEither[T](t: Either[T,Throwable]): T = t match {case Left(left) => left ;case Right(t) => throw t}
          "test id" in {
            true must_== (t.id.get == 228106060337135617l)
          "test id_str" in {
            true must_== (t.id_str.get == "228106060337135617")
          "test time" in {
            true must_== (t.created_at.getHours == 13 )
        case Left((pe: JsonParseException, reason: String)) => fail(reason + "\n" + pe)

 //The Tweet is produced from JSON using Fasterxml's Jackson-Scala library. 
 //I want to use Option or Either monads over all child attributes - for the usual reasons.
case class Tweet(
  @BeanProperty contributors: Option[String],
  @BeanProperty coordinates: Option[String],

  @BeanProperty @JsonDeserialize (
      using = classOf[TwitterDateDeserializer]
  ) created_at: Either[Date,Throwable],
  @BeanProperty favorited: Boolean = false,
  //elided etc etc
  @BeanProperty id_str: Option[String]

Source: (StackOverflow)

How does the "specs" BDD framework for Scala work?

I'm just getting started with Scala, and I'm wondering which language feature allows you to do this:

"PersistentQueue" should {
  "add and remove one item" in {
    withTempFolder {
      val q = new PersistentQueue(folderName, "work", Config.fromMap(Map.empty))

      q.length mustEqual 0
      q.totalItems mustEqual 0
      q.bytes mustEqual 0
      q.journalSize mustEqual 0

      q.add("hello kitty".getBytes)

      q.length mustEqual 1
      q.totalItems mustEqual 1
      q.bytes mustEqual 11
      q.journalSize mustEqual 32

      new String(q.remove.get.data) mustEqual "hello kitty"

      q.length mustEqual 0
      q.totalItems mustEqual 1
      q.bytes mustEqual 0
      q.journalSize mustEqual 33

      dumpJournal("work") mustEqual "add(11:0:hello kitty), remove"

That's from the unit tests for Kestrel.

What's going on here? Does "PersistentQueue" should mean that the Scala string class has been extended with a "should" method, or is something else happening here? I had a quick look through the Scala documentation but couldn't see which language features are being used for this code sample.

Source: (StackOverflow)

Exception matcher in Specs BDD library for Scala

Im using the Specs BDD library for writing Scala unit tests (http://code.google.com/p/specs) .In my code if i want to assert that a throws an exception of type ClassNotFoundException, then i can write the following code:

a must throwA[ClassNotFoundException]

However,i want to test the reverse case,i.e.i want to assert that a "does not" throw an exception of type ClassNotFoundException.

I tried using not negation matcher, as follows:

 a must throwA[ClassNotFoundException].not

But that didnt work. Im getting compilation errors. So, is there any way i can assert that an exception of type ClassNotFoundException for example, is not thrown ?

Please Help Thank You

Source: (StackOverflow)

How to use Specs2 with Scalacheck to automate testing of String arguments?

The rewritten specs2 testing framework for Scala integrates automated testing with scalacheck. The examples given in the specs2 documentation on how to use scalacheck together with specs2 either use integers or more complicated custom generators as in eric's json example.

While trying to get a slightly less complicated example working, I'm struggling because I don't know how one would use specs2 and scalacheck if I want to generate String arguments instead of Integers. How would this Quickstart example

import org.scalacheck._

object StringSpecification extends Properties("String") { property("startsWith") = Prop.forAll((a: String, b: String) => (a+b).startsWith(a))

property("endsWith") = Prop.forAll((a: String, b: String) => (a+b).endsWith(b))

// Is this really always true? property("concat") = Prop.forAll((a: String, b: String) => (a+b).length > a.length && (a+b).length > b.length )

property("substring") = Prop.forAll((a: String, b: String) => (a+b).substring(a.length) == b )

property("substring") = Prop.forAll((a: String, b: String, c: String) => (a+b+c).substring(a.length, a.length+b.length) == b ) }

taken from the scalacheck homepage look, if it was written as Specs2 specification using the scalacheck integration?

Source: (StackOverflow)

Creating a Specs2 matcher in a modular way

I have functions A => Double. I want to check whether two such functions give the same results (up to a tolerance, using the existing beCloseTo matcher) for a given set of values.

I want to be able to write:

type TF = A => Double
(f: TF) must computeSameResultsAs(g: TF,tolerance: Double, tests: Set[A])

I want to build this matcher in a modular way, not simply writing a Matcher[TF] from scratch.

It might be even nicer if I could write:

(f: TF) must computeSameResultsAs(g: TF)
               .onValues(tests: Set[A])

Also I want to get a reasonable description when the matcher fails.


After sleeping over it I came up with the following.

def computeSameResultsAs[A](ref: A => Double, tolerance: Double, args: Set[A]): Matcher[A => Double] = 
  args.map(beCloseOnArg(ref, tolerance, _)).reduce(_ and _)

def beCloseOnArg[A](ref: A => Double, tolerance: Double, arg: A): Matcher[A => Double] = 
  closeTo(ref(arg), tolerance) ^^ ((_: A => Double).apply(arg))

This is much shorter than Eric's solution but doesn't provide a good failure message. What I'd love to be able is rename the mapped value in the second method. Something like the following (which does not compile).

def beCloseOnArg[A](ref: A => Double, tolerance: Double, arg: A): Matcher[A => Double] = 
  closeTo(ref(arg), tolerance) ^^ ((_: A => Double).apply(arg) aka "result on argument " + arg)

Source: (StackOverflow)

Akka actors unit testing with Scala

I'm fairly new to Scala so please be gentle.

In the app I'm currently building, I'm using Akka actors and I want to write some unit tests. I came across this official documentation for writing unit tests for Akka actors

but I couldn't understand exactly how it should work. In particular,

val actorRef = TestActorRef(new MyActor)
// hypothetical message stimulating a '42' answer
val future = actorRef ? Say42
val Success(result: Int) = future.value.get
result must be(42)

When I try that, I get not found: value Success, which is not surprising.

I then found this example of how to test Scala actors

val actorRef = TestActorRef[TickTock]

implicit val timeout = Timeout(5 seconds)
val future = (actorRef ? new Tick("msg")).mapTo[String]
val result = Await.result(future, timeout.duration)

Assert.assertEquals("processed the tick message", result)

, which admittedly is possibly old, but it is easy to understand and closer to what I normally use when I want to use Futures, and most importantly works. It does require me to declare a few implicits like the ActorSystem, timeout and such, which doesn't seem to be the case with the official way...

If possible, I'd like to use the method proposed by the official documentation, so I would appreciate it if someone could help me understand how it works (in particular the Success bit) and how to use it.

Source: (StackOverflow)

How to get card specs programatically in CUDA

I'm just starting out with CUDA. Is there a way of getting the card specs programatically?

Source: (StackOverflow)