Skip to content

Instantly share code, notes, and snippets.

@williamho
Last active November 5, 2015 18:22
Show Gist options
  • Select an option

  • Save williamho/928b31f5709d142fc8d6 to your computer and use it in GitHub Desktop.

Select an option

Save williamho/928b31f5709d142fc8d6 to your computer and use it in GitHub Desktop.
ficus
import org.specs2.mutable._
import com.typesafe.config._
import net.ceedubs.ficus.Ficus._
import net.ceedubs.ficus.readers.ArbitraryTypeReader._
class HelloSpec extends Specification {
case class MyConfig(
key1: String,
key2: String,
key3: String = "a default string")
val config1 = ConfigFactory.parseString("""
somePath {
key1: hello
key2: world
# key3 is unspecified
}
""")
val config2 = ConfigFactory.parseString("""
somePath {
key1: goodbye
# key2 is unspecified
key3: fallback
}
""")
"something" in {
config1.as[MyConfig]("somePath") must_== MyConfig("hello", "world", "a default string")
config2.as[MyConfig]("somePath") must throwA[com.typesafe.config.ConfigException.Missing] // key2 is required
val merged1 = (config1 withFallback config2).as[MyConfig]("somePath")
merged1 must_== MyConfig("hello", "world", "fallback")
val merged2 = (config2 withFallback config1).as[MyConfig]("somePath")
merged2 must_== MyConfig("goodbye", "world", "fallback")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment