Created
August 4, 2013 15:35
-
-
Save mzkrelx/6150705 to your computer and use it in GitHub Desktop.
specs2 の事前処理、事後処理
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package views.admin.mlproposals | |
| import org.specs2.mutable.After | |
| import org.specs2.mutable.Specification | |
| import org.specs2.specification.AfterExample | |
| import org.specs2.specification.BeforeExample | |
| import org.specs2.specification.Scope | |
| import play.api.test.Helpers.HTMLUNIT | |
| import play.api.test.Helpers.running | |
| import play.api.test.TestServer | |
| class IntegrationSpec extends Specification with BeforeExample with AfterExample { | |
| def before = { | |
| println("==== before ====") | |
| } | |
| def after = { | |
| println("==== after ====") | |
| } | |
| "Application" should { | |
| "work from within a browser" in new TestScope { | |
| running(TestServer(3333), HTMLUNIT) { browser => | |
| browser.goTo("http://localhost:3333/") | |
| browser.waitUntil[Boolean]{ | |
| browser.pageSource contains ("Hello") | |
| } | |
| } | |
| } | |
| } | |
| "Application2" should { | |
| "work from within a browser" in { | |
| running(TestServer(3333), HTMLUNIT) { browser => | |
| browser.goTo("http://localhost:3333/") | |
| browser.waitUntil[Boolean]{ | |
| browser.pageSource contains ("World") | |
| } | |
| } | |
| } | |
| } | |
| trait TestScope extends Scope with After { | |
| println("**** before ****") | |
| def after = { | |
| println("**** after ****") | |
| } | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
play2 + scala で specs2 の事前処理、事後処理をしたいときのサンプル
TestScope は、個別にやりたいときだけ BeforeAfter したいときに in の後に書いて使う。
複数のScopeを定義して使い分けもできる感じ。
全テスト固定の処理でよい場合は BeforeExample と AfterExample をミックスインして before・after メソッドを定義する。
サンプルの実行結果