-
Notifications
You must be signed in to change notification settings - Fork 2
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
1 parent
610cc28
commit 8fc61d3
Showing
6 changed files
with
84 additions
and
9 deletions.
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
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,5 @@ | ||
name := "xml-compare" | ||
|
||
libraryDependencies ++= Seq( | ||
"org.scalatest" %% "scalatest" % "3.0.4" % "test" | ||
) |
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,6 +1,5 @@ | ||
name := "xml-scalatest" | ||
|
||
// need to build against scalatest | ||
libraryDependencies ++= Seq( | ||
"org.scalatest" %% "scalatest" % "3.0.4" % "provided" | ||
) |
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,5 @@ | ||
name := "xml-specs2" | ||
|
||
libraryDependencies ++= Seq( | ||
"org.specs2" %% "specs2-core" % "3.9.4" % "provided" | ||
) |
15 changes: 15 additions & 0 deletions
15
xml-specs2/src/main/scala/software/purpledragon/xml/specs2/XmlMatchers.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,15 @@ | ||
package software.purpledragon.xml.specs2 | ||
|
||
import org.specs2.matcher.Matcher | ||
import org.specs2.matcher.MatchersImplicits._ | ||
import software.purpledragon.xml.compare.XmlCompare | ||
|
||
import scala.xml.Node | ||
|
||
trait XmlMatchers { | ||
def beXml(expected: Node): Matcher[Node] = { actual: Node => | ||
val diff = XmlCompare.compare(expected, actual) | ||
|
||
(diff.isEqual, "XML matched", s"XML did not match - ${diff.message}") | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
xml-specs2/src/test/scala/software/purpledragon/xml/specs2/XmlMatchersSpec.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,51 @@ | ||
/* | ||
* Copyright 2017 Michael Stringer | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package software.purpledragon.xml.specs2 | ||
|
||
import org.specs2.matcher.Expectations | ||
import org.specs2.mutable.Specification | ||
|
||
class XmlMatchersSpec extends Specification with XmlMatchers with Expectations { | ||
|
||
"beXml" should { | ||
"match identical XML" in { | ||
val matcher = beXml(<test>text</test>) | ||
|
||
val matchResult = matcher(createExpectable(<test>text</test>)) | ||
matchResult.isSuccess === true | ||
} | ||
|
||
"match XML with different whitespace" in { | ||
val matcher = beXml(<test>text</test>) | ||
|
||
val matchResult = matcher(createExpectable( | ||
<test> | ||
text | ||
</test>)) | ||
matchResult.isSuccess === true | ||
} | ||
|
||
"not match different XML" in { | ||
val matcher = beXml(<test>text</test>) | ||
|
||
val matchResult = matcher(createExpectable(<test>different</test>)) | ||
matchResult.isSuccess === false | ||
matchResult.message === "XML did not match - different text - text != different" | ||
} | ||
} | ||
} | ||
|