I have a method inside my Controller that I want to unit test using Spec2.
object MyController extends Controller with MyAuth {
def article(id: String) = {
authenticate {
......
}
}
}
authenticate
is defined in MyAuth
. This function gets the token if available or authenticates and gets the token. I want to mock authenticate
while unit testing article
. I am not sure how to proceed with this. Any pointers will be helpful.
UPDATE: My approach so far. I saw this question and overrode authenticate method in MyAuth trait.
trait MyAuthMock {
this: MyAuth =>
override def authenticate ....
}
I also changed MyController
to have class and companion object. Then in my test I used the controller as follows
new MyController with MyAuthMock