Skip to content

Commit

Permalink
migrated to Specs2 2.3.7, using macro matchers
Browse files Browse the repository at this point in the history
  • Loading branch information
shaiyallin committed Dec 26, 2013
1 parent 179dac2 commit 9bba35d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 30 deletions.
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ organization := "com.wix"

scalaVersion := "2.10.3"

scalacOptions ++= Seq("-unchecked", "-deprecation", "-feature")
scalacOptions ++= Seq("-unchecked", "-deprecation", "-feature", "-language:experimental.macros")

resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"

libraryDependencies ++= Seq(
"org.slf4j" % "slf4j-api" % "1.7.5",
"com.twitter" %% "util-core" % "6.3.6",
"org.specs2" %% "specs2" % "2.3.6" % "test",
"org.specs2" %% "specs2" % "2.3.7" % "test",
"org.jmock" % "jmock" % "2.6.0" % "test"
)

Expand Down
38 changes: 10 additions & 28 deletions src/test/scala/com/wix/async/FuturePerfectTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import com.twitter.util.{CountDownLatch, TimeoutException, Await}
* @since 11/5/12
*/

class FuturePerfectTest extends SpecificationWithJUnit with Mockito with NoTimeConversions {
class FuturePerfectTest extends SpecificationWithJUnit with Mockito with NoTimeConversions with MatcherMacros {

sequential

Expand All @@ -43,20 +43,20 @@ class FuturePerfectTest extends SpecificationWithJUnit with Mockito with NoTimeC
"report success duration with default execution name" in new AsyncScope {
Await.result(execution(timeout) { /* do nothing on purpose */ })

there was one(reporter).report(forSuccess(be_==("async")))
there was one(reporter).report(matchA[Successful].executionName("async"))
}


"report success duration with custom execution name" in new AsyncScope {
Await.result(execution(timeout = timeout, name = "foo") { /* do nothing on purpose */ })

there was one(reporter).report(forSuccess(be_==("foo")))
there was one(reporter).report(matchA[Successful].executionName("foo"))
}

"report time spent in queue" in new AsyncScope {
Await.result(execution(timeout) { /* do nothing on purpose */ })

there was one(reporter).report(forTimeSpentInQueue())
there was one(reporter).report(matchA[TimeSpentInQueue])
}

"report when timed out while in queue" in new AsyncScope {
Expand All @@ -67,7 +67,7 @@ class FuturePerfectTest extends SpecificationWithJUnit with Mockito with NoTimeC
val f = execution(timeout) { /* do nothing on purpose */ }

Await.result(f) must throwA[TimeoutGaveUpException]
there was one(reporter).report(forTimeoutWhileInQueue())
there was one(reporter).report(matchA[TimeoutWhileInQueue])

executorService.runUntilIdle()
}
Expand All @@ -79,7 +79,7 @@ class FuturePerfectTest extends SpecificationWithJUnit with Mockito with NoTimeC
}
Await.result(f) must throwA(error)

there was one(reporter).report(forFailure(error))
there was one(reporter).report(matchA[Failed].error(error))
}

"timeout when blocking function stalls" in new AsyncScope {
Expand All @@ -90,8 +90,8 @@ class FuturePerfectTest extends SpecificationWithJUnit with Mockito with NoTimeC
Await.result(f) must throwA[TimeoutGaveUpException]
bar.release()

there was one(reporter).report(forExceededTimeout())
there was one(reporter).report(forGaveUp())
there was one(reporter).report(matchA[ExceededTimeout])
there was one(reporter).report(matchA[GaveUp])
}

"retry on timeout" in new AsyncScope {
Expand All @@ -101,7 +101,7 @@ class FuturePerfectTest extends SpecificationWithJUnit with Mockito with NoTimeC
Await.result(f) must beTrue
bar.times must_== 2

there was one(reporter).report(forRetrying(1))
there was one(reporter).report(matchA[Retrying].remainingRetries(1))
}

"retry on expected error" in new AsyncScope {
Expand All @@ -113,7 +113,7 @@ class FuturePerfectTest extends SpecificationWithJUnit with Mockito with NoTimeC
Await.result(f) must beTrue
bar.times must_== 2

there was one(reporter).report(forRetrying(1))
there was one(reporter).report(matchA[Retrying].remainingRetries(1))
}

"give up after retrying up to the limit" in new AsyncScope {
Expand Down Expand Up @@ -220,24 +220,6 @@ class FuturePerfectTest extends SpecificationWithJUnit with Mockito with NoTimeC
}

val bar = new Bar

def forSuccess(matchName: Matcher[String] = AlwaysMatcher()): Matcher[Event] = beLike {
case Successful(_, name) => name must matchName
}
def forFailure(error: Throwable): Matcher[Event] = beLike {
case Failed(_, theError, _) => theError must_== error
}
def forExceededTimeout(matchDuration: Matcher[Duration] = AlwaysMatcher()): Matcher[Event] = beLike {
case ExceededTimeout(actual, _) => actual must matchDuration
}

def forGaveUp(): Matcher[Event] = beAnInstanceOf[GaveUp]
def forTimeSpentInQueue(): Matcher[Event] = beAnInstanceOf[TimeSpentInQueue]
def forTimeoutWhileInQueue(): Matcher[Event] = beAnInstanceOf[TimeoutWhileInQueue]

def forRetrying(times: Int): Matcher[Event] = beLike {
case Retrying(_, remaining, _) => remaining must_== times
}
}

val timeout = 100 millis
Expand Down

0 comments on commit 9bba35d

Please sign in to comment.