twirl-spec documentation
twirl-spec is a ScalaTest toolkit for testing Twirl
views: a page model with named accessors, an expectation DSL that reads like
the page, rule sets that check accessibility and markup without a browser, and
failure messages that show what the template actually rendered.
The README is the reference: every expectation, matcher and rule is listed there, and the rule tables are held to the code by a test. The API documentation is the Scaladoc of all ten modules as one site. These pages are the guide.
| Page | Read it when |
|---|---|
| Getting started | you have never used the library: install it, write a first spec, read a failure |
| Writing view specs | you are writing specs and want the DSL explained control by control |
| Rules and standards | you want to know what the check traits enforce, how to select or exclude rules, and how to write your own |
| Languages and message files | your service renders in more than one language, or you want the message files themselves checked |
| Coverage and entry points | you want to know what a spec never looked at, and to reach the Twirl entry points nothing calls |
| Failure messages | a test is red and you want to read its output quickly |
| Adopting in an existing service | you have a home-grown spec base to replace, or are moving from 1.x or 2.x |
| Troubleshooting | something does not behave as you expected |
| For coding agents | an agent, or you, wants the whole adoption as a procedure: decisions, commands, a definition of done, and instructions to keep in the service |
Every page is also listed, for tools that read one, in
llms.txt.
Requirements
| Scala | 3.3.0 or any later Scala 3; on Java 21 or later, 3.3.0 needs -release set to an older Java, such as 11 or 17 |
| Java | 17 or later |
| Play | any 3.0.x; your project supplies it |
| ScalaTest | 3.2.20 or later |
The shortest possible start
libraryDependencies += "io.github.frikit" %% "twirl-spec-all" % "3.3.1" % Test
import io.github.frikit.twirlspec.{AllChecks, TwirlSpec}
import org.scalatest.matchers.must.Matchers
import org.scalatest.wordspec.AnyWordSpec
class SignUpViewSpec extends AnyWordSpec with Matchers with TwirlSpec with AllChecks {
private val view = inject[SignUpView]
private val form = inject[SignUpFormProvider].apply()
"SignUpView" should {
"render the question" in {
render(view(form)) must display(
title("signUp.title"),
heading("signUp.heading"),
textInput("email").labelled("signUp.email"),
submitButton(),
noErrors
)
}
}
}
That one display checks what it names and, because AllChecks is mixed in,
runs every rule in the library over the page as well.
Getting started takes it from there.