Skip to content

Commit 8fc61d3

Browse files
committed
Add specs2 matcher
1 parent 610cc28 commit 8fc61d3

File tree

6 files changed

+84
-9
lines changed

6 files changed

+84
-9
lines changed

build.sbt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,30 @@ import PgpKeys.{publishLocalSigned, publishSigned}
22
import com.typesafe.sbt.SbtGit.GitKeys._
33

44
organization := "software.purpledragon.xml"
5-
version := "0.0.1"
5+
version := "0.0.2"
66

77
scalaVersion := "2.12.3"
88
crossScalaVersions := Seq("2.11.11", "2.12.3")
99

1010
// dependencies common for all sub-projects
1111
libraryDependencies ++= Seq(
12-
"org.scala-lang.modules" %% "scala-xml" % "1.0.6",
13-
"org.scalatest" %% "scalatest" % "3.0.4" % "test"
12+
"org.scala-lang.modules" %% "scala-xml" % "1.0.6"
1413
)
1514

16-
lazy val xmlCompare = project
17-
.in(file("xml-compare"))
15+
lazy val xmlCompare = Project("xml-compare", file("xml-compare"))
1816

19-
lazy val xmlScalatest = project
20-
.in(file("xml-scalatest"))
17+
lazy val xmlScalatest = Project("xml-scalatest", file("xml-scalatest"))
18+
.dependsOn(xmlCompare)
19+
20+
lazy val xmlSpecs2 = Project("xml-specs2", file("xml-specs2"))
2121
.dependsOn(xmlCompare)
2222

2323
lazy val root = project
2424
.in(file("."))
2525
.aggregate(
2626
xmlCompare,
27-
xmlScalatest
27+
xmlScalatest,
28+
xmlSpecs2
2829
)
2930
.settings(
3031
publish := {},

xml-compare/build.sbt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
name := "xml-compare"
2+
3+
libraryDependencies ++= Seq(
4+
"org.scalatest" %% "scalatest" % "3.0.4" % "test"
5+
)

xml-scalatest/build.sbt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
name := "xml-scalatest"
22

3-
// need to build against scalatest
43
libraryDependencies ++= Seq(
54
"org.scalatest" %% "scalatest" % "3.0.4" % "provided"
65
)

xml-specs2/build.sbt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
name := "xml-specs2"
2+
3+
libraryDependencies ++= Seq(
4+
"org.specs2" %% "specs2-core" % "3.9.4" % "provided"
5+
)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package software.purpledragon.xml.specs2
2+
3+
import org.specs2.matcher.Matcher
4+
import org.specs2.matcher.MatchersImplicits._
5+
import software.purpledragon.xml.compare.XmlCompare
6+
7+
import scala.xml.Node
8+
9+
trait XmlMatchers {
10+
def beXml(expected: Node): Matcher[Node] = { actual: Node =>
11+
val diff = XmlCompare.compare(expected, actual)
12+
13+
(diff.isEqual, "XML matched", s"XML did not match - ${diff.message}")
14+
}
15+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright 2017 Michael Stringer
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package software.purpledragon.xml.specs2
18+
19+
import org.specs2.matcher.Expectations
20+
import org.specs2.mutable.Specification
21+
22+
class XmlMatchersSpec extends Specification with XmlMatchers with Expectations {
23+
24+
"beXml" should {
25+
"match identical XML" in {
26+
val matcher = beXml(<test>text</test>)
27+
28+
val matchResult = matcher(createExpectable(<test>text</test>))
29+
matchResult.isSuccess === true
30+
}
31+
32+
"match XML with different whitespace" in {
33+
val matcher = beXml(<test>text</test>)
34+
35+
val matchResult = matcher(createExpectable(
36+
<test>
37+
text
38+
</test>))
39+
matchResult.isSuccess === true
40+
}
41+
42+
"not match different XML" in {
43+
val matcher = beXml(<test>text</test>)
44+
45+
val matchResult = matcher(createExpectable(<test>different</test>))
46+
matchResult.isSuccess === false
47+
matchResult.message === "XML did not match - different text - text != different"
48+
}
49+
}
50+
}
51+

0 commit comments

Comments
 (0)