I thing you got the basics there. However mocking Objects can be a bit trick. First off somewhere in your code you are going to call
val inbox = Settings("inbox_path")
This does not use the mocked object, it will use the real object.
So the way I do it is the following:
1) Create a Setting trait that has all the methods
2) Something like
object Setting {
def getCurrent: Setting = {
// return an instance setting
}
def setInstance(newSetting: Setting) {
}
}
So now on the Test you mock the trait and inject it in your object:
"show have inbox" in {
val mS = mock[Setting]
ms.appy("inbox_path") returns ("Value for this test")
Setting.setInstance(mS)
do_test()
}
In do_test() you can call like this:
Setting.getInstance("inbox_path")
Now since its just a trait it's easy to mock. You still avoid dependency injection.
This is how I've done it.
Other way is to pass the Setting train to the constructor of the object and have a default that grabs setting like this:
class SomeConfiguredObject(setting: Setting) {
def this() = this(Setting.getInstance)
}
Thomas