Giter Club home page Giter Club logo

outlets's Introduction

Outlets logo

Outlets

Utility functions for validating IBOutlet and IBAction connections.

Version License Language Swift 2 Platform Carthage compatible Build Status codecov

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' do
  use_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:

class ViewControllerSpec: QuickSpec {
	override func spec() {
        setupFailHandler { message in
            if let message = message {
                fail(message)
            } else {
                fail()
            }
        }

		var viewController: UIViewController!

		var hasBarButtonItemOutlet: BarButtonItemOutletAssertion!
		var hasSegmentedControlOutlet: SegmentedControlOutletAssertion!
		var receivesAction: ActionAssertion!

		describe("view controller") {
			beforeEach {
				viewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("ViewController")
				viewController.loadView()
				expect(viewController.view).toNot(beNil())

                setupActionValidator { target, action, expectedAction in
                    expect(target) === viewController
                    expect(action).toNot(beNil())
                    if let 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.

outlets's People

Contributors

phatblat avatar esttorhe avatar

Stargazers

Rakhim Abdullayev avatar frankfanslc avatar Alexander Mendez avatar Yasin ATEŞ avatar Bogdan Bystritskiy avatar Takuya Ohsawa avatar James Cliburn avatar RealBug avatar Florian Petit avatar Ronnie Vega avatar Michal Zygar avatar Adam Gr avatar Hoang Tran avatar Ignacio Romero Zurbuchen avatar Sander Soots avatar Felix  avatar Greg Price avatar Jurģis Ķiršakmens avatar Deepu Mukundan avatar Russell Finn avatar teriiehina avatar Basem avatar Lucas Farah avatar Ivan Vavilov avatar Keita Ito avatar Karlis avatar Rob Cecil avatar Usama Sadiq avatar Walter Skyrim avatar Yannick Stephan avatar Alex Rupérez avatar Albert Devesa avatar Jesse Squires avatar Candost avatar Fabien avatar Nutchaphon Rewik avatar Anat Gilboa avatar Paul Semionov avatar  avatar marcusjpotter avatar Konstantin Pavlikhin avatar  avatar Yoichi Tagaya avatar mono — Masayuki Ono avatar Marcin avatar Yuki Nagai avatar Lasha Efremidze avatar Blue White avatar Michael Pchelnikov avatar Santiago avatar Antonio Cabezuelo Vivo avatar Prashanth avatar David Ohayon avatar Matej Ľach avatar Chinsyo avatar Gurpartap Singh avatar Anton avatar Moshe avatar İsmail avatar  avatar Anıl Göktaş avatar Denis Svara avatar Faiz Mokhtar avatar Steven Masini avatar Hyuk Hur avatar Kirill Kunst avatar  avatar Anton Selyanin avatar Krzysztof Zabłocki avatar  avatar  avatar  avatar JENHAO YEH avatar Marcus Kida avatar Wayne Zhang avatar Gabriel Coronel avatar Mark Anderson avatar Jeff Blagdon avatar kmhjs avatar Seyhun Akyürek avatar Blair McArthur avatar Kieran Harper avatar Carabineiro avatar James Campbell avatar Felix Barros avatar James Pamplona avatar Jorge Maroto avatar Bassem Youssef avatar Max Child avatar Colin Smith avatar Pedro Vereza avatar masters3d avatar Nikolaos Papadakis avatar Tim Kersey avatar Isuru Nanayakkara avatar Alice avatar Nate West avatar Tony Wang avatar Joshue Santibanez avatar Boris Bügling avatar

Watchers

 avatar James Cloos avatar  avatar Carabineiro avatar Evgeniy avatar John Lah Boo avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.