插件 0.1.0

插件 0.1.0

测试已测试
语言语言 SwiftSwift
授权 MIT
发布时间最近发布2016年5月
SPM支持SPM

Ben Chatelain维护。




插件 0.1.0

插件

插件提供了一套函数,用于验证Storyboard/XIB文件和视图控制器属性之间是否连接了IBOutlets。它还可以验证IBAction方法是否正确连接。

要了解方法和这些断言是如何工作的,请参见使用Swift中的柯里化函数测试IBOutlets和IBActions

示例

要运行示例项目,请克隆仓库,然后首先从Example目录运行pod install

以下是Outlets与Quick和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")
            }
        }
    }
}

要求

  • Xcode 7.3+
  • CocoaPods 0.39+

安装

插件通过CocoaPods提供。要安装它,只需将以下行添加到Podfile中

pod "Outlets"

作者

Ben Chatelain, @phatblat

许可证

此存储库的许可证为MIT许可证。有关权利和限制,请参阅许可文件。