Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
133 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
language: scala | ||
|
||
scala: | ||
- 2.12.6 | ||
|
||
script: | ||
- sbt test | ||
|
||
before_cache: | ||
- find $HOME/.ivy2/cache -name "ivydata-*.properties" -print -delete | ||
- find $HOME/.sbt -name "*.lock" -print -delete |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name := "scalatest-structured-before" | ||
organization := "com.github.bigwheel" | ||
version := "1.0" | ||
scalaVersion := "2.12.6" | ||
|
||
libraryDependencies ++= Seq( | ||
"org.scalactic" %% "scalactic" % "[3.0.5,)", | ||
"org.scalatest" %% "scalatest" % "[3.0.5,)", | ||
"org.scalaz" %% "scalaz-core" % "[7.2.26,)", | ||
) | ||
|
||
// about maven publish | ||
publishMavenStyle := true | ||
publishTo := { | ||
val nexus = "https://oss.sonatype.org/" | ||
if (isSnapshot.value) | ||
Some("snapshots" at nexus + "content/repositories/snapshots") | ||
else | ||
Some("releases" at nexus + "service/local/staging/deploy/maven2") | ||
} | ||
publishArtifact in Test := false | ||
licenses := Seq("BSD-3-Clause" -> url("https://github.com/bigwheel/scalatest-structured-before/blob/master/LICENSE")) | ||
homepage := Some(url("https://github.com/bigwheel/scalatest-structured-before")) | ||
pomExtra := ( | ||
<scm> | ||
<url>git@github.com:bigwheel/scalatest-structured-before.git</url> | ||
<connection>scm:git:git@github.com:bigwheel/scalatest-structured-before.git</connection> | ||
</scm> | ||
<developers> | ||
<developer> | ||
<id>bigwheel</id> | ||
<name>k.bigwheel</name> | ||
<url>https://github.com/bigwheel</url> | ||
</developer> | ||
</developers> | ||
) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
sbt.version = 1.2.1 | ||
sbt.version = 1.2.3 |
49 changes: 49 additions & 0 deletions
49
src/main/scala/com/github/bigwheel/scalatest/FunSpecEx.scala
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.github.bigwheel.scalatest | ||
|
||
import org.scalatest._ | ||
import org.scalactic._ | ||
|
||
import scalaz._ | ||
import Scalaz._ | ||
|
||
class FunSpecEx extends FunSpec { | ||
|
||
private[this] type Description = (String, () => Unit) | ||
private[this] type DescriptionOrTestTitle = \/[Description, String] | ||
private[this] var tree: Tree[DescriptionOrTestTitle] = ("", () => ()).left[String].node() | ||
|
||
override protected val it: ItWord = new ItWord() { | ||
override def apply(specText: String, testTags: Tag*)(testFun: => Any /* Assertion */)(implicit pos: source.Position): Unit = { | ||
tree = tree.loc.insertDownLast(\/-(specText).asInstanceOf[DescriptionOrTestTitle].leaf).toTree | ||
super.apply(specText, testTags: _*)(testFun)(pos) | ||
} | ||
} | ||
|
||
protected[this] def describeWithBefore(description: String) | ||
(before: => Unit) | ||
(fun: => Unit) | ||
(implicit pos: org.scalactic.source.Position): Unit = { | ||
val backup = tree | ||
tree = (description, before _).left[String].node() | ||
super.describe(description)(fun)(pos) | ||
tree = backup.loc.insertDownLast(tree).toTree | ||
} | ||
|
||
protected override def runTest(testName: String, args: Args): Status = { | ||
val targetTestLeaf: TreeLoc[DescriptionOrTestTitle] = tree.loc.find { treeLoc => | ||
val strOfDescriptionAndTest = treeLoc.path.reverse.map { | ||
case -\/(yyy) => yyy._1 | ||
case \/-(xxx) => xxx | ||
} | ||
strOfDescriptionAndTest.tail.mkString(" ") == testName | ||
}.get | ||
val descriptions: Seq[DescriptionOrTestTitle] = targetTestLeaf.path.reverse | ||
val befores: Seq[() => Unit] = descriptions.map { | ||
case -\/(yyy) => yyy._2 | ||
case \/-(_) => () => () | ||
} | ||
for (before <- befores) before() | ||
super.runTest(testName, args) | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
src/test/scala/com/github/bigwheel/scalatest/FunSpecExSpec.scala
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.github.bigwheel.scalatest | ||
|
||
import org.scalatest.Matchers | ||
|
||
class FunSpecExSpec extends FunSpecEx with Matchers { | ||
|
||
var subject: Int = _ | ||
|
||
describeWithBefore("When initialized by 0"){ subject = 0 } { | ||
it("is 0") { | ||
subject should be(0) | ||
} | ||
|
||
describeWithBefore("when + 5"){ subject += 5 } { | ||
it("is 5") { | ||
subject should be(5) | ||
} | ||
|
||
describeWithBefore("then - 3"){ subject -= 3 } { | ||
it("is 2") { | ||
subject should be(2) | ||
} | ||
it("also is even") { | ||
(2 % 2) should be (0) | ||
} | ||
} | ||
|
||
describeWithBefore("and * -1"){ subject *= -1 } { | ||
it("is -5") { | ||
subject should be(-5) | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |