Case class context in specs2 acceptance tests: "must not be a member of Int"

I am using specs2 (v1.8.2) with Scala (v2.9.1) to write acceptance tests. Following the example http://etorreborre.github.com/specs2/guide/org.specs2.guide.SpecStructure.html#Contexts , I have the following class of specs and context cases:

import org.specs2._


class testspec extends SpecificationWithJUnit { def is =

    "test should" ^
        "run a test in a context" ! context().e1

}

case class context() {

    def e1 = 1 must beEqualTo(1)
}

      

I am getting compiler error:

error: value must not be a member Int def e1 = 1 must be EqualTo (1)

when compiling a case context class.

Obviously I'm new to specs2 (and Scala). Links to related documentation are appreciated.

+3


source to share


2 answers


Obviously the document is wrong (wrong, I corrected it now).

The correct way of writing to declare a case class for a context is generally to include it in scope Specification

:



import org.specs2._

class ContextSpec extends Specification { def is =
  "this is the first example" ! context().e1

  case class context() {
    def e1 = List(1,2,3) must have size(3)
  }
}

      

Otherwise, if you want to reuse the context in another specification, you can, as Dario wrote, access the functions MustMatchers

either by importing object methods MustMatchers

or by inheriting a trait MustMatchers

.

+3


source


must is not a member of Int because "must" is not known in the context of your "context" class. Place the "e1" method inside the spec class and it should work. For example.

import org.specs2._

class TestSpec extends Specification { def is =
  "test should" ^
    "run a test in a context" ! e1 ^
    end

  def e1 = 1 must beEqualTo(1)

}

      

change



Ah, I see what you want ;-). It should work like this:

In order to match the context classes, you need to import MustMatchers.

import org.specs2._
import matcher.MustMatchers._

class ContextSpec extends Specification { def is =
  "this is the first example" ! context().e1
}

case class context() {
  def e1 = List(1,2,3) must have size(3)
}

      

+2


source







All Articles