Commit 38ac0bee authored by Stefan van den Oord's avatar Stefan van den Oord

Updated Nimble to rc2

parent 827802b2
......@@ -14,15 +14,15 @@ pod 'NetUtils', '~> 1.0'
target 'PulseTests' do
pod 'Quick', '~> 0.2'
pod 'Nimble', '2.0.0-rc.1'
pod 'Nimble', '2.0.0-rc.2'
end
target 'PulseIntegrationTests' do
pod 'Quick', '~> 0.2'
pod 'Nimble', '2.0.0-rc.1'
pod 'Nimble', '2.0.0-rc.2'
end
target 'PulseSystemTests' do
pod 'Quick', '~> 0.2'
pod 'Nimble', '2.0.0-rc.1'
pod 'Nimble', '2.0.0-rc.2'
end
......@@ -4,9 +4,9 @@ PODS:
- IGDigest (1.1.2)
- lz4 (128)
- NetUtils (1.0)
- Nimble (2.0.0-rc.1)
- Nimble (2.0.0-rc.2)
- OpenSSL-Framework (1.0.201)
- Quick (0.5.0)
- Quick (0.5.1)
- SwiftBytes (0.2.0)
DEPENDENCIES:
......@@ -15,7 +15,7 @@ DEPENDENCIES:
- IGDigest (~> 1.1.0)
- lz4 (~> 128)
- NetUtils (~> 1.0)
- Nimble (= 2.0.0-rc.1)
- Nimble (= 2.0.0-rc.2)
- OpenSSL-Framework (~> 1.0.201)
- Quick (~> 0.2)
- SwiftBytes (~> 0.2.0)
......@@ -26,9 +26,9 @@ SPEC CHECKSUMS:
IGDigest: 066753c10f3f1b593b00037b9ee93dc96b9e7762
lz4: 5e066195ca751d552becaa026f8fe213ff738adf
NetUtils: a83e4d66bd9b62a7e8d09f71b1e7159c5f71b44f
Nimble: 9572458605e65c9fc5a56754ab19a970f6ab5a88
Nimble: e3cf5e73a491daf21c2bc88783dbfc55ce8b8e02
OpenSSL-Framework: f10c6aa8a92f69fca94303c3774b4773860a9690
Quick: 45494d91b43b34346217879491853ee3ca073f5d
Quick: 7426537a99e75076d6930c5b6da58006e4a9f38a
SwiftBytes: a700beb32d020abedd3fc3bb4f0e3b5444cb18b6
COCOAPODS: 0.38.0
COCOAPODS: 0.38.2
../../../Base32/Base32/MF_Base32Additions.h
\ No newline at end of file
../../../CocoaAsyncSocket/RunLoop/AsyncSocket.h
\ No newline at end of file
../../../CocoaAsyncSocket/RunLoop/AsyncUdpSocket.h
\ No newline at end of file
../../../CocoaAsyncSocket/GCD/GCDAsyncSocket.h
\ No newline at end of file
../../../CocoaAsyncSocket/GCD/GCDAsyncUdpSocket.h
\ No newline at end of file
../../../IGDigest/IGDigest/HMAC/IGHMAC.h
\ No newline at end of file
../../../IGDigest/IGDigest/Digest/NSData+MD5Digest.h
\ No newline at end of file
../../../IGDigest/IGDigest/Digest/NSData+SHA1Digest.h
\ No newline at end of file
../../../IGDigest/IGDigest/Digest/NSData+SHA256Digest.h
\ No newline at end of file
../../../IGDigest/IGDigest/Digest/NSString+MD5Digest.h
\ No newline at end of file
../../../IGDigest/IGDigest/HMAC/NSString+MD5HMAC.h
\ No newline at end of file
../../../IGDigest/IGDigest/Digest/NSString+SHA1Digest.h
\ No newline at end of file
../../../IGDigest/IGDigest/HMAC/NSString+SHA1HMAC.h
\ No newline at end of file
../../../IGDigest/IGDigest/Digest/NSString+SHA256Digest.h
\ No newline at end of file
../../../IGDigest/IGDigest/HMAC/NSString+SHA256HMAC.h
\ No newline at end of file
../../../Nimble/Nimble/objc/DSL.h
\ No newline at end of file
../../../Nimble/Nimble/objc/NMBExceptionCapture.h
\ No newline at end of file
../../../Nimble/Nimble/Nimble.h
\ No newline at end of file
../../../Quick/Quick/DSL/QCKDSL.h
\ No newline at end of file
../../../Quick/Quick/Quick.h
\ No newline at end of file
../../../Quick/Quick/Configuration/QuickConfiguration.h
\ No newline at end of file
../../../Quick/Quick/QuickSpec.h
\ No newline at end of file
../../../lz4/lib/lz4.h
\ No newline at end of file
../../../lz4/lib/lz4frame.h
\ No newline at end of file
../../../lz4/lib/lz4frame_static.h
\ No newline at end of file
../../../lz4/lib/lz4hc.h
\ No newline at end of file
../../../lz4/lib/xxhash.h
\ No newline at end of file
......@@ -4,9 +4,9 @@ PODS:
- IGDigest (1.1.2)
- lz4 (128)
- NetUtils (1.0)
- Nimble (2.0.0-rc.1)
- Nimble (2.0.0-rc.2)
- OpenSSL-Framework (1.0.201)
- Quick (0.5.0)
- Quick (0.5.1)
- SwiftBytes (0.2.0)
DEPENDENCIES:
......@@ -15,7 +15,7 @@ DEPENDENCIES:
- IGDigest (~> 1.1.0)
- lz4 (~> 128)
- NetUtils (~> 1.0)
- Nimble (= 2.0.0-rc.1)
- Nimble (= 2.0.0-rc.2)
- OpenSSL-Framework (~> 1.0.201)
- Quick (~> 0.2)
- SwiftBytes (~> 0.2.0)
......@@ -26,9 +26,9 @@ SPEC CHECKSUMS:
IGDigest: 066753c10f3f1b593b00037b9ee93dc96b9e7762
lz4: 5e066195ca751d552becaa026f8fe213ff738adf
NetUtils: a83e4d66bd9b62a7e8d09f71b1e7159c5f71b44f
Nimble: 9572458605e65c9fc5a56754ab19a970f6ab5a88
Nimble: e3cf5e73a491daf21c2bc88783dbfc55ce8b8e02
OpenSSL-Framework: f10c6aa8a92f69fca94303c3774b4773860a9690
Quick: 45494d91b43b34346217879491853ee3ca073f5d
Quick: 7426537a99e75076d6930c5b6da58006e4a9f38a
SwiftBytes: a700beb32d020abedd3fc3bb4f0e3b5444cb18b6
COCOAPODS: 0.38.0
COCOAPODS: 0.38.2
......@@ -43,14 +43,14 @@ public class AssertionRecorder : AssertionHandler {
/// Once the closure finishes, then the original Nimble assertion handler is restored.
///
/// @see AssertionHandler
public func withAssertionHandler(tempAssertionHandler: AssertionHandler, closure: () -> Void) {
public func withAssertionHandler(tempAssertionHandler: AssertionHandler, closure: () throws -> Void) {
let oldRecorder = NimbleAssertionHandler
let capturer = NMBExceptionCapture(handler: nil, finally: ({
NimbleAssertionHandler = oldRecorder
}))
NimbleAssertionHandler = tempAssertionHandler
capturer.tryBlock {
closure()
try! closure()
}
}
......@@ -64,7 +64,7 @@ public func withAssertionHandler(tempAssertionHandler: AssertionHandler, closure
/// assertion handler when this is true. Defaults to false.
///
/// @see gatherFailingExpectations
public func gatherExpectations(silently: Bool = false, closure: () -> Void) -> [AssertionRecord] {
public func gatherExpectations(silently silently: Bool = false, closure: () -> Void) -> [AssertionRecord] {
let previousRecorder = NimbleAssertionHandler
let recorder = AssertionRecorder()
let handlers: [AssertionHandler]
......@@ -91,9 +91,9 @@ public func gatherExpectations(silently: Bool = false, closure: () -> Void) -> [
///
/// @see gatherExpectations
/// @see raiseException source for an example use case.
public func gatherFailingExpectations(silently: Bool = false, closure: () -> Void) -> [AssertionRecord] {
let assertions = gatherExpectations(silently, closure: closure)
public func gatherFailingExpectations(silently silently: Bool = false, closure: () -> Void) -> [AssertionRecord] {
let assertions = gatherExpectations(silently: silently, closure: closure)
return assertions.filter { assertion in
!assertion.success
}
}
\ No newline at end of file
}
......@@ -3,7 +3,7 @@ import Foundation
/// Only classes, protocols, methods, properties, and subscript declarations can be
/// bridges to Objective-C via the @objc keyword. This class encapsulates callback-style
/// asynchronous waiting logic so that it may be called from Objective-C and Swift.
@objc internal class NMBWait {
internal class NMBWait: NSObject {
internal class func until(timeout timeout: NSTimeInterval, file: String = __FILE__, line: UInt = __LINE__, action: (() -> Void) -> Void) -> Void {
var completed = false
var token: dispatch_once_t = 0
......@@ -15,11 +15,17 @@ import Foundation
}
return completed
}
if result == PollResult.Failure {
switch (result) {
case .Failure:
let pluralize = (timeout == 1 ? "" : "s")
fail("Waited more than \(timeout) second\(pluralize)", file: file, line: line)
} else if result == PollResult.Timeout {
case .Timeout:
fail("Stall on main thread - too much enqueued on main run loop before waitUntil executes.", file: file, line: line)
case let .ErrorThrown(error):
// Technically, we can never reach this via a public API call
fail("Unexpected error thrown: \(error)", file: file, line: line)
case .Success:
break
}
}
......
/// Make an expectation on a given actual value. The value given is lazily evaluated.
public func expect<T>(@autoclosure(escaping) expression: () -> T?, file: String = __FILE__, line: UInt = __LINE__) -> Expectation<T> {
public func expect<T>(@autoclosure(escaping) expression: () throws -> T?, file: String = __FILE__, line: UInt = __LINE__) -> Expectation<T> {
return Expectation(
expression: Expression(
expression: expression,
......@@ -8,7 +8,7 @@ public func expect<T>(@autoclosure(escaping) expression: () -> T?, file: String
}
/// Make an expectation on a given actual value. The closure is lazily invoked.
public func expect<T>(file: String = __FILE__, line: UInt = __LINE__, expression: () -> T?) -> Expectation<T> {
public func expect<T>(file: String = __FILE__, line: UInt = __LINE__, expression: () throws -> T?) -> Expectation<T> {
return Expectation(
expression: Expression(
expression: expression,
......
import Foundation
internal func expressionMatches<T, U where U: Matcher, U.ValueType == T>(expression: Expression<T>, matcher: U, to: String) -> (Bool, FailureMessage) {
internal func expressionMatches<T, U where U: Matcher, U.ValueType == T>(expression: Expression<T>, matcher: U, to: String, description: String?) -> (Bool, FailureMessage) {
let msg = FailureMessage()
msg.userDescription = description
msg.to = to
let pass = matcher.matches(expression, failureMessage: msg)
if msg.actualValue == "" {
msg.actualValue = "<\(stringify(expression.evaluate()))>"
do {
let pass = try matcher.matches(expression, failureMessage: msg)
if msg.actualValue == "" {
msg.actualValue = "<\(stringify(try expression.evaluate()))>"
}
return (pass, msg)
} catch let error {
msg.actualValue = "an unexpected error thrown: <\(error)>"
return (false, msg)
}
return (pass, msg)
}
internal func expressionDoesNotMatch<T, U where U: Matcher, U.ValueType == T>(expression: Expression<T>, matcher: U, toNot: String) -> (Bool, FailureMessage) {
internal func expressionDoesNotMatch<T, U where U: Matcher, U.ValueType == T>(expression: Expression<T>, matcher: U, toNot: String, description: String?) -> (Bool, FailureMessage) {
let msg = FailureMessage()
msg.userDescription = description
msg.to = toNot
let pass = matcher.doesNotMatch(expression, failureMessage: msg)
if msg.actualValue == "" {
msg.actualValue = "<\(stringify(expression.evaluate()))>"
do {
let pass = try matcher.doesNotMatch(expression, failureMessage: msg)
if msg.actualValue == "" {
msg.actualValue = "<\(stringify(try expression.evaluate()))>"
}
return (pass, msg)
} catch let error {
msg.actualValue = "an unexpected error thrown: <\(error)>"
return (false, msg)
}
return (pass, msg)
}
public struct Expectation<T> {
......@@ -28,22 +40,22 @@ public struct Expectation<T> {
}
/// Tests the actual value using a matcher to match.
public func to<U where U: Matcher, U.ValueType == T>(matcher: U) {
let (pass, msg) = expressionMatches(expression, matcher: matcher, to: "to")
public func to<U where U: Matcher, U.ValueType == T>(matcher: U, description: String? = nil) {
let (pass, msg) = expressionMatches(expression, matcher: matcher, to: "to", description: description)
verify(pass, msg)
}
/// Tests the actual value using a matcher to not match.
public func toNot<U where U: Matcher, U.ValueType == T>(matcher: U) {
let (pass, msg) = expressionDoesNotMatch(expression, matcher: matcher, toNot: "to not")
public func toNot<U where U: Matcher, U.ValueType == T>(matcher: U, description: String? = nil) {
let (pass, msg) = expressionDoesNotMatch(expression, matcher: matcher, toNot: "to not", description: description)
verify(pass, msg)
}
/// Tests the actual value using a matcher to not match.
///
/// Alias to toNot().
public func notTo<U where U: Matcher, U.ValueType == T>(matcher: U) {
toNot(matcher)
public func notTo<U where U: Matcher, U.ValueType == T>(matcher: U, description: String? = nil) {
toNot(matcher, description: description)
}
// see:
......
......@@ -2,11 +2,11 @@ import Foundation
// Memoizes the given closure, only calling the passed
// closure once; even if repeat calls to the returned closure
internal func memoizedClosure<T>(closure: () -> T) -> (Bool) -> T {
internal func memoizedClosure<T>(closure: () throws -> T) -> (Bool) throws -> T {
var cache: T?
return ({ withoutCaching in
if (withoutCaching || cache == nil) {
cache = closure()
cache = try closure()
}
return cache!
})
......@@ -24,7 +24,7 @@ internal func memoizedClosure<T>(closure: () -> T) -> (Bool) -> T {
/// This provides a common consumable API for matchers to utilize to allow
/// Nimble to change internals to how the captured closure is managed.
public struct Expression<T> {
internal let _expression: (Bool) -> T?
internal let _expression: (Bool) throws -> T?
internal let _withoutCaching: Bool
public let location: SourceLocation
public let isClosure: Bool
......@@ -40,7 +40,7 @@ public struct Expression<T> {
/// requires an explicit closure. This gives Nimble
/// flexibility if @autoclosure behavior changes between
/// Swift versions. Nimble internals always sets this true.
public init(expression: () -> T?, location: SourceLocation, isClosure: Bool = true) {
public init(expression: () throws -> T?, location: SourceLocation, isClosure: Bool = true) {
self._expression = memoizedClosure(expression)
self.location = location
self._withoutCaching = false
......@@ -61,7 +61,7 @@ public struct Expression<T> {
/// requires an explicit closure. This gives Nimble
/// flexibility if @autoclosure behavior changes between
/// Swift versions. Nimble internals always sets this true.
public init(memoizedExpression: (Bool) -> T?, location: SourceLocation, withoutCaching: Bool, isClosure: Bool = true) {
public init(memoizedExpression: (Bool) throws -> T?, location: SourceLocation, withoutCaching: Bool, isClosure: Bool = true) {
self._expression = memoizedExpression
self.location = location
self._withoutCaching = withoutCaching
......@@ -76,12 +76,12 @@ public struct Expression<T> {
///
/// @param block The block that can cast the current Expression value to a
/// new type.
public func cast<U>(block: (T?) -> U?) -> Expression<U> {
return Expression<U>(expression: ({ block(self.evaluate()) }), location: self.location, isClosure: self.isClosure)
public func cast<U>(block: (T?) throws -> U?) -> Expression<U> {
return Expression<U>(expression: ({ try block(self.evaluate()) }), location: self.location, isClosure: self.isClosure)
}
public func evaluate() -> T? {
return self._expression(_withoutCaching)
public func evaluate() throws -> T? {
return try self._expression(_withoutCaching)
}
public func withoutCaching() -> Expression<T> {
......
......@@ -3,12 +3,13 @@ import Foundation
/// Encapsulates the failure message that matchers can report to the end user.
///
/// This is shared state between Nimble and matchers that mutate this value.
@objc public class FailureMessage {
public class FailureMessage: NSObject {
public var expected: String = "expected"
public var actualValue: String? = "" // empty string -> use default; nil -> exclude
public var to: String = "to"
public var postfixMessage: String = "match"
public var postfixActual: String = ""
public var userDescription: String? = nil
public var stringValue: String {
get {
......@@ -25,7 +26,7 @@ import Foundation
internal var _stringValueOverride: String?
public init() {
public override init() {
}
public init(stringValue: String) {
......@@ -44,6 +45,12 @@ import Foundation
if let actualValue = actualValue {
value = "\(expected) \(to) \(postfixMessage), got \(actualValue)\(postfixActual)"
}
return stripNewlines(value)
value = stripNewlines(value)
if let userDescription = userDescription {
return "\(userDescription)\n\(value)"
}
return value
}
}
\ No newline at end of file
......@@ -10,24 +10,26 @@ public func allPass<T,U where U: SequenceType, U.Generator.Element == T>
return createAllPassMatcher() {
expression, failureMessage in
failureMessage.postfixMessage = passName
return passFunc(expression.evaluate())
return passFunc(try expression.evaluate())
}
}
public func allPass<U,V where U: SequenceType, V: Matcher, U.Generator.Element == V.ValueType>
(matcher: V) -> NonNilMatcherFunc<U> {
return createAllPassMatcher() {matcher.matches($0, failureMessage: $1)}
return createAllPassMatcher() {
try matcher.matches($0, failureMessage: $1)
}
}
private func createAllPassMatcher<T,U where U: SequenceType, U.Generator.Element == T>
(elementEvaluator:(Expression<T>, FailureMessage) -> Bool) -> NonNilMatcherFunc<U> {
(elementEvaluator:(Expression<T>, FailureMessage) throws -> Bool) -> NonNilMatcherFunc<U> {
return NonNilMatcherFunc { actualExpression, failureMessage in
failureMessage.actualValue = nil
if let actualValue = actualExpression.evaluate() {
if let actualValue = try actualExpression.evaluate() {
for currentElement in actualValue {
let exp = Expression(
expression: {currentElement}, location: actualExpression.location)
if !elementEvaluator(exp, failureMessage) {
if try !elementEvaluator(exp, failureMessage) {
failureMessage.postfixMessage =
"all \(failureMessage.postfixMessage),"
+ " but failed first at element <\(stringify(currentElement))>"
......@@ -49,7 +51,7 @@ extension NMBObjCMatcher {
public class func allPassMatcher(matcher: NMBObjCMatcher) -> NMBObjCMatcher {
return NMBObjCMatcher(canMatchNil: false) { actualExpression, failureMessage in
let location = actualExpression.location
let actualValue = actualExpression.evaluate()
let actualValue = try! actualExpression.evaluate()
var nsObjects = [NSObject]()
var collectionIsUsable = true
......@@ -79,9 +81,9 @@ extension NMBObjCMatcher {
let elementEvaluator: (Expression<NSObject>, FailureMessage) -> Bool = {
expression, failureMessage in
return matcher.matches(
{expression.evaluate()}, failureMessage: failureMessage, location: expr.location)
{try! expression.evaluate()}, failureMessage: failureMessage, location: expr.location)
}
return createAllPassMatcher(elementEvaluator).matches(
return try! createAllPassMatcher(elementEvaluator).matches(
expr, failureMessage: failureMessage)
}
}
......
import Foundation
// A Nimble matcher that catches attempts to use beAKindOf with non Objective-C types
public func beAKindOf(expectedClass: Any) -> NonNilMatcherFunc<Any> {
return NonNilMatcherFunc {actualExpression, failureMessage in
failureMessage.stringValue = "beAKindOf only works on Objective-C types since"
+ " the Swift compiler will automatically type check Swift-only types."
+ " This expectation is redundant."
return false
}
}
/// A Nimble matcher that succeeds when the actual value is an instance of the given class.
/// @see beAnInstanceOf if you want to match against the exact class
public func beAKindOf(expectedClass: AnyClass) -> NonNilMatcherFunc<NSObject> {
return NonNilMatcherFunc { actualExpression, failureMessage in
let instance = actualExpression.evaluate()
let instance = try actualExpression.evaluate()
if let validInstance = instance {
failureMessage.actualValue = "<\(NSStringFromClass(validInstance.dynamicType)) instance>"
} else {
......@@ -18,7 +28,7 @@ public func beAKindOf(expectedClass: AnyClass) -> NonNilMatcherFunc<NSObject> {
extension NMBObjCMatcher {
public class func beAKindOfMatcher(expected: AnyClass) -> NMBMatcher {
return NMBObjCMatcher(canMatchNil: false) { actualExpression, failureMessage in
return beAKindOf(expected).matches(actualExpression, failureMessage: failureMessage)
return try! beAKindOf(expected).matches(actualExpression, failureMessage: failureMessage)
}
}
}
import Foundation
// A Nimble matcher that catches attempts to use beAnInstanceOf with non Objective-C types
public func beAnInstanceOf(expectedClass: Any) -> NonNilMatcherFunc<Any> {
return NonNilMatcherFunc {actualExpression, failureMessage in
failureMessage.stringValue = "beAnInstanceOf only works on Objective-C types since"
+ " the Swift compiler will automatically type check Swift-only types."
+ " This expectation is redundant."
return false
}
}
/// A Nimble matcher that succeeds when the actual value is an instance of the given class.
/// @see beAKindOf if you want to match against subclasses
public func beAnInstanceOf(expectedClass: AnyClass) -> NonNilMatcherFunc<NSObject> {
return NonNilMatcherFunc { actualExpression, failureMessage in
let instance = actualExpression.evaluate()
let instance = try actualExpression.evaluate()
if let validInstance = instance {
failureMessage.actualValue = "<\(NSStringFromClass(validInstance.dynamicType)) instance>"
} else {
......@@ -18,7 +28,7 @@ public func beAnInstanceOf(expectedClass: AnyClass) -> NonNilMatcherFunc<NSObjec
extension NMBObjCMatcher {
public class func beAnInstanceOfMatcher(expected: AnyClass) -> NMBMatcher {
return NMBObjCMatcher(canMatchNil: false) { actualExpression, failureMessage in
return beAnInstanceOf(expected).matches(actualExpression, failureMessage: failureMessage)
return try! beAnInstanceOf(expected).matches(actualExpression, failureMessage: failureMessage)
}
}
}
......@@ -18,7 +18,7 @@ internal func isCloseTo(actualValue: Double?, expectedValue: Double, delta: Doub
/// @see equal
public func beCloseTo(expectedValue: Double, within delta: Double = DefaultDelta) -> NonNilMatcherFunc<Double> {
return NonNilMatcherFunc { actualExpression, failureMessage in
return isCloseTo(actualExpression.evaluate(), expectedValue: expectedValue, delta: delta, failureMessage: failureMessage)
return isCloseTo(try actualExpression.evaluate(), expectedValue: expectedValue, delta: delta, failureMessage: failureMessage)
}
}
......@@ -28,11 +28,11 @@ public func beCloseTo(expectedValue: Double, within delta: Double = DefaultDelta
/// @see equal
public func beCloseTo(expectedValue: NMBDoubleConvertible, within delta: Double = DefaultDelta) -> NonNilMatcherFunc<NMBDoubleConvertible> {
return NonNilMatcherFunc { actualExpression, failureMessage in
return isCloseTo(actualExpression.evaluate()?.doubleValue, expectedValue: expectedValue.doubleValue, delta: delta, failureMessage: failureMessage)
return isCloseTo(try actualExpression.evaluate()?.doubleValue, expectedValue: expectedValue.doubleValue, delta: delta, failureMessage: failureMessage)
}
}
@objc public class NMBObjCBeCloseToMatcher : NMBMatcher {
public class NMBObjCBeCloseToMatcher : NSObject, NMBMatcher {
var _expected: NSNumber
var _delta: CDouble
init(expected: NSNumber, within: CDouble) {
......@@ -46,7 +46,7 @@ public func beCloseTo(expectedValue: NMBDoubleConvertible, within delta: Double
})
let expr = Expression(expression: actualBlock, location: location)
let matcher = beCloseTo(self._expected, within: self._delta)
return matcher.matches(expr, failureMessage: failureMessage)
return try! matcher.matches(expr, failureMessage: failureMessage)
}
public func doesNotMatch(actualExpression: () -> NSObject!, failureMessage: FailureMessage, location: SourceLocation) -> Bool {
......@@ -55,7 +55,7 @@ public func beCloseTo(expectedValue: NMBDoubleConvertible, within delta: Double
})
let expr = Expression(expression: actualBlock, location: location)
let matcher = beCloseTo(self._expected, within: self._delta)
return matcher.doesNotMatch(expr, failureMessage: failureMessage)
return try! matcher.doesNotMatch(expr, failureMessage: failureMessage)
}
public var within: (CDouble) -> NMBObjCBeCloseToMatcher {
......@@ -74,7 +74,7 @@ extension NMBObjCMatcher {
public func beCloseTo(expectedValues: [Double], within delta: Double = DefaultDelta) -> NonNilMatcherFunc <[Double]> {
return NonNilMatcherFunc { actualExpression, failureMessage in
failureMessage.postfixMessage = "be close to <\(stringify(expectedValues))> (each within \(stringify(delta)))"
if let actual = actualExpression.evaluate() {
if let actual = try actualExpression.evaluate() {
if actual.count != expectedValues.count {
return false
} else {
......@@ -92,7 +92,10 @@ public func beCloseTo(expectedValues: [Double], within delta: Double = DefaultDe
// MARK: - Operators
infix operator {}
infix operator {
associativity none
precedence 130
}
public func (lhs: Expectation<[Double]>, rhs: [Double]) {
lhs.to(beCloseTo(rhs))
......
......@@ -6,7 +6,7 @@ import Foundation
public func beEmpty<S: SequenceType>() -> NonNilMatcherFunc<S> {
return NonNilMatcherFunc { actualExpression, failureMessage in
failureMessage.postfixMessage = "be empty"
let actualSeq = actualExpression.evaluate()
let actualSeq = try actualExpression.evaluate()
if actualSeq == nil {
return true
}
......@@ -20,7 +20,7 @@ public func beEmpty<S: SequenceType>() -> NonNilMatcherFunc<S> {
public func beEmpty() -> NonNilMatcherFunc<String> {
return NonNilMatcherFunc { actualExpression, failureMessage in
failureMessage.postfixMessage = "be empty"
let actualString = actualExpression.evaluate()
let actualString = try actualExpression.evaluate()
return actualString == nil || (actualString! as NSString).length == 0
}
}
......@@ -30,7 +30,7 @@ public func beEmpty() -> NonNilMatcherFunc<String> {
public func beEmpty() -> NonNilMatcherFunc<NSString> {
return NonNilMatcherFunc { actualExpression, failureMessage in
failureMessage.postfixMessage = "be empty"
let actualString = actualExpression.evaluate()
let actualString = try actualExpression.evaluate()
return actualString == nil || actualString!.length == 0
}
}
......@@ -43,7 +43,7 @@ public func beEmpty() -> NonNilMatcherFunc<NSString> {
public func beEmpty() -> NonNilMatcherFunc<NSDictionary> {
return NonNilMatcherFunc { actualExpression, failureMessage in
failureMessage.postfixMessage = "be empty"
let actualDictionary = actualExpression.evaluate()
let actualDictionary = try actualExpression.evaluate()
return actualDictionary == nil || actualDictionary!.count == 0
}
}
......@@ -53,7 +53,7 @@ public func beEmpty() -> NonNilMatcherFunc<NSDictionary> {
public func beEmpty() -> NonNilMatcherFunc<NSArray> {
return NonNilMatcherFunc { actualExpression, failureMessage in
failureMessage.postfixMessage = "be empty"
let actualArray = actualExpression.evaluate()
let actualArray = try actualExpression.evaluate()
return actualArray == nil || actualArray!.count == 0
}
}
......@@ -63,7 +63,7 @@ public func beEmpty() -> NonNilMatcherFunc<NSArray> {
public func beEmpty() -> NonNilMatcherFunc<NMBCollection> {
return NonNilMatcherFunc { actualExpression, failureMessage in
failureMessage.postfixMessage = "be empty"
let actual = actualExpression.evaluate()
let actual = try actualExpression.evaluate()
return actual == nil || actual!.count == 0
}
}
......@@ -72,14 +72,14 @@ extension NMBObjCMatcher {
public class func beEmptyMatcher() -> NMBObjCMatcher {
return NMBObjCMatcher(canMatchNil: false) { actualExpression, failureMessage in
let location = actualExpression.location
let actualValue = actualExpression.evaluate()
let actualValue = try! actualExpression.evaluate()
failureMessage.postfixMessage = "be empty"
if let value = actualValue as? NMBCollection {
let expr = Expression(expression: ({ value as NMBCollection }), location: location)
return beEmpty().matches(expr, failureMessage: failureMessage)
return try! beEmpty().matches(expr, failureMessage: failureMessage)
} else if let value = actualValue as? NSString {
let expr = Expression(expression: ({ value as String }), location: location)
return beEmpty().matches(expr, failureMessage: failureMessage)
return try! beEmpty().matches(expr, failureMessage: failureMessage)
} else if let actualValue = actualValue {
failureMessage.postfixMessage = "be empty (only works for NSArrays, NSSets, NSDictionaries, NSHashTables, and NSStrings)"
failureMessage.actualValue = "\(NSStringFromClass(actualValue.dynamicType)) type"
......