Latest 0.1.0
Homepage https://github.com/giginet/JSONMatcher
License MIT
Platforms ios 8.0, osx 10.9, tvos 9.0, requires ARC
Dependencies Nimble
Authors

Build Status
codecov
CocoaPods Compatible
Carthage compatible
Swift Package Manager
Platform

JSONMatcher is a JSON matcher library for Swift testing. It works as an extension for Nimble.

This library is inspired by rspec-json_matcher.

Usage

Example

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()],
            ]
        ]))
    }
}

Matcher

  • beJSON
  • beJSONIncluding
  • beJSONAs
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]))

Requirements

Supported Swift Version

  • Swift 2.2

Dependencies

  • Nimble >= 4.0.0

Supported Platforms

  • iOS 8.0 or above
  • OSX 10.9 or above
  • tvOS 9.0 or above

Installation

Carthage

Declare following in your Cartfile.private.

github "giginet/JSONMatcher"

CocoaPods

Declare following in your Podfile.

use_frameworks!

target "YourApplicationTests" do
  pod 'JSONMatcher'
end

Author

giginet >

License

MIT License

Latest podspec

{
    "name": "JSONMatcher",
    "version": "0.1.0",
    "summary": "A JSON matcher extension for Nimble",
    "description": "JSONMatcher is a JSON matcher library for Swift testing. It works as an extension for Nimble.",
    "homepage": "https://github.com/giginet/JSONMatcher",
    "license": {
        "type": "MIT",
        "file": "LICENSE.md"
    },
    "authors": {
        "giginet": "[email protected]"
    },
    "social_media_url": "http://twitter.com/giginet",
    "platforms": {
        "ios": "8.0",
        "osx": "10.9",
        "tvos": "9.0"
    },
    "source": {
        "git": "https://github.com/giginet/JSONMatcher.git",
        "tag": "v0.1.0"
    },
    "source_files": "Sources/JSONMatcher/**/*.{swift,h,m}",
    "weak_frameworks": "XCTest",
    "requires_arc": true,
    "dependencies": {
        "Nimble": [
            "~> 4.0.0"
        ]
    },
    "pod_target_xcconfig": {
        "ENABLE_BITCODE": "NO",
        "OTHER_LDFLAGS": "-weak-lswiftXCTest",
        "FRAMEWORK_SEARCH_PATHS": "$(inherited) "$(PLATFORM_DIR)/Developer/Library/Frameworks""
    }
}

Pin It on Pinterest

Share This