These are chat archives for etorreborre/specs2

15th
Apr 2015
Daniel Capo Sobral
@dcsobral
Apr 15 2015 00:36
Wasn’t there are way to write an acceptance test specification where you’d show the input, and feed it into the test method?
I can’t find anything on the new and revised Specs2 docs. And maybe that thing is gone.
Not GWT, though. Just something like {2} plus {2} must equal {4} ${_ + _ === _}
Eric Torreborre
@etorreborre
Apr 15 2015 00:39
In the simplest form you can write
class TestSpec extends Specification with ScalaCheck { def is = s2"""

 hello $test

"""

  def test = { description: String =>
    description must_== "hello"
  }
}
Daniel Capo Sobral
@dcsobral
Apr 15 2015 00:40
Interesting.
Eric Torreborre
@etorreborre
Apr 15 2015 00:40
I need to check what’s available to write what you wish to write. This might be possible by reusing some classes from the GWT spec
Daniel Capo Sobral
@dcsobral
Apr 15 2015 00:40
How is that displayed?
Eric Torreborre
@etorreborre
Apr 15 2015 00:41
[info] TestSpec
[info]
[info]  + hello
[info]
[info] Total for specification TestSpec
[info] Finished in 72 ms
[info] 1 example, 0 failure, 0 error
Daniel Capo Sobral
@dcsobral
Apr 15 2015 00:41
Well, that’s suboptimal, because I have different inputs for different stuff.
Eric Torreborre
@etorreborre
Apr 15 2015 00:56
With a bit of work I can integrate something like that
class TestSpec extends Specification with ScalaCheck { def is = s2"""

 {1} plus {1} is {2} $test

"""

  def test = groupAs("\\d+").and { (s1: String, s2: String, s3: String) =>
    s1.toInt + s2.toInt must_== s3.toInt
  }
}
and the {} would be removed on display
Daniel Capo Sobral
@dcsobral
Apr 15 2015 04:38
@etorreborre I got Specs completely frozen trying to use the first thing.
I had this:
class CommitParserTest extends Specification {
  override def is =
    s2"""
          Basic elements
          ==============

          It should parse correctly
            8f23d788faa3dd12038fcf1b9e6534bf24d9244e $hashOk
            Daniel Sobral                            $nameOk
            <dsobral@richrelevance.com>              $$emailOk
            1429053662 -0600                         $$timestampOk



      """

  def hashOk = { description: String =>
    new CommitParser(description).Hash.run() must beASuccessfulTry(description)
  }
  def nameOk = { description: String =>
    new CommitParser(description).Name.run() must beASuccessfulTry(description)
  }
  def emailOk = { description: String =>
    new CommitParser(description).Email.run() must beASuccessfulTry(description)
  }
  def timestampOk = { description: String =>
    new CommitParser(description).Timestamp.run() must beASuccessfulTry(description)
  }
}
If there’s only one $method, it works. As soon as I add the second, it stops working.
Eric Torreborre
@etorreborre
Apr 15 2015 04:44
This works ok for me
btw you don’t need to write override def, def is enough
Daniel Capo Sobral
@dcsobral
Apr 15 2015 04:51
Weird. It doesn’t work here at all. Completely freezes everything.
Eric Torreborre
@etorreborre
Apr 15 2015 04:51
what happens if you remove all your test code and replace it with ok?
Daniel Capo Sobral
@dcsobral
Apr 15 2015 04:57
Aha! If I have only one thing calling my test code, it works. If I have two of my tests at the same time, it doesn’t.
btw, when I try your example it can’t find groupAs
And the problem turned out to be new CommitParser(description).Name.run(). THAT freezes up stuff.
Eric Torreborre
@etorreborre
Apr 15 2015 05:01
groupAs comes from import org.specs2.specification.script.StepParsers._
ok that’s good to know :-)
Daniel Capo Sobral
@dcsobral
Apr 15 2015 05:18
New error. I have this:
class CommitParserTest extends Specification with ScalaCheck {
  override def is =
    s2"""
          Basic elements
          ==============

          It should parse correctly
            {8f23d788faa3dd12038fcf1b9e6534bf24d9244e} $hashOk
            {Daniel Sobral}                            $$nameOk
            {dsobral@richrelevance.com}                $$emailOk
            {1429053662 -0600}                         $$timestampOk



      """

  def hashOk = groupAs(".*").and { pattern: String =>
//    new CommitParser(pattern).Hash.run() must beASuccessfulTry(pattern)
    pattern must beEqualTo(pattern)
  }
  def nameOk = groupAs(".*").and { description: String =>
//    new CommitParser("description").Name.run() must beASuccessfulTry(description)
    skipped
  }
  def emailOk = groupAs(".*").and { description: String =>
    new CommitParser(description).Email.run() must beASuccessfulTry(description)
  }
  def timestampOk = groupAs(".*").and { description: String =>
    new CommitParser(description).Timestamp.run() must beASuccessfulTry(description)
  }
}
So I disabled the three other tests. The only thing being called is hashOk, but I get this message when trying to compile:
[error] /Users/dsobral/src/gitTools/src/test/scala/com/rr/tools/git/parser/CommitParserTest.scala:13: type mismatch;
[error]  found   : org.specs2.specification.script.StepParsers.ReadAs#ReadAsParser[org.specs2.matcher.MatchResult[String]]
[error]  required: org.specs2.specification.create.InterpolatedFragment
[error]             {8f23d788faa3dd12038fcf1b9e6534bf24d9244e} $hashOk
[error]                                                         ^
Eric Torreborre
@etorreborre
Apr 15 2015 05:22
that’s because my changes are not yet published :-)
Daniel Capo Sobral
@dcsobral
Apr 15 2015 05:25
Oh, changes. You are a sneaky one! :)