Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/giginet/jsonmatcher
A JSON matcher extension in Swift for Nimble
https://github.com/giginet/jsonmatcher
Last synced: 3 months ago
JSON representation
A JSON matcher extension in Swift for Nimble
- Host: GitHub
- URL: https://github.com/giginet/jsonmatcher
- Owner: giginet
- License: mit
- Created: 2016-04-22T14:31:56.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-06-01T21:57:57.000Z (over 7 years ago)
- Last Synced: 2024-09-17T23:37:49.630Z (4 months ago)
- Language: Swift
- Homepage:
- Size: 98.6 KB
- Stars: 14
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
JSONMatcher
=================[![Build Status](https://travis-ci.org/giginet/JSONMatcher.svg?branch=master)](https://travis-ci.org/giginet/JSONMatcher)
[![codecov](https://codecov.io/gh/giginet/JSONMatcher/branch/master/graph/badge.svg)](https://codecov.io/gh/giginet/JSONMatcher)
[![CocoaPods Compatible](https://img.shields.io/cocoapods/v/JSONMatcher.svg)](https://img.shields.io/cocoapods/v/JSONMatcher.svg)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
[![Swift Package Manager](https://img.shields.io/badge/Swift%20Package%20Manager-compatible-brightgreen.svg)](https://github.com/apple/swift-package-manager)
[![Platform](https://img.shields.io/cocoapods/p/JSONMatcher.svg?style=flat)](http://cocoadocs.org/docsets/JSONMatcher)JSONMatcher is a JSON matcher library for Swift testing. It works as an extension for [Nimble](https://github.com/Quick/Nimble/).
This library is inspired by [rspec-json_matcher](https://github.com/r7kamura/rspec-json_matcher).
## Usage
### Example
```swift
import XCTest
import Nimble
import JSONMatcherclass 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```swift
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`.
```ruby
use_frameworks!target "YourApplicationTests" do
pod 'JSONMatcher'
end
```## Author
giginet <>
## License
MIT License