TestsTested | ✓ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | May 2016 |
SPMSupports SPM | ✓ |
Maintained by giginet.
JSONMatcher is a JSON matcher library for Swift testing. It works as an extension for Nimble.
This library is inspired by rspec-json_matcher.
import XCTest
import Nimble
import JSONMatcher
class ExampleTestCase: XCTestCase {
func testComplexExample() {
expect([
"name" : "Snorlax",
"no" : 143,
"species" : "Sleeping",
"type" : ["normal"],
"stats" : [
"hp" : 160,
"attack" : 110,
"defense" : 65,
"special_attack" : 65,
"special_defense" : 65,
"speed" : 30
],
"moves" : [
["name" : "Tackle", "type" : "normal", "level" : 1],
["name" : "Hyper Beam", "type" : "normal", "level" : NSNull()],
]
]).to(beJSONAs([
"name" : "Snorlax",
"no" : Type.Number, // value type matching
"species" : try! NSRegularExpression(pattern: "[A-Z][a-z]+", options: []), // regular expression matching
"type" : ["[a-z]+".regex], // shorthands for NSRegularExpression
"stats" : [
"hp" : 160,
"attack" : 110,
"defense" : 65,
"special_attack" : 65,
"special_defense" : 65,
"speed" : 30
],
"moves" : [
["name" : "Tackle", "type" : "[a-z]+".regex, "level" : Type.Number], // nested collection
["name" : "Hyper Beam", "type" : "normal", "level" : NSNull()],
]
]))
}
}
expect("{\"name\": \"Pikachu\"}").to(beJSON())
expect(["name" : "Pikachu", "no" : 25]).to(beJSONIncluding(["name" : "Pikachu"]))
expect(["name" : "Pikachu", "no" : 25]).to(beJSONAs(["name": "Pikachu", "no" : 25]))
giginet <[email protected]>
MIT License