Skip to content

Commit

Permalink
Update README for Swift 3.0
Browse files Browse the repository at this point in the history
This reverts commit 2ddd3af.
  • Loading branch information
kylef committed Sep 28, 2016
1 parent 2661dd9 commit 6efca19
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Mockingjay has full integration to XCTest and you simply just need to register a

```swift
let body = [ "user": "Kyle" ]
stub(uri("/{user}/{repository}"), builder: json(body))
stub(uri("/{user}/{repository}"), json(body))
```

The `uri` function takes a URL or path which can have a [URI Template](https://github.com/kylef/URITemplate.swift). Such as the following:
Expand All @@ -32,22 +32,24 @@ The `uri` function takes a URL or path which can have a [URI Template](https://g

```swift
let body = [ "description": "Kyle" ]
stub(http(.PUT, uri: "/kylef/Mockingjay"), builder: json(body))
stub(http(.PUT, "/kylef/Mockingjay"), json(body))
```

#### Stubbing everything request to result in an error

```swift
let error = NSError(domain: "Mockingjay Session Tests", code: 0, userInfo: nil)
stub(everything, builder: failure(error))
let error = NSError()
stub(everything, failure(error))
```

#### Stub with a specific HTTP response

```swift
stub(everything, builder: http(404, headers: nil, data: nil))
stub(everything, http(status: 404))
```

*Note, the `http` builder can take a set of headers and a body too.*

## Stub

The `stub` method in Mockingjay takes two functions or closures, one to match the request and another to build the response. This allows you to easily extend the syntax to provide your own specific functions.
Expand All @@ -65,7 +67,7 @@ func matcher(request:NSURLRequest) -> Bool {
return true // Let's match this request
}

stub(matcher, builder: failure(error))
stub(matcher, failure(error))
```

### Builders
Expand All @@ -78,7 +80,7 @@ func builder(request:NSURLRequest) -> Response {
return .Success(response, .NoContent)
}

stub(matcher, builder: builder)
stub(matcher, builder)
```

### Generics
Expand Down

0 comments on commit 6efca19

Please sign in to comment.