Created
December 12, 2019 15:13
-
-
Save zerosum/311b02b1f3ef5dc44cfacc32be00c881 to your computer and use it in GitHub Desktop.
example of `ScalaTest` with `Airframe`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
tested[Actual]
の定義のところ、macroとか使いこなせればspec毎に書かなくても良くなるか?