alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Play Framework/Scala example source code file (DevErrorPageSpec.scala)

This example Play Framework source code file (DevErrorPageSpec.scala) is included in my "Source Code Warehouse" project. The intent of this project is to help you more easily find Play Framework (and Scala) source code examples by using tags.

All credit for the original source code belongs to Play Framework; I'm just trying to make examples easier to find. (For my Scala work, see my Scala examples and tutorials.)

Play Framework tags/keywords

api, deverrorpagespec, fakeapplication, oops, play, play framework, playspecification, test

The DevErrorPageSpec.scala Play Framework example source code

package play.it.views

import play.api.test.PlaySpecification

import play.api.test._
import play.api.DefaultGlobal
import java.lang.String
import scala.Predef.String

object DevErrorPageSpec extends PlaySpecification{


  "devError.scala.html" should {

    val testExceptionSource = new play.api.PlayException.ExceptionSource("test","making sure the link shows up") {
      def line = 100.asInstanceOf[Integer]
      def position = 20.asInstanceOf[Integer]
      def input = "test"
      def sourceName = "someSourceFile"
    }

    "link the error line if play.editor is configured" in {
        try {
          System.setProperty("play.editor", "someEditorLinkWith %s:%s")
          val result = DefaultGlobal.onError(FakeRequest(), testExceptionSource)
          Helpers.contentAsString(result) must contain("""href="someEditorLinkWith someSourceFile:100" """)
        } finally {
          System.clearProperty("play.editor")
        }
    }

    "show prod error page in prod mode" in {
      val fakeApplication = new FakeApplication() {
        override val mode = play.api.Mode.Prod
      }
      running(fakeApplication) {
        val result = DefaultGlobal.onError(FakeRequest(), testExceptionSource)
        Helpers.contentAsString(result) must contain("Oops, an error occurred")
      }
    }
  }

}

Other Play Framework source code examples

Here is a short list of links related to this Play Framework DevErrorPageSpec.scala source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.