How to use computeStringValue method of FailureMessage class

Best Nimble code snippet using FailureMessage.computeStringValue

Run Nimble automation tests on LambdaTest cloud grid

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

FailureMessage.swift

Source: FailureMessage.swift Github

copy
1import Foundation
2
3/// Encapsulates the failure message that matchers can report to the end user.
4///
5/// This is shared state between Nimble and matchers that mutate this value.
6public class FailureMessage: NSObject {
7    public var expected: String = "expected"
8    public var actualValue: String? = "" // empty string -> use default; nil -> exclude
9    public var to: String = "to"
10    public var postfixMessage: String = "match"
11    public var postfixActual: String = ""
12    public var userDescription: String? = nil
13
14    public var stringValue: String {
15        get {
16            if let value = _stringValueOverride {
17                return value
18            } else {
19                return computeStringValue()
20            }
21        }
22        set {
23            _stringValueOverride = newValue
24        }
25    }
26
27    internal var _stringValueOverride: String?
28
29    public override init() {
30    }
31
32    public init(stringValue: String) {
33        _stringValueOverride = stringValue
34    }
35
36    internal func stripNewlines(str: String) -> String {
37        var lines: [String] = NSString(string: str).componentsSeparatedByString("\n") as [String]
38        let whitespace = NSCharacterSet.whitespaceAndNewlineCharacterSet()
39        lines = lines.map { line in NSString(string: line).stringByTrimmingCharactersInSet(whitespace) }
40        return lines.joinWithSeparator("")
41    }
42
43    internal func computeStringValue() -> String {
44        var value = "\(expected) \(to) \(postfixMessage)"
45        if let actualValue = actualValue {
46            value = "\(expected) \(to) \(postfixMessage), got \(actualValue)\(postfixActual)"
47        }
48        value = stripNewlines(value)
49        
50        if let userDescription = userDescription {
51            return "\(userDescription)\n\(value)"
52        }
53        
54        return value
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

Most used method in FailureMessage

Trigger computeStringValue code on LambdaTest Cloud Grid

Execute automation tests with computeStringValue on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
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)