paulbutcher/borachio — Issue #8: Non-text method names can't be mocked directly
Author: mseebach
Created: 2011-10-16 22:40:58+00:00
State: open

This does not work:

withExpectations {
val actor = mock[SpecializedLiftActor[String]]
actor expects '! withArgs ("bar") once()
actor ! "bar"
}

Resulting exception:

com.borachio.ExpectationException: Unexpected: '$bang with arguments: (bar)
at com.borachio.AbstractMockFactory$class.handleUnexpectedCall(AbstractMockFactory.scala:92)

The method is defined on the SpecializedLiftActor trait as such:

def !(msg: T): Unit = {
....
}

A functional work-around is simple, but it doesn't read terribly well:

withExpectations {
val actor = mock[SpecializedLiftActor[String]]
actor expects '$bang withArgs ("bar") once()
actor ! "bar"
}

Thanks,
Martin