How to use beTruthyMatcher method of func class

Best Nimble code snippet using func.beTruthyMatcher

Run Nimble automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

BeLogical.swift

Source: BeLogical.swift Github

copy
1import Foundation
2
3public struct _BeBooleanTypeMatcher: BasicMatcher {
4    public let expectedValue: BooleanType
5    public let stringValue: String
6
7    public func matches(actualExpression: Expression<BooleanType>, failureMessage: FailureMessage) -> Bool {
8        failureMessage.postfixMessage = "be \(stringValue)"
9        return actualExpression.evaluate()?.boolValue == expectedValue.boolValue
10    }
11}
12
13public struct _BeBoolMatcher: BasicMatcher {
14    public let expectedValue: BooleanType
15    public let stringValue: String
16
17    public func matches(actualExpression: Expression<Bool>, failureMessage: FailureMessage) -> Bool {
18        failureMessage.postfixMessage = "be \(stringValue)"
19        let actual = actualExpression.evaluate()
20        return (actual?.boolValue) == expectedValue.boolValue
21    }
22}
23
24public func beTruthy() -> _BeBooleanTypeMatcher {
25    return _BeBooleanTypeMatcher(expectedValue: true, stringValue: "truthy")
26}
27
28public func beFalsy() -> _BeBooleanTypeMatcher {
29    return _BeBooleanTypeMatcher(expectedValue: false, stringValue: "falsy")
30}
31
32public func beTruthy() -> _BeBoolMatcher {
33    return _BeBoolMatcher(expectedValue: true, stringValue: "truthy")
34}
35
36public func beFalsy() -> _BeBoolMatcher {
37    return _BeBoolMatcher(expectedValue: false, stringValue: "falsy")
38}
39
40extension NMBObjCMatcher {
41    public class func beTruthyMatcher() -> NMBObjCMatcher {
42        return NMBObjCMatcher { actualBlock, failureMessage, location in
43            let block = ({ (actualBlock() as? NSNumber)?.boolValue ?? false })
44            let expr = Expression(expression: block, location: location)
45            return beTruthy().matches(expr, failureMessage: failureMessage)
46        }
47    }
48    public class func beFalsyMatcher() -> NMBObjCMatcher {
49        return NMBObjCMatcher { actualBlock, failureMessage, location in
50            let block = ({ (actualBlock() as? NSNumber)?.boolValue ?? false })
51            let expr = Expression(expression: block, location: location)
52            return beFalsy().matches(expr, failureMessage: failureMessage)
53        }
54    }
55}
56
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)