Skip to content

Repository files navigation

Outlets logo

Outlets

Utility functions for validating IBOutlet and IBAction connections.

VersionLicenseLanguage Swift 2PlatformCarthage compatibleBuild Statuscodecov

About

Outlets provides a set of functions which validate that IBOutlets are correctly connected between your Storyboard/XIB file and view controller properties. It can also validate that IBAction methods are connected correctly as well.

This micro-library is based on the following post: Testing IBOutlets and IBActions With Curried Functions in Swift

Requirements

  • Xcode 7.3+
  • Swift 2.2+
  • iOS 8.0+

Installation

CocoaPods (recommended)

target'AppTests'douse_frameworks!pod'Outlets'end
github "phatblat/Outlets"

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Or run pod try Outlets from the command line.

Getting Started

Here is an example of using Outlets with Quick and Nimble:

classViewControllerSpec:QuickSpec{overridefunc spec(){setupFailHandler{ message iniflet message = message {fail(message)}else{fail()}}varviewController:UIViewController!varhasBarButtonItemOutlet:BarButtonItemOutletAssertion!varhasSegmentedControlOutlet:SegmentedControlOutletAssertion!varreceivesAction:ActionAssertion!describe("view controller"){beforeEach{
viewController =UIStoryboard(name:"Main", bundle:nil).instantiateViewControllerWithIdentifier("ViewController")
viewController.loadView()expect(viewController.view).toNot(beNil())setupActionValidator{ target, action, expectedAction inexpect(target)=== viewController
expect(action).toNot(beNil())iflet action = action {expect(action)== expectedAction
}}
// Capture the new viewController instance for each test
hasBarButtonItemOutlet =outlet(viewController)
hasSegmentedControlOutlet =outlet(viewController)
receivesAction =action(viewController)}
// MARK: - Outlets
it("has a leftButton outlet"){hasBarButtonItemOutlet("leftButton")}it("has a rightButton outlet"){hasBarButtonItemOutlet("rightButton")}it("has a segmentedControl outlet"){hasSegmentedControlOutlet("segmentedControl")}
// MARK: - Actions
it("receives a didTapLeftButton: action from leftButton"){receivesAction("didTapLeftButton:", from:"leftButton")}it("receives a didTapRightButton: action from rightButton"){receivesAction("didTapRightButton:", from:"rightButton")}it("receives a segmentedControlValueDidChange: action from segmentedControl"){receivesAction("segmentedControlValueDidChange:", from:"segmentedControl")}}}}

Author

Ben Chatelain, @phatblat

License

Outlets is released under the MIT License. See the LICENSE file for details.

About

Utility functions for validating IBOutlet and IBAction connections

Resources

Stars

131 stars

Watchers

4 watching

Forks

Releases

Packages

Used by

Contributors

Languages