Skip to content

Instantly share code, notes, and snippets.

@zerosum
Created December 12, 2019 15:13
Show Gist options
  • Save zerosum/311b02b1f3ef5dc44cfacc32be00c881 to your computer and use it in GitHub Desktop.
Save zerosum/311b02b1f3ef5dc44cfacc32be00c881 to your computer and use it in GitHub Desktop.
example of `ScalaTest` with `Airframe`
package dev.zerosum.sandbox.base
import java.time._
import wvlet.airframe._
trait DateTimeSupport {
private lazy val clock = bind[Clock]
def now: OffsetDateTime = OffsetDateTime.now(clock)
}
package dev.zerosum.sandbox.base
import java.time._
import org.scalatest.funspec.AnyFunSpec
import org.scalatest.matchers.should
import wvlet.airframe._
class DateTimeSupportSpec extends AnyFunSpec with should.Matchers {
private val design: Design =
newSilentDesign
.bind[Clock].toInstance(Clock.fixed(Instant.EPOCH, ZoneOffset.UTC))
private def tested[Actual](f: DateTimeSupport => Actual): Actual = {
design.build[DateTimeSupport](f).asInstanceOf[Actual]
}
describe("now") {
it("is the time!") {
val actual = tested(_.now)
val expected = OffsetDateTime.of(1970, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC)
actual should be(expected)
}
}
}
package dev.zerosum.sandbox
import java.time._
import wvlet.airframe._
package object base {
private[base] lazy val defaultOffset = ZoneOffset.UTC
private[base] lazy val defaultClock = Clock.system(defaultOffset)
val design: Design = newDesign
.bind[Clock].toInstance(defaultClock)
}
@zerosum
Copy link
Author

zerosum commented Dec 12, 2019

tested[Actual] の定義のところ、macroとか使いこなせればspec毎に書かなくても良くなるか?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment