### Install GoCardlessSDK using CocoaPods Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/README.md This snippet shows the line to add to your Podfile to install the GoCardlessSDK. After adding this line, run `pod install` from your project's directory to integrate the SDK into your iOS project. ```Ruby pod 'GoCardlessSDK' ``` -------------------------------- ### Install iOSSnapshotTestCase with Package Managers Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/iOSSnapshotTestCase/README.md Add iOSSnapshotTestCase to your project using CocoaPods, Carthage, or Swift Package Manager. Choose the appropriate method based on your project's dependency management setup. For Objective-C only test targets, use `iOSSnapshotTestCase/Core` with CocoaPods to exclude Swift support. ```Ruby target "Tests" do use_frameworks! pod 'iOSSnapshotTestCase' end ``` ```Carthage github "uber/ios-snapshot-test-case" ~> 6.1.0 ``` ```Swift Package Manager dependencies: [ .package(url: "https://github.com/uber/ios-snapshot-test-case.git", from: "7.0.0"), ], ``` -------------------------------- ### Example: Asserting floating-point proximity with `beCloseTo` Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/Nimble/README.md Provides a concrete example of using `beCloseTo` to check if `10.01` is close to `10` within a `0.1` delta. ```Swift expect(10.01).to(beCloseTo(10, within: 0.1)) ``` ```Objective-C expect(@(10.01)).to(beCloseTo(@10).within(0.1)); ``` -------------------------------- ### Install Nimble via CocoaPods Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/Nimble/README.md Provides the `Podfile` configuration required to integrate Nimble into an iOS project using CocoaPods, including the `use_frameworks!` directive for Swift support and targeting a specific test bundle for dependency management. ```Ruby platform :ios, '8.0' source 'https://github.com/CocoaPods/Specs.git' # Whatever pods you need for your app go here target 'YOUR_APP_NAME_HERE_Tests', :exclusive => true do use_frameworks! pod 'Nimble' end ``` -------------------------------- ### Fetch List of Billing Requests in Swift Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/README.md Example demonstrating how to fetch a list of billing requests using the GoCardless SDK's billingRequestService and handle the asynchronous response with Combine, including error handling. ```swift GoCardlessSDK.shared.billingRequestService.listBillingRequests() .receive(on: DispatchQueue.main) .sink(receiveCompletion: { (completion) in switch completion { case let .failure(error): print("API error: \(error)") self.state = .error case .finished: break } }) { billingRequestList in self.state = .success(billingRequest: billingRequest) } .store(in: &subscriptions) ``` -------------------------------- ### Example: Asserting object type with `beAKindOf` Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/Nimble/README.md Provides a practical example of using `beAKindOf` to assert that an object (`dolphin`) is a kind of a specific class (`Mammal`), clarifying the usage of `isMemberOfClass:` and `isKindOfClass:`. ```Swift expect(dolphin).to(beAKindOf(Mammal)) ``` ```Objective-C expect(dolphin).to(beAKindOf([Mammal class])); ``` -------------------------------- ### Catch Precondition Failures on macOS and iOS Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/CwlPreconditionTesting/README.md Example demonstrating how to use `catchBadInstruction` from the `CwlPreconditionTesting` module to catch `EXC_BAD_INSTRUCTION` errors, such as those raised by `precondition(false, ...)` on macOS and iOS platforms. ```Swift import CwlPreconditionTesting let e = catchBadInstruction { precondition(false, "THIS PRECONDITION FAILURE IS EXPECTED") } ``` -------------------------------- ### Install GoCardless iOS SDK using CocoaPods Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/README.md Instructions for adding the GoCardless iOS SDK to an iOS project using CocoaPods, a dependency manager for Swift and Objective-C Cocoa projects. ```ruby pod 'GoCardlessSDK' ``` -------------------------------- ### Register XCTest Principal Class for Nimble Setup (Info.plist) Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/Nimble/README.md This XML snippet for `Info.plist` demonstrates how to register a principal class for XCTest. This registration is essential for setting up an `XCTestObservation` observer, enabling custom test setup like configuring Nimble's polling defaults at test bundle startup. ```XML NSPrincipalClass MyTests.TestSetup ``` -------------------------------- ### Catch Precondition Failures on tvOS, Linux, and POSIX Systems Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/CwlPreconditionTesting/README.md Example demonstrating how to use `catchBadInstruction` from the `CwlPosixPreconditionTesting` module to catch `EXC_BAD_INSTRUCTION` errors on tvOS, Linux, and other POSIX-compliant platforms. Note that this version may conflict with lldb's Mach exception handler. ```Swift import CwlPosixPreconditionTesting let e = catchBadInstruction { precondition(false, "THIS PRECONDITION FAILURE IS EXPECTED") } ``` -------------------------------- ### Perform Common String Assertions Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/Nimble/README.md Provides examples of various matchers for asserting properties of strings, including `contain` for substrings, `beginWith` for prefixes, `endWith` for suffixes, `beEmpty` for empty strings, and `match` for regular expressions. ```Swift // Passes if 'actual' contains 'substring': expect(actual).to(contain(substring)) // Passes if 'actual' begins with 'prefix': expect(actual).to(beginWith(prefix)) // Passes if 'actual' ends with 'suffix': expect(actual).to(endWith(suffix)) // Passes if 'actual' represents the empty string, "": expect(actual).to(beEmpty()) // Passes if 'actual' matches the regular expression defined in 'expected': expect(actual).to(match(expected)) ``` ```Objective-C // Passes if 'actual' contains 'substring': expect(actual).to(contain(expected)); // Passes if 'actual' begins with 'prefix': expect(actual).to(beginWith(prefix)); // Passes if 'actual' ends with 'suffix': expect(actual).to(endWith(suffix)); // Passes if 'actual' represents the empty string, "": expect(actual).to(beEmpty()); // Passes if 'actual' matches the regular expression defined in 'expected': expect(actual).to(match(expected)) ``` -------------------------------- ### Integrate CwlPreconditionTesting with CocoaPods Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/CwlPosixPreconditionTesting/README.md To integrate CwlPreconditionTesting into your Xcode project using CocoaPods, specify the pod in your Podfile. Ensure you have CocoaPods installed and configured. ```Ruby pod 'CwlPreconditionTesting', '~> 2.0' ``` -------------------------------- ### Use `toEventually` with Swift Async/Await Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/Nimble/README.md Illustrates how to integrate `toEventually` with Swift's `async`/`await` syntax. It shows a basic example with `DispatchQueue.main.async` and a more advanced scenario involving an `actor` to demonstrate testing asynchronous operations that return values. ```Swift // Swift DispatchQueue.main.async { ocean.add("dolphins") ocean.add("whales") } await expect(ocean).toEventually(contain("dolphens", "whiles")) ``` ```Swift actor MyActor { private var counter = 0 func access() -> Int { counter += 1 return counter } } let subject = MyActor() await expect { await subject.access() }.toEventually(equal(2)) ``` -------------------------------- ### Catch Precondition Failures on macOS and iOS Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/CwlPosixPreconditionTesting/README.md This example demonstrates how to use catchBadInstruction from CwlPreconditionTesting on macOS and iOS to catch precondition failures. The precondition inside the closure is expected to fail, and its exception is caught. ```Swift import CwlPreconditionTesting let e = catchBadInstruction { precondition(false, "THIS PRECONDITION FAILURE IS EXPECTED") } ``` -------------------------------- ### Create Asynchronous Swift Matchers with AsyncMatcher Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/Nimble/README.md This section demonstrates how to implement asynchronous matchers in Swift using `AsyncMatcher`. It includes an example of a `beCalled` matcher that checks if an actor has recorded a specific call, showcasing how to handle asynchronous expressions and await results. ```Swift actor CallRecorder { private(set) var calls: [Arguments] = [] func record(call: Arguments) { calls.append(call) } } func beCalled(with arguments: Argument) -> AsyncMatcher> { AsyncMatcher { (expression: AsyncExpression>) in let message = ExpectationMessage.expectedActualValueTo("be called with \(arguments)") guard let calls = try await expression.evaluate()?.calls else { return MatcherResult(status: .fail, message: message.appendedBeNilHint()) } return MatcherResult(bool: calls.contains(args), message: message.appended(details: "called with \(calls)")) } } ``` -------------------------------- ### Assert Collection Start and End Elements Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/Nimble/README.md Illustrates how to use `beginWith` to check if a collection starts with specific elements and `endWith` to check if it ends with them. Similar to `contain`, Objective-C versions of these matchers currently support only a single argument. ```Swift // Passes if the elements in expected appear at the beginning of 'actual': expect(actual).to(beginWith(expected...)) // Passes if the the elements in expected come at the end of 'actual': expect(actual).to(endWith(expected...)) ``` ```Objective-C // Passes if the elements in expected appear at the beginning of 'actual': expect(actual).to(beginWith(expected)); // Passes if the the elements in expected come at the end of 'actual': expect(actual).to(endWith(expected)); ``` -------------------------------- ### Configure Nimble Timeout and Poll Intervals with Quick in Swift Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/Nimble/README.md This example shows how to set Nimble's polling defaults using a `QuickConfiguration` subclass. This approach allows for global configuration at test startup when using the Quick testing framework. ```Swift import Quick import Nimble class PollingConfiguration: QuickConfiguration { override class func configure(_ configuration: QCKConfiguration) { Nimble.PollingDefaults.timeout = .seconds(5) Nimble.PollingDefaults.pollInterval = .milliseconds(100) } } ``` -------------------------------- ### Nimble Objective-C expectAction for Non-Returning Expressions Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/Nimble/README.md This example demonstrates using `expectAction` in Objective-C for making expectations on expressions that do not return a value, such as raising an exception. It is crucial for testing side effects or actions that do not produce a direct return value. ```Objective-C // Objective-C expectAction(^{ [exception raise]; }).to(raiseException()); ``` -------------------------------- ### Verifying Swift Errors with `throwError` Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/Nimble/README.md Illustrates how to use the `throwError` matcher in Swift to check if a function throws an `Error`. Examples include verifying any error, errors within a specific domain, particular error enum cases, or errors of a specific type. ```Swift // Swift // Passes if 'somethingThatThrows()' throws an 'Error': expect { try somethingThatThrows() }.to(throwError()) // Passes if 'somethingThatThrows()' throws an error within a particular domain: expect { try somethingThatThrows() }.to(throwError { (error: Error) in expect(error._domain).to(equal(NSCocoaErrorDomain)) }) // Passes if 'somethingThatThrows()' throws a particular error enum case: expect { try somethingThatThrows() }.to(throwError(NSCocoaError.PropertyListReadCorruptError)) // Passes if 'somethingThatThrows()' throws an error of a particular type: expect { try somethingThatThrows() }.to(throwError(errorType: NimbleError.self)) ``` -------------------------------- ### Nimble Objective-C Expectations with Parameter Boxing Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/Nimble/README.md This snippet illustrates how to use Nimble's `expect` function in Objective-C, demonstrating the necessity of boxing C numeric types and strings into their `NSObject` equivalents. It shows examples for `NSNumber`, `NSString`, and `NSRange` conversions for proper assertion. ```Objective-C // Objective-C @import Nimble; expect(@(1 + 1)).to(equal(@2)); expect(@"Hello world").to(contain(@"world")); // Boxed as NSNumber * expect(2).to(equal(2)); expect(1.2).to(beLessThan(2.0)); expect(true).to(beTruthy()); // Boxed as NSString * expect("Hello world").to(equal("Hello world")); // Boxed as NSRange expect(NSMakeRange(1, 10)).to(equal(NSMakeRange(1, 10))); ``` -------------------------------- ### Implement XCTest Observer for Nimble Polling Defaults in Swift Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/Nimble/README.md This Swift code defines an `XCTestObserver` to configure Nimble's polling defaults when using XCTest. The `TestSetup` class registers the observer, ensuring the settings are applied when the test bundle starts, providing a structured way to initialize test environment parameters. ```Swift // TestSetup.swift import XCTest import Nimble @objc class TestSetup: NSObject { override init() { XCTestObservationCenter.shared.register(PollingConfigurationTestObserver()) } } class PollingConfigurationTestObserver: NSObject, XCTestObserver { func testBundleWillStart(_ testBundle: Bundle) { Nimble.PollingDefaults.timeout = .seconds(5) Nimble.PollingDefaults.pollInterval = .milliseconds(100) } } ``` -------------------------------- ### Define Swift Matcher with Type Constraint using Generics Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/Nimble/README.md This example demonstrates how to create a Swift matcher that constrains the type of the actual value using generics. The `haveDescription` matcher only accepts values implementing the `Printable` protocol and checks their `description` property against a provided string. ```Swift public func haveDescription(description: String) -> Matcher { return Matcher.simple("have description") { actual in return MatcherStatus(bool: actual.evaluate().description == description) } } ``` -------------------------------- ### Expect a Value to Eventually Match (Polling) Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/Nimble/README.md Demonstrates how to use `toEventually` to assert on values that are updated asynchronously. The expectation continuously re-evaluates the value until it matches or a default timeout occurs. This example uses `DispatchQueue.main.async` to simulate an asynchronous update. ```Swift // Swift DispatchQueue.main.async { ocean.add("dolphins") ocean.add("whales") } expect(ocean).toEventually(contain("dolphins", "whales")) ``` ```Objective-C // Objective-C dispatch_async(dispatch_get_main_queue(), ^{ [ocean add:@"dolphins"]; [ocean add:@"whales"]; }); expect(ocean).toEventually(contain(@"dolphins", @"whales")); ``` -------------------------------- ### Customize Nimble Failure Messages with Matcher.define Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/Nimble/README.md This section shows how to customize failure messages in Nimble using `Matcher.define`. It provides an example of an `equal` matcher that modifies the default error message based on the comparison result, offering more detailed feedback, especially for nil values. ```Swift public func equal(_ expectedValue: T?) -> Matcher { return Matcher.define("equal <\(stringify(expectedValue))>") { actualExpression, msg in let actualValue = try actualExpression.evaluate() let matches = actualValue == expectedValue && expectedValue != nil if expectedValue == nil || actualValue == nil { if expectedValue == nil && actualValue != nil { return MatcherResult( status: .fail, message: msg.appendedBeNilHint() ) } return MatcherResult(status: .fail, message: msg) } return MatcherResult(bool: matches, message: msg) } } ``` -------------------------------- ### Ensuring Collection Count with `expect` vs. `require` in Swift Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/Nimble/README.md This example contrasts the traditional `expect` assertion followed by a `guard` statement with the more concise `require` DSL. `require` directly throws an error if the collection count does not match, eliminating redundant conditional checks and streamlining test logic. ```swift let collection = myFunction() expect(collection).to(haveCount(3)) guard collection.count == 3 else { return } // ... ``` ```swift let collection = try require(myFunction()).to(haveCount(3)) // ... ``` -------------------------------- ### Assert Swift Result Type (Swift) Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/Nimble/README.md Examples of matchers for Swift `Result` types, including `beSuccess()` and `beFailure()`. These matchers allow validation of both success and failure cases, including their associated values using closures. This matcher is only available in Swift. ```Swift // Swift let aResult: Result = .success("Hooray") // passes if result is .success expect(aResult).to(beSuccess()) // passes if result value is .success and validates Success value expect(aResult).to(beSuccess { value in expect(value).to(equal("Hooray")) }) enum AnError: Error { case somethingHappened } let otherResult: Result = .failure(.somethingHappened) // passes if result is .failure expect(otherResult).to(beFailure()) // passes if result value is .failure and validates error expect(otherResult).to(beFailure { error in expect(error).to(matchError(AnError.somethingHappened)) }) ``` -------------------------------- ### Append Messages to Nimble Failure Messages Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/Nimble/README.md This example illustrates how to use `appended(message: String)` and `appended(details: String)` helper functions to add extra information to Nimble's failure messages. `appended(message:)` adds inline text, while `appended(details:)` provides multi-line details for test logs. ```Swift .expectedActualValueTo("be true").appended(message: " (use beFalse() for inverse)") ``` ```Swift .expectedActualValueTo("be true").appended(details: "use beFalse() for inverse\nor use beNil()") ``` -------------------------------- ### Check if All Elements Pass a Condition (Swift) Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/Nimble/README.md Demonstrates how to use `allPass` in Swift to assert that all elements in a collection satisfy a given condition. The collection must be an instance of a type conforming to `Sequence`. Examples include using a custom closure, composing with another matcher, and handling asynchronous conditions. ```Swift // Swift // Providing a custom function: expect([1, 2, 3, 4]).to(allPass { $0 < 5 }) // Composing the expectation with another matcher: expect([1, 2, 3, 4]).to(allPass(beLessThan(5))) ``` ```Swift // Swift // Providing a custom function: expect([1, 2, 3, 4]).to(allPass { await asyncFunctionReturningBool($0) }) // Composing the expectation with another matcher: expect([1, 2, 3, 4]).to(allPass(someAsyncMatcher())) ``` -------------------------------- ### Assert Collection Element Count (Swift and Objective-C) Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/Nimble/README.md Examples of using `haveCount` to assert the number of elements in a collection. For Swift, the actual value must be an instance of a type conforming to `Collection` (e.g., `Array`, `Dictionary`, or `Set`). For Objective-C, the actual value must be one of `NSArray`, `NSDictionary`, `NSSet`, or `NSHashTable` (or their subclasses). ```Swift // Swift // Passes if 'actual' contains the 'expected' number of elements: expect(actual).to(haveCount(expected)) // Passes if 'actual' does _not_ contain the 'expected' number of elements: expect(actual).notTo(haveCount(expected)) ``` ```Objective-C // Objective-C // Passes if 'actual' contains the 'expected' number of elements: expect(actual).to(haveCount(expected)) // Passes if 'actual' does _not_ contain the 'expected' number of elements: expect(actual).notTo(haveCount(expected)) ``` -------------------------------- ### Initialize GoCardless SDK client in Swift Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/README.md Demonstrates how to initialize the GoCardless SDK client with an access token and configure it for the live environment. This step is crucial before making any API requests. ```swift import GoCardlessSDK GoCardlessSDK.initSDK(accessToken: "YOUR_ACCESS_TOKEN", environment: .live) { print("GoCardless SDK is initialised") } ``` -------------------------------- ### Catch Precondition Failures on tvOS and Linux using CwlPosixPreconditionTesting Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/CwlMachBadInstructionHandler/README.md Illustrates the usage of the POSIX version of `catchBadInstruction` from `CwlPosixPreconditionTesting` for platforms like tvOS and Linux. Note that this version may conflict with lldb debugging and is whole-process scoped. ```Swift import CwlPosixPreconditionTesting let e = catchBadInstruction { precondition(false, "THIS PRECONDITION FAILURE IS EXPECTED") } ``` -------------------------------- ### Perform basic numeric comparisons Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/Nimble/README.md Demonstrates how to use `beLessThan`, `beLessThanOrEqualTo`, `beGreaterThan`, and `beGreaterThanOrEqualTo` matchers for numeric comparisons. Values must conform to the `Comparable` protocol. ```Swift expect(actual).to(beLessThan(expected)) expect(actual) < expected expect(actual).to(beLessThanOrEqualTo(expected)) expect(actual) <= expected expect(actual).to(beGreaterThan(expected)) expect(actual) > expected expect(actual).to(beGreaterThanOrEqualTo(expected)) expect(actual) >= expected ``` ```Objective-C expect(actual).to(beLessThan(expected)); expect(actual).to(beLessThanOrEqualTo(expected)); expect(actual).to(beGreaterThan(expected)); expect(actual).to(beGreaterThanOrEqualTo(expected)); ``` -------------------------------- ### Integrate CwlPreconditionTesting with Swift Package Manager Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/CwlMachBadInstructionHandler/README.md Add CwlPreconditionTesting as a dependency to your project using Swift Package Manager by updating your `Package.swift` file or through Xcode's Swift Packages interface. ```Swift .package(url: "https://github.com/mattgallagher/CwlPreconditionTesting.git", from: Version("2.0.0")) ``` -------------------------------- ### Add CwlPreconditionTesting with Swift Package Manager Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/CwlPosixPreconditionTesting/README.md To integrate CwlPreconditionTesting into your project using Swift Package Manager, add the provided dependency entry to the 'dependencies' array in your 'Package.swift' file. Alternatively, you can add the GitHub URL directly in Xcode. ```Swift .package(url: "https://github.com/mattgallagher/CwlPreconditionTesting.git", from: Version("2.0.0")) ``` -------------------------------- ### Add CwlPreconditionTesting with Swift Package Manager Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/CwlPreconditionTesting/README.md Instructions for integrating CwlPreconditionTesting into a project using Swift Package Manager. This involves adding the package URL and version to the `dependencies` array in the `Package.swift` file or through Xcode's Swift packages interface. ```Swift .package(url: "https://github.com/mattgallagher/CwlPreconditionTesting.git", from: Version("2.0.0")) ``` -------------------------------- ### GoCardless SDK Supported Services API Reference Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/README.md Overview of the services and their functions supported by the GoCardless iOS SDK, including Billing Request, Billing Request Flow, and Payment operations. ```APIDOC Billing Request: createBillingRequest: Creates a Billing Request, enabling you to collect all types of GoCardless payments collectCustomerDetails: If the billing request has a pending collect_customer_details action, this endpoint can be used to collect the details in order to complete it. collectBankAccount: If the billing request has a pending collect_bank_account action, this endpoint can be used to collect the details in order to complete it. confirmPayerDetails: This is needed when you have a mandate request. As a scheme compliance rule we are required to allow the payer to crosscheck the details entered by them and confirm it. fulfil: If a billing request is ready to be fulfilled, call this endpoint to cause it to fulfil, executing the payment. cancel: Immediately cancels a billing request, causing all billing request flows to expire. notify: Notifies the customer linked to the billing request, asking them to authorise it. getBillingRequest: Fetches a billing request listBillingRequests: Returns a cursor-paginated list of your billing requests. Billing Request Flow: createBillingRequestFlow: Creates a new billing request flow. Payment: createPaymentRequest: Creates a new payment object. ``` -------------------------------- ### Implement a Basic iOS Snapshot Test Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/iOSSnapshotTestCase/README.md To create a snapshot test, subclass `FBSnapshotTestCase` and use `FBSnapshotVerifyView` within your test method. Initially, set `self.recordMode = YES;` (or `recordMode = true` in Swift) in the `-setUp` method to generate reference images, then remove or comment out this line for subsequent test runs to perform comparisons. ```Objective-C #import #import @interface MySnapshotTests : FBSnapshotTestCase @end @implementation MySnapshotTests - (void)setUp { [super setUp]; // Uncomment the line below to record new reference images // self.recordMode = YES; } - (void)testMyViewSnapshot { UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; myView.backgroundColor = [UIColor redColor]; // Configure your view's content and state here FBSnapshotVerifyView(myView, nil); } @end ``` ```Swift import FBSnapshotTestCase import UIKit class MySnapshotTests: FBSnapshotTestCase { override func setUp() { super.setUp() // Uncomment the line below to record new reference images // recordMode = true } func testMyViewSnapshot() { let myView = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100)) myView.backgroundColor = .red // Configure your view's content and state here FBSnapshotVerifyView(myView) } } ``` -------------------------------- ### Define and Expose 'beginWith' Matcher for Swift and Objective-C Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/Nimble/README.md Illustrates the full implementation of a `beginWith` custom matcher in Swift, including its generic definition and the necessary `NMBMatcher` extension to make it callable from Objective-C, demonstrating how to handle sequence evaluation and Objective-C interoperability for custom matchers. ```Swift public func beginWith(_ startingElement: S.Element) -> Matcher where S.Element: Equatable { return Matcher.simple("begin with <\(startingElement)>") { actualExpression in guard let actualValue = try actualExpression.evaluate() else { return .fail } var actualGenerator = actualValue.makeIterator() return MatcherStatus(bool: actualGenerator.next() == startingElement) } } ``` ```Swift extension NMBMatcher { @objc public class func beginWithMatcher(_ expected: Any) -> NMBMatcher { return NMBMatcher { actualExpression in let actual = try actualExpression.evaluate() let expr = actualExpression.cast { $0 as? NMBOrderedCollection } return try beginWith(expected).satisfies(expr).toObjectiveC() } } } ``` -------------------------------- ### Catch Precondition Failures on macOS and iOS using CwlPreconditionTesting Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/CwlMachBadInstructionHandler/README.md Demonstrates how to use `catchBadInstruction` from `CwlPreconditionTesting` to safely catch and test `precondition` failures in Swift applications running on macOS or iOS. ```Swift import CwlPreconditionTesting let e = catchBadInstruction { precondition(false, "THIS PRECONDITION FAILURE IS EXPECTED") } ``` -------------------------------- ### Expressing Expectations with Nimble's `expect(...).to` Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/Nimble/README.md Illustrates Nimble's core `expect(...).to` syntax for expressing natural language expectations. This method allows for clear and readable assertions, addressing some limitations of XCTest. ```Swift import Nimble expect(seagull.squawk).to(equal("Squee!")) ``` ```Objective-C @import Nimble; expect(seagull.squawk).to(equal(@"Squee!")); ``` -------------------------------- ### Basic Expectation Syntax in Swift with Nimble Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/Nimble/README.md This snippet demonstrates the fundamental syntax for writing expectations in Swift using Nimble. It showcases various built-in matchers like `equal`, `beCloseTo`, `contain`, and `toEventually` for different assertion types, providing a clear and readable way to express test outcomes. ```Swift // Swift expect(1 + 1).to(equal(2)) expect(1.2).to(beCloseTo(1.1, within: 0.1)) expect(3) > 2 expect("seahorse").to(contain("sea")) expect(["Atlantic", "Pacific"]).toNot(contain("Mississippi")) expect(ocean.isClean).toEventually(beTruthy()) ``` -------------------------------- ### Integrate CwlPreconditionTesting with CocoaPods Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/CwlPreconditionTesting/README.md Instructions for integrating CwlPreconditionTesting into an Xcode project using CocoaPods. This involves specifying the pod and its version in the project's Podfile. ```Ruby pod 'CwlPreconditionTesting', '~> 2.0' ``` -------------------------------- ### Configure Nimble with Swift Package Manager Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/Nimble/README.md This snippet demonstrates how to add Nimble as a dependency to your `Package.swift` file when using Swift Package Manager. It shows how to declare the Nimble package URL and version, and how to link it with your test target to enable testing functionalities. ```swift // swift-tools-version:5.5 import PackageDescription let package = Package( name: "MyAwesomeLibrary", products: [ // ... ], dependencies: [ // ... .package(url: "https://github.com/Quick/Nimble.git", from: "12.0.0") ], targets: [ // Targets are the basic building blocks of a package. A target can define a module or a test suite. // Targets can depend on other targets in this package, and on products in packages this package depends on. .target( name: "MyAwesomeLibrary", dependencies: ...), .testTarget( name: "MyAwesomeLibraryTests", dependencies: ["MyAwesomeLibrary", "Nimble"]) ] ) ``` -------------------------------- ### Catch Precondition Failures on tvOS, Linux (POSIX) Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/CwlPosixPreconditionTesting/README.md For tvOS, Linux, and other POSIX-compliant platforms, use CwlPosixPreconditionTesting to catch precondition failures. Note that this version cannot be used when lldb is attached, and the signal handler is whole process scoped. ```Swift import CwlPosixPreconditionTesting let e = catchBadInstruction { precondition(false, "THIS PRECONDITION FAILURE IS EXPECTED") } ``` -------------------------------- ### Integrate CwlPreconditionTesting with CocoaPods Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/CwlMachBadInstructionHandler/README.md Add CwlPreconditionTesting as a dependency to your Xcode project using CocoaPods by specifying it in your Podfile. ```Ruby pod 'CwlPreconditionTesting', '~> 2.0' ``` -------------------------------- ### Define C Function for Simplified Objective-C Matcher Syntax Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/Nimble/README.md Illustrates how to create a C function wrapper for an Objective-C class method, simplifying the syntax for calling Nimble matchers in Objective-C tests and improving readability. ```Objective-C FOUNDATION_EXPORT NMBMatcher *beNil() { return [NMBMatcher beNilMatcher]; } ``` -------------------------------- ### Implementing `beNil` Matcher with Lazy Evaluation in Swift Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/Nimble/README.md This snippet illustrates how to implement a `beNil` matcher in Swift, demonstrating the use of `actualExpression.evaluate()` for lazy evaluation. It shows how `Matcher.simpleNilable` can be used to simplify matcher creation and handle nil actual expressions. ```Swift public func beNil() -> Matcher { // Matcher.simpleNilable(..) automatically generates ExpectationMessage for // us based on the string we provide to it. Also, the 'Nilable' postfix indicates // that this Matcher supports matching against nil actualExpressions, instead of // always resulting in a MatcherStatus.fail result -- which is true for // Matcher.simple(..) return Matcher.simpleNilable("be nil") { actualExpression in let actualValue = try actualExpression.evaluate() return MatcherStatus(bool: actualValue == nil) } } ``` -------------------------------- ### Use Swift Custom Matcher from Objective-C Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/Nimble/README.md Shows how to invoke a custom matcher defined in Swift (like `beNilMatcher`) directly from Objective-C test code using the `expect` function, demonstrating cross-language usage. ```Objective-C expect(actual).to([NMBMatcher beNilMatcher]()); ``` -------------------------------- ### Extend NMBMatcher in Swift for Objective-C Interoperability Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/Nimble/README.md Demonstrates how to extend the `NMBMatcher` class in Swift to create a custom matcher (`beNilMatcher`) that can be called from Objective-C, enabling Swift-defined matchers to be used in Objective-C test code. ```Swift extension NMBMatcher { @objc public class func beNilMatcher() -> NMBMatcher { return NMBMatcher { actualExpression in return try beNil().satisfies(actualExpression).toObjectiveC() } } } ``` -------------------------------- ### Testing Swift Assertions with `throwAssertion` Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/Nimble/README.md Demonstrates using the `throwAssertion` matcher in Swift to verify if code throws an assertion, such as `fatalError()` or a failed `precondition`. This feature relies on the CwlPreconditionTesting library. ```Swift // Swift // Passes if 'somethingThatThrows()' throws an assertion, // such as by calling 'fatalError()' or if a precondition fails: expect { try somethingThatThrows() }.to(throwAssertion()) expect { () -> Void in fatalError() }.to(throwAssertion()) expect { precondition(false) }.to(throwAssertion()) // Passes if throwing an NSError is not equal to throwing an assertion: expect { throw NSError(domain: "test", code: 0, userInfo: nil) }.toNot(throwAssertion()) // Passes if the code after the precondition check is not run: var reachedPoint1 = false var reachedPoint2 = false expect { reachedPoint1 = true precondition(false, "condition message") reachedPoint2 = true }.to(throwAssertion()) expect(reachedPoint1) == true expect(reachedPoint2) == false ``` -------------------------------- ### Integrate CwlCatchException using CocoaPods Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/CwlCatchException/README.md Instructions for integrating CwlCatchException into an Xcode project using CocoaPods. This requires specifying the pod in your Podfile with the desired version range. ```Ruby pod 'CwlCatchException', '~> 2.0' ``` -------------------------------- ### Verify a Matcher Always or Never Matches Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/Nimble/README.md Demonstrates how to use `toAlways` and `toNever` to assert that a value consistently matches or never matches a given expectation throughout the timeout period. This is useful for verifying invariant conditions. ```Swift // Swift ocean.add("dolphins") expect(ocean).toAlways(contain("dolphins")) expect(ocean).toNever(contain("hares")) ``` ```Objective-C // Objective-C [ocean add:@"dolphins"] expect(ocean).toAlways(contain(@"dolphins")) expect(ocean).toNever(contain(@"hares")) ``` -------------------------------- ### Testing Exceptions in Swift and Objective-C Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/Nimble/README.md Demonstrates using the `raiseException` matcher to test for exceptions. It covers checking for any exception, specific names, names with reasons, or exceptions satisfying custom conditions. Note that Swift's exception handling differs from Objective-C's. ```Swift // Swift // Passes if 'actual', when evaluated, raises an exception: expect(actual).to(raiseException()) // Passes if 'actual' raises an exception with the given name: expect(actual).to(raiseException(named: name)) // Passes if 'actual' raises an exception with the given name and reason: expect(actual).to(raiseException(named: name, reason: reason)) // Passes if 'actual' raises an exception which passes expectations defined in the given closure: // (in this case, if the exception's name begins with "a r") expect { exception.raise() }.to(raiseException { (exception: NSException) in expect(exception.name).to(beginWith("a r")) }) ``` ```Objective-C // Objective-C // Passes if 'actual', when evaluated, raises an exception: expect(actual).to(raiseException()) // Passes if 'actual' raises an exception with the given name expect(actual).to(raiseException().named(name)) // Passes if 'actual' raises an exception with the given name and reason: expect(actual).to(raiseException().named(name).reason(reason)) // Passes if 'actual' raises an exception and it passes expectations defined in the given block: // (in this case, if name begins with "a r") expect(actual).to(raiseException().satisfyingBlock(^(NSException *exception) { expect(exception.name).to(beginWith(@"a r")); })); ``` -------------------------------- ### Configure Xcode Scheme for Snapshot Test Directories Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/iOSSnapshotTestCase/README.md Define environment variables in your Xcode test scheme to specify the directories for storing reference images (`FB_REFERENCE_IMAGE_DIR`) and diffs of failed snapshots (`IMAGE_DIFF_DIR`). This ensures that snapshot tests can locate and save their required files correctly. ```APIDOC Xcode Scheme Environment Variables: FB_REFERENCE_IMAGE_DIR: Description: Path to the directory where reference images are stored. Value: $(SOURCE_ROOT)/$(PROJECT_NAME)Tests/ReferenceImages IMAGE_DIFF_DIR: Description: Path to the directory where diffs of failed snapshots are stored. Value: $(SOURCE_ROOT)/$(PROJECT_NAME)Tests/FailureDiffs ``` -------------------------------- ### Asserting Inequality with Nimble's `toNot` and `notTo` Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/Nimble/README.md Shows how to express negative expectations (asserting something is not equal) using Nimble's `toNot` and `notTo` matchers. Both forms achieve the same outcome for asserting inequality. ```Swift import Nimble expect(seagull.squawk).toNot(equal("Oh, hello there!")) expect(seagull.squawk).notTo(equal("Oh, hello there!")) ``` ```Objective-C @import Nimble; expect(seagull.squawk).toNot(equal(@"Oh, hello there!")); expect(seagull.squawk).notTo(equal(@"Oh, hello there!")); ``` -------------------------------- ### Handle Nil Values with Nimble's beNil Matcher in Objective-C Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/Nimble/README.md Compares the behavior of `equal(nil)` and `beNil()` when asserting on `nil` values in Objective-C, highlighting that `beNil()` is the correct and intended matcher for `nil` expectations to prevent unexpected test failures. ```Objective-C expect(nil).to(equal(nil)); // fails expect(nil).to(beNil()); // passes ``` -------------------------------- ### Testing Asynchronous Functions with Nimble's Async/Await Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/Nimble/README.md Nimble provides seamless support for testing asynchronous functions using Swift's async/await. The `expect` function awaits the async function's completion before passing its result to the matcher. For scenarios requiring autoclosures or explicit synchronous expectations, `expecta` (expect async) and `expects` (expect sync) functions are available respectively. ```Swift // Swift await expect { await aFunctionReturning1() }.to(equal(1)) ``` ```Swift // Swift await expecta(await aFunctionReturning1()).to(equal(1))) ``` ```Swift // Swift expects(someNonAsyncFunction()).to(equal(1))) expects(await someAsyncFunction()).to(equal(1)) // Compiler error: 'async' call in an autoclosure that does not support concurrency ``` -------------------------------- ### Remove libswiftXCTest.dylib in Post-Build Action Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/Nimble/README.md This shell script is intended to be used as a post-build action in Xcode. Its purpose is to remove the `libswiftXCTest.dylib` library from the application's destination directory, addressing an issue where it might be unnecessarily copied into the app bundle when using Nimble without XCTest. ```shell rm "${SWIFT_STDLIB_TOOL_DESTINATION_DIR}/libswiftXCTest.dylib" ``` -------------------------------- ### Add CwlCatchException using Swift Package Manager Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/CwlCatchExceptionSupport/README.md Adds CwlCatchException as a dependency to your Swift Package Manager project by including it in the `dependencies` array of your `Package.swift` file. ```Swift Package Manager config .package(url: "https://github.com/mattgallagher/CwlCatchException.git", from: Version("2.0.0")) ``` -------------------------------- ### Compare arrays of floating-point numbers Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/Nimble/README.md Shows how to apply `beCloseTo` to arrays of floating-point numbers, allowing for element-wise proximity checks within a specified delta. ```Swift expect([0.0, 2.0]) ≈ [0.0001, 2.0001] expect([0.0, 2.0]).to(beCloseTo([0.1, 2.1], within: 0.1)) ``` -------------------------------- ### Compare floating-point numbers with `beCloseTo` Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/Nimble/README.md Explains how to assert that two floating-point numbers are close to each other within a specified margin of error (`delta`), addressing potential issues with direct equality checks. Values must conform to `FloatingPoint`. ```Swift expect(actual).to(beCloseTo(expected, within: delta)) ``` ```Objective-C expect(actual).to(beCloseTo(expected).within(delta)); ``` -------------------------------- ### Asserting Equality with XCTest Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/Nimble/README.md Demonstrates how to use XCTest's `XCTAssertEqual` macro to assert that two values are equal, including an optional failure message. This is a basic assertion mechanism provided by Apple's XCTest framework. ```Swift XCTAssertEqual(1 + 1, 2, "expected one plus one to equal two") ``` ```Objective-C XCTAssertEqual(1 + 1, 2, @"expected one plus one to equal two"); ``` -------------------------------- ### Check object type and class hierarchy Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/Nimble/README.md Illustrates the use of `beAnInstanceOf` to check for exact class membership and `beAKindOf` to check for class membership or subclass membership. Instances must be Objective-C objects or Swift objects bridged to Objective-C. ```Swift // Passes if 'instance' is an instance of 'aClass': expect(instance).to(beAnInstanceOf(aClass)) // Passes if 'instance' is an instance of 'aClass' or any of its subclasses: expect(instance).to(beAKindOf(aClass)) ``` ```Objective-C // Passes if 'instance' is an instance of 'aClass': expect(instance).to(beAnInstanceOf(aClass)); // Passes if 'instance' is an instance of 'aClass' or any of its subclasses: expect(instance).to(beAKindOf(aClass)); ``` -------------------------------- ### Assert truthiness, falsiness, and nil values Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/Nimble/README.md Documents various matchers for checking boolean states and nil values: `beTruthy` (not nil, true, or boolean true object), `beTrue` (only true), `beFalsy` (nil, false, or boolean false object), `beFalse` (only false), and `beNil` (only nil). ```Swift // Passes if 'actual' is not nil, true, or an object with a boolean value of true: expect(actual).to(beTruthy()) // Passes if 'actual' is only true (not nil or an object conforming to Boolean true): expect(actual).to(beTrue()) // Passes if 'actual' is nil, false, or an object with a boolean value of false: expect(actual).to(beFalsy()) // Passes if 'actual' is only false (not nil or an object conforming to Boolean false): expect(actual).to(beFalse()) // Passes if 'actual' is nil: expect(actual).to(beNil()) ``` ```Objective-C // Passes if 'actual' is not nil, true, or an object with a boolean value of true: expect(actual).to(beTruthy()); // Passes if 'actual' is only true (not nil or an object conforming to Boolean true): expect(actual).to(beTrue()); // Passes if 'actual' is nil, false, or an object with a boolean value of false: expect(actual).to(beFalsy()); // Passes if 'actual' is only false (not nil or an object conforming to Boolean false): expect(actual).to(beFalse()); // Passes if 'actual' is nil: expect(actual).to(beNil()); ``` -------------------------------- ### Adding Custom Failure Messages to Nimble Expectations Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/Nimble/README.md Demonstrates how to provide custom failure messages for Nimble expectations using the `description` argument in Swift or `toWithDescription` in Objective-C. This enhances debugging by providing more context when an assertion fails. ```Swift expect(1 + 1).to(equal(3)) expect(1 + 1).to(equal(3), description: "Make sure libKindergartenMath is loaded") ``` ```Objective-C @import Nimble; expect(@(1+1)).to(equal(@3)); expect(@(1+1)).toWithDescription(equal(@3), @"Make sure libKindergartenMath is loaded"); ``` -------------------------------- ### Using Operator Overloads for Concise Expectations in Swift Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/Nimble/README.md Demonstrates the use of overloaded operators like `!=` and `>` in Nimble for Swift, providing a more concise syntax for common comparisons. This feature is exclusive to Swift due to its operator overloading capabilities. ```Swift // Passes if squawk does not equal "Hi!": expect(seagull.squawk) != "Hi!" // Passes if 10 is greater than 2: expect(10) > 2 ``` -------------------------------- ### Add CwlCatchException dependency using Swift Package Manager Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/CwlCatchException/README.md Instructions for adding CwlCatchException as a dependency to a Swift project using Swift Package Manager. This involves adding the package URL and version to the 'dependencies' array in your 'Package.swift' file or directly in Xcode. ```Swift .package(url: "https://github.com/mattgallagher/CwlCatchException.git", from: Version("2.0.0")) ``` -------------------------------- ### Creating a Custom `equal` Matcher Function in Swift Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/Nimble/README.md This snippet demonstrates how to define a custom `equal` matcher function in Swift for Nimble. It shows how a matcher takes an expected value and returns a `Matcher` closure, which then evaluates an `actualExpression` and returns a `MatcherResult` indicating success or failure with an appropriate message. ```Swift public func equal(expectedValue: T?) -> Matcher { // Can be shortened to: // Matcher { actual in ... } // // But shown with types here for clarity. return Matcher { (actualExpression: Expression) throws -> MatcherResult in let msg = ExpectationMessage.expectedActualValueTo("equal <\(expectedValue)>") if let actualValue = try actualExpression.evaluate() { return MatcherResult( bool: actualValue == expectedValue!, message: msg ) } else { return MatcherResult( status: .fail, message: msg.appendedBeNilHint() ) } } } ``` -------------------------------- ### Integrate CwlCatchException with CocoaPods Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/CwlCatchExceptionSupport/README.md Integrates CwlCatchException into an Xcode project using CocoaPods by specifying it in your Podfile. ```Podfile config pod 'CwlCatchException', '~> 2.0' ``` -------------------------------- ### Assert Posted Notifications (Swift) Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/Nimble/README.md Demonstrates how to use `postNotifications` to verify that a closure posts specific notifications to the default `NotificationCenter` or a given `NotificationCenter`. Also shows usage with `DistributedNotificationCenter` for observing notifications by name. This matcher is only available in Swift. ```Swift // Swift let testNotification = Notification(name: Notification.Name("Foo"), object: nil) // Passes if the closure in expect { ... } posts a notification to the default // notification center. expect { NotificationCenter.default.post(testNotification) }.to(postNotifications(equal([testNotification]))) // Passes if the closure in expect { ... } posts a notification to a given // notification center let notificationCenter = NotificationCenter() expect { notificationCenter.post(testNotification) }.to(postNotifications(equal([testNotification]), from: notificationCenter)) // Passes if the closure in expect { ... } posts a notification with the provided names to a given // notification center. Make sure to use this when running tests on Catalina, // using DistributedNotificationCenter as there is currently no way // of observing notifications without providing specific names. let distributedNotificationCenter = DistributedNotificationCenter() expect { distributedNotificationCenter.post(testNotification) }.toEventually(postDistributedNotifications(equal([testNotification]), from: distributedNotificationCenter, names: [testNotification.name])) ``` -------------------------------- ### Swift operator shortcut for `beCloseTo` (`±`) Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/Nimble/README.md Presents another Swift operator shortcut, `±`, for expressing floating-point proximity, allowing for more readable assertions. ```Swift expect(actual) ≈ expected ± delta expect(actual) == expected ± delta ``` -------------------------------- ### Customize Timeout and Polling Interval for Expectations Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/Nimble/README.md Demonstrates how to adjust the `timeout` and `pollInterval` parameters for `toEventually` expectations. This allows fine-tuning the waiting period and the frequency of re-evaluation for asynchronous assertions. ```Swift // Swift // Waits three seconds for ocean to contain "starfish": expect(ocean).toEventually(contain("starfish"), timeout: .seconds(3)) // Evaluate someValue every 0.2 seconds repeatedly until it equals 100, or fails if it timeouts after 5.5 seconds. expect(someValue).toEventually(equal(100), timeout: .milliseconds(5500), pollInterval: .milliseconds(200)) ``` ```Objective-C // Objective-C // Waits three seconds for ocean to contain "starfish": expect(ocean).withTimeout(3).toEventually(contain(@"starfish")); ``` -------------------------------- ### Custom Error Handling with Nimble's `require` in Swift Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/Nimble/README.md This snippet demonstrates how to customize the error thrown by `require` when a matcher fails. By passing a `customError` parameter, developers can replace the default `RequireError` with a specific error type relevant to their test case. ```swift try require(1).to(equal(2)) // throws a `RequireError` try require(customError: MyCustomError(), 1).to(equal(2)) // throws a `MyCustomError` ``` -------------------------------- ### Compare Object Equivalence with equal (Swift, Objective-C) Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/Nimble/README.md This snippet demonstrates how to use the `equal` matcher to assert if two values are equivalent. It supports both Swift and Objective-C, requiring values to be `Equatable`, `Comparable`, or `NSObject` subclasses. It's important to note that `equal` will always fail when comparing `nil` values. ```Swift // Passes if 'actual' is equivalent to 'expected': expect(actual).to(equal(expected)) expect(actual) == expected // Passes if 'actual' is not equivalent to 'expected': expect(actual).toNot(equal(expected)) expect(actual) != expected ``` ```Objective-C // Objective-C // Passes if 'actual' is equivalent to 'expected': expect(actual).to(equal(expected)) // Passes if 'actual' is not equivalent to 'expected': expect(actual).toNot(equal(expected)) ``` -------------------------------- ### Matching a Value to Any of a Group of Matchers Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/Nimble/README.md This section demonstrates how to match a value against multiple conditions using `satisfyAnyOf` or the `||` operator in Swift and Objective-C. It highlights the flexibility of chaining matchers, allowing for any number of conditions. While powerful, it advises caution against over-chaining as it can lead to unfocused tests. ```Swift // Swift // passes if actual is either less than 10 or greater than 20 expect(actual).to(satisfyAnyOf(beLessThan(10), beGreaterThan(20))) // can include any number of matchers -- the following will pass // **be careful** -- too many matchers can be the sign of an unfocused test expect(6).to(satisfyAnyOf(equal(2), equal(3), equal(4), equal(5), equal(6), equal(7))) // in Swift you also have the option to use the || operator to achieve a similar function expect(82).to(beLessThan(50) || beGreaterThan(80)) ``` ```Objective-C // Objective-C // passes if actual is either less than 10 or greater than 20 expect(actual).to(satisfyAnyOf(beLessThan(@10), beGreaterThan(@20))) // can include any number of matchers -- the following will pass // **be careful** -- too many matchers can be the sign of an unfocused test expect(@6).to(satisfyAnyOf(equal(@2), equal(@3), equal(@4), equal(@5), equal(@6), equal(@7))) ``` -------------------------------- ### GoCardless SDK Error Types Reference Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/README.md Details on the types of errors (GoCardlessError and its derivatives) that can be encountered when interacting with the GoCardless API, providing context for debugging and error handling. ```APIDOC GoCardlessError Types: AuthenticationError: Indicates an issue with authentication. GoCardlessInternalError: Denotes an internal error within the GoCardless system. InvalidApiUsageError: Occurs when the API is used incorrectly. InvalidStateError: Indicates an invalid state in the system. MalformedResponseError: Denotes an issue with the response received from the API. PermissionError: Occurs when the user does not have the necessary permissions. RateLimitError: Indicates that the rate limit for API requests has been exceeded. ValidationFailedError: Denotes a validation failure, usually with user input. ``` -------------------------------- ### Check Collection Membership and Emptiness Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/Nimble/README.md Demonstrates how to use `contain` to assert if a collection includes specific elements and `beEmpty` to check if a collection contains no elements. Note that Swift's `contain` accepts multiple arguments, while Objective-C's currently accepts only one. ```Swift // Passes if all of the expected values are members of 'actual': expect(actual).to(contain(expected...)) // Passes if 'actual' is empty (i.e. it contains no elements): expect(actual).to(beEmpty()) // Example: expect(["whale", "dolphin", "starfish"]).to(contain("dolphin", "starfish")) ``` ```Objective-C // Passes if expected is a member of 'actual': expect(actual).to(contain(expected)); // Passes if 'actual' is empty (i.e. it contains no elements): expect(actual).to(beEmpty()); // Example: expect(@[@"whale", @"dolphin", @"starfish"]).to(contain(@"dolphin")); expect(@[@"whale", @"dolphin", @"starfish"]).to(contain(@"starfish")); ``` -------------------------------- ### Swift operator shortcut for `beCloseTo` (`≈`) Source: https://github.com/gocardless/gocardless-pro-ios-sdk/blob/master/GoCardlessSDK/Example/Pods/Nimble/README.md Introduces the `≈` operator as a concise Swift shortcut for `beCloseTo` assertions. The first form uses a default delta of 0.0001, while the second allows specifying a custom delta. ```Swift expect(actual) ≈ expected expect(actual) ≈ (expected, delta) ```