Skip to content

Instantly share code, notes, and snippets.

@nelanka
Last active August 29, 2015 14:27
Show Gist options
  • Save nelanka/9f151cbb0aa33fc796c9 to your computer and use it in GitHub Desktop.
Save nelanka/9f151cbb0aa33fc796c9 to your computer and use it in GitHub Desktop.
Scala Test Tips
// Retry until it succeeds
class ExampleSpec extends FlatSpec with Eventually {
eventually {
futureInt.get shouldBe 1
}
}
// Extended patience for integration tests
class ExampleSpec extends FlatSpec with Eventually with IntegrationPatience {
eventually {
futureInt.get shouldBe 1
}
}
// Wait for a future to complete rather than try repeatedly until it succeeds as in 'eventually'
class ExampleSpec extends FlatSpec with ScalaFutures {
whenReady(futureInt) { i =>
i should be(1)
}
}
// Get option values with meaningful errors
class ExampleSpec extends FlatSpec with OptionValues {
optString.value shouldBe "Hello"
}
// Look inside nested structures
case class Address(street: String, city: String, state: String, zip: String)
case class Name(first: String, middle: String, last: String)
case class Record(name: Name, address: Address, age: Int)
class ExampleSpec extends FlatSpec with Inside {
inside (rec) { case Record(name, address, age) =>
inside (name) { case Name(first, middle, last) =>
first should be ("Sally")
middle should be ("Ann")
last should be ("Jones")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment