Assert
public class Assert : NSObject
Users should not need to create individual instances of Assert by themselves; rather, an Assert will automatically be initialized by calling one of the that
functions in the Attest
class. See the Attest class for more information.
-
Removes the Rule specified from the list of Rules that will be run in the analysis.
Declaration
Swift
open func exceptRule(_ ID:RuleID) -> Assert
Parameters
ID
RuleID of the Rule that should be removed from the list.
Return Value
Assert class. This return value should be used to start the analysis.
-
Call this in a Unit Test Case in Swift to analyze the accessibility of the UIView or UIViewController specified in the Attest class. The typical use case for this function is
Attest.that(view: myView).isAccessible({(result:Attest.Result) in XCTAssertEqual(result.violations.count, 0)})
or
Attest.that(viewController: myViewController).isAccessible({(result:Attest.Result) in //Iterate over violations and assert things about each structure individually for violation in result.violations { switch violation.ruleId { case RuleID.SpeakableText: XCTAssertEqual(1, violation.nodes.count, violation.description) case RuleID.DynamicType: XCTAssertEqual(3, violation.nodes.count, violation.description) case RuleID.ColorContrast: XCTAssertEqual(1, violation.nodes.count, violation.description) default: XCTAssertEqual(0, violation.nodes.count, violation.description) } } })
or
Attest.that(storyBoardName: "storyBoard Name").isAccessible({(result:Attest.Result) in //There should only be one rule that's in violation XCTAssertEqual(1, result.violations.count) //There should be four violations of this rule XCTAssertEqual(2, result.violations.first?.nodes.count) //This violation should be on the ColorContrast rule XCTAssertEqual(RuleID.ColorContrast, result.violations.first?.ruleId) }))
The results from the analysis can be seen in full detail in the log.
Declaration
Swift
open func isAccessible(_ resultConsumer: (Attest.Result) -> () = {(result:Attest.Result) -> () in if (!result.violations.isEmpty) { NSException(name: NSExceptionName(rawValue: "Deque Accessibility Failure"), reason: result.description, userInfo: [:]).raise() } else { NSLog(result.description) } })
Parameters
resultConsumer
A function that expects an Attest.Result as a parameter. Specify this to tell the analyzer which violations you expect. If no resultConsumer is supplied, it will fail your test case if there are any violations.
Return Value
None.
-
Call this in a Unit Test Case in Objective C to analyze the accessibility of the UIView or UIViewController specified in the Attest class. The typical use case for this function is:
// Analyzes the view for accessibility and returns a result Result* result = [[Attest thatWithView:view] isAccessible]; // There should be no accessibility violations XCTAssertEqual(result.violations.count, 0); // See all results from the analysis NSLog(@"%@", result.description);
or
// Run the analysis Result* result = [[Attest thatWithViewController:viewController] isAccessible]; // See all results from the analysis NSLog(@"%@", result.description); //Iterate over violations and assert things about each structure individually for (Entry *violation in result.violations) { switch(violation.ruleId) { case RuleIDColorContrast: XCTAssertEqual(violation.nodes.count, 3, @"%@", violation.description); break; case RuleIDDynamicType: XCTAssertEqual(violation.nodes.count, 2, @"%@", violation.description); break; case RuleIDSpeakableText: XCTAssertEqual(violation.nodes.count, 3, @"%@", violation.description); break; default: XCTAssertEqual(violation.nodes.count, 0, @"%@", violation.description); break; } }
or
Result* result = [[Attest thatWithStoryBoardName:@"Main" viewControllerID:NULL bundle:NULL] isAccessible]; // See all results from the analysis NSLog(@"%@", result.description); // Only one Rule should be in violation XCTAssertEqual(result.violations.count, 1); // There should be three violations of this Rule XCTAssertEqual(result.violations.firstObject.nodes.count, 3); // The Rule in violation is the Color Contrast Rule XCTAssertEqual(result.violations.firstObject.ruleId, RuleIDColorContrast);
Return Value
Attest Result. Parse through this result to find violations of Rules or violations of BestPractices.