Skip to content

Instantly share code, notes, and snippets.

@erikvanoosten
Created July 1, 2011 17:40
Show Gist options
  • Save erikvanoosten/1059045 to your computer and use it in GitHub Desktop.
Save erikvanoosten/1059045 to your computer and use it in GitHub Desktop.
Example of a specs2 unit test, with mocks and rich context
import org.specs2.mutable._
import org.specs2.mock._
import org.specs2.specification.Scope
class ParentElementStrategyTest extends SpecificationWithJUnit with Mockito {
"The ParentElementStrategy" should {
"extract a user ref" in new SimpleContext {
val testColumn = mock[Column]
registry.get("urn:grons.nl:user:9475877") returns testColumn
userStrategy("user").getShardForEntity(ad, columns) must beTheSameAs(testColumn)
}
}
trait SimpleContext extends Scope {
val registry = mock[Registry]
def userStrategy(element: String) = {
val userStrategy = new ParentElementStrategy(element)
userStrategy.setRegistry(registry)
userStrategy
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment