AMPopTip
repository·main·Indexed 25 days ago
https://github.com/andreamazz/ampoptipAn animated popover library for iOS that allows developers to display subtle hints, onboarding popups, or custom views that 'pop out' of a specific frame. It supports both UIKit and SwiftUI.
What's inside AMPopTip
- Nimble is a matcher framework used to express the expected outcomes of Swift or Objective-C expressions. It provides a more natural and readable syntax for assertions compared to standard XCTest macros, specifically addressing the lack of diverse assertion macros and the difficulty of writing asynchronous tests in XCTest.
Test for exceptions and raised errors
mainBecause
expectevaluates its argument lazily, you can pass a closure to test if an expression raises an exception.In Swift, this is primarily for catching Objective-C exceptions. In Objective-C, you must use the
expectActionmacro for expressions that do not return a value.Install iOSSnapshotTestCase via CocoaPods
mainTo install
iOSSnapshotTestCaseusing CocoaPods, add it to your Podfile. If your test target is Objective-C only, useiOSSnapshotTestCase/Coreto avoid Swift support overhead.target "Tests" do use_frameworks! pod 'iOSSnapshotTestCase' endTest C Primitives
mainNimble supports C primitives (like
CInt) in Swift using type inference. In Objective-C, primitive C values must be wrapped in an object literal (e.g.,@()) to be used with Nimble.// Swift let actual: CInt = 1 expect(actual).to(equal(1)) // Objective-C expect(@(1 + 1)).to(equal(@2));Install iOSSnapshotTestCase via Swift Package Manager
mainAdd the dependency to your
Package.swiftor use the Xcode interface with the repository URL. It is recommended to use "Up to Next Major" versioning.dependencies: [ .package(url: "https://github.com/uber/ios-snapshot-test-case.git", from: "7.0.0"), ],Install Nimble as a Git Submodule
mainTo use Nimble as a submodule for macOS, iOS, or tvOS applications:
- Clone the Nimble repository.
- Add
Nimble.xcodeprojto your Xcode workspace. - Link
Nimble.frameworkto your test target.
Install Quick and Nimble via Swift Package Manager
mainTo install Quick and Nimble using Swift Package Manager, add the following dependencies to your
Package.swiftfile:dependencies: [ .package(url: "https://github.com/Quick/Quick.git", from: "7.0.0"), .package(url: "https://github.com/Quick/Nimble.git", from: "12.0.0"), ],Use Nimble-Snapshots for basic snapshot testing
mainUse
haveValidSnapshot()to assert that a view matches its recorded snapshot. You can provide a custom name for the snapshot usingnamed:or use the shorthand== snapshot("name")syntax. To record new snapshots, userecordSnapshot()or the emoji operator📷.import Quick import Nimble import Nimble_Snapshots import UIKit class MySpec: QuickSpec { override func spec() { describe("in some context") { it("has valid snapshot") { let view = ... // some view you want to test expect(view).to( haveValidSnapshot() ) } } } } // Custom named snapshots expect(view).to( haveValidSnapshot(named: "some custom name") ) expect(view) == snapshot("some custom name") // Recording snapshots expect(view).to( recordSnapshot() ) expect(view).to( recordSnapshot(named: "some custom name") ) 📷(view) 📷(view, "some custom name")Install Nimble-Snapshots via Swift Package Manager
mainAdd
Nimble-Snapshotsto thedependenciesarray of yourPackage.swiftand include it in your target'sdependencies.import PackageDescription let package = Package( name: "<Your Product Name>", dependencies: [ .package(url: "https://github.com/ashfurrow/Nimble-Snapshots", .upToNextMajor(from: "9.0.0")) ], targets: [ .target( name: "<Your Target Name>", dependencies: ["Nimble-Snapshots"]), ] )Customize failure messages in matchers
mainNimble provides several ways to control the error message shown when a test fails:
Predicate.simple(message)orPredicate.simpleNilable(message): Automatically generates a standard message:"expected to <message>, got <actual>".Predicate.define(message): Allows you to receive a pre-constructedExpectationMessage(msg) and return a customPredicateResult.- Full Customization: Return a
PredicateResultdirectly to use anyExpectationMessagecase (like.expectedToor.expectedCustomValueTo).
public func equal<T: Equatable>(_ expectedValue: T?) -> Predicate<T> { return Predicate.define("equal <\(stringify(expectedValue))>") { actualExpression, msg in let actualValue = try actualExpression.evaluate() let matches = actualValue == expectedValue && expectedValue != nil // ... custom logic returning PredicateResult ... return PredicateResult(bool: matches, message: msg) } }Use Nimble without XCTest (Standalone App)
mainTo use Nimble in a standalone app outside of XCTest, you must implement a custom assertion handler and perform a post-build cleanup to prevent unnecessary library copying.
1. Implement and assign an AssertionHandler
Create a class conforming to
AssertionHandlerand assign it to the globalNimbleAssertionHandlervariable before using assertions.2. Add Post-build Action
To prevent the Swift XCTest support library from being copied into your app:
- Edit your scheme in Xcode and navigate to Build -> Post-actions.
- Click + and select New Run Script Action.
- Set "Provide build settings from" to your target.
- Add the following script:
rm "${SWIFT_STDLIB_TOOL_DESTINATION_DIR}/libswiftXCTest.dylib"
class MyAssertionHandler : AssertionHandler { func assert(assertion: Bool, message: FailureMessage, location: SourceLocation) { if (!assertion) { print("Expectation failed: \(message.stringValue)") } } } // Somewhere before you use any assertions NimbleAssertionHandler = MyAssertionHandler()Install iOSSnapshotTestCase via Carthage
mainAdd the following line to your
Cartfileto install via Carthage:github "uber/ios-snapshot-test-case" ~> 6.1.0