Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions OHHTTPStubs/Sources/Swift/OHHTTPStubsSwift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,15 @@ public func fixture(filePath: String, status: Int32 = 200, headers: [NSObject: A
* - Returns: The opaque `OHHTTPStubsDescriptor` that uniquely identifies the stub
* and can be later used to remove it with `removeStub:`
*/
#if swift(>=3.0)
public func stub(condition: @escaping OHHTTPStubsTestBlock, response: @escaping OHHTTPStubsResponseBlock) -> OHHTTPStubsDescriptor {
return OHHTTPStubs.stubRequests(passingTest: condition, withStubResponse: response)
}
#else
public func stub(condition: OHHTTPStubsTestBlock, response: OHHTTPStubsResponseBlock) -> OHHTTPStubsDescriptor {
return OHHTTPStubs.stubRequests(passingTest: condition, withStubResponse: response)
}
#endif



Expand Down Expand Up @@ -275,9 +281,15 @@ public func hasHeaderNamed(_ name: String, value: String) -> OHHTTPStubsTestBloc
*
* - Returns: a matcher (`OHHTTPStubsTestBlock`) that succeeds if either of the given matchers succeeds
*/
#if swift(>=3.0)
public func || (lhs: @escaping OHHTTPStubsTestBlock, rhs: @escaping OHHTTPStubsTestBlock) -> OHHTTPStubsTestBlock {
return { req in lhs(req) || rhs(req) }
}
#else
public func || (lhs: OHHTTPStubsTestBlock, rhs: OHHTTPStubsTestBlock) -> OHHTTPStubsTestBlock {
return { req in lhs(req) || rhs(req) }
}
#endif

/**
* Combine different `OHHTTPStubsTestBlock` matchers with an 'AND' operation.
Expand All @@ -287,9 +299,15 @@ public func || (lhs: OHHTTPStubsTestBlock, rhs: OHHTTPStubsTestBlock) -> OHHTTPS
*
* - Returns: a matcher (`OHHTTPStubsTestBlock`) that only succeeds if both of the given matchers succeeds
*/
#if swift(>=3.0)
public func && (lhs: @escaping OHHTTPStubsTestBlock, rhs: @escaping OHHTTPStubsTestBlock) -> OHHTTPStubsTestBlock {
return { req in lhs(req) && rhs(req) }
}
#else
public func && (lhs: OHHTTPStubsTestBlock, rhs: OHHTTPStubsTestBlock) -> OHHTTPStubsTestBlock {
return { req in lhs(req) && rhs(req) }
}
#endif

/**
* Create the opposite of a given `OHHTTPStubsTestBlock` matcher.
Expand All @@ -298,6 +316,12 @@ public func && (lhs: OHHTTPStubsTestBlock, rhs: OHHTTPStubsTestBlock) -> OHHTTPS
*
* - Returns: a matcher (OHHTTPStubsTestBlock) that only succeeds if the expr matcher fails
*/
#if swift(>=3.0)
public prefix func ! (expr: @escaping OHHTTPStubsTestBlock) -> OHHTTPStubsTestBlock {
return { req in !expr(req) }
}
#else
public prefix func ! (expr: OHHTTPStubsTestBlock) -> OHHTTPStubsTestBlock {
return { req in !expr(req) }
}
#endif