Skip to content

Commit

Permalink
Add failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubvano committed Oct 28, 2016
1 parent 3c0a184 commit 83d3aa5
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 0 deletions.
20 changes: 20 additions & 0 deletions SwinjectStoryboard.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@
CD2C63AD1D786C1F0075BC14 /* RelationshipReference1.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CD2C63AC1D786C1F0075BC14 /* RelationshipReference1.storyboard */; };
CD2C63AF1D786CD70075BC14 /* RelationshipReference2.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CD2C63AE1D786CD70075BC14 /* RelationshipReference2.storyboard */; };
CD2C63B01D786D6B0075BC14 /* SwinjectStoryboard+StoryboardReference.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD2C63A91D7864840075BC14 /* SwinjectStoryboard+StoryboardReference.swift */; };
CD3AB1991DC3A851001A45FA /* AnimalPagesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD3AB1981DC3A851001A45FA /* AnimalPagesViewController.swift */; };
CD3AB19A1DC3A851001A45FA /* AnimalPagesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD3AB1981DC3A851001A45FA /* AnimalPagesViewController.swift */; };
CD3AB1A91DC3A858001A45FA /* Pages.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CD3AB1A81DC3A858001A45FA /* Pages.storyboard */; };
CD3AB1AA1DC3A858001A45FA /* Pages.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CD3AB1A81DC3A858001A45FA /* Pages.storyboard */; };
CD3AB1AE1DC3A8CD001A45FA /* AnimalPagesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD3AB1AD1DC3A8CD001A45FA /* AnimalPagesViewController.swift */; };
CD3AB1B01DC3A8D6001A45FA /* Pages.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CD3AB1AF1DC3A8D6001A45FA /* Pages.storyboard */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -423,6 +429,10 @@
CD2C63A91D7864840075BC14 /* SwinjectStoryboard+StoryboardReference.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "SwinjectStoryboard+StoryboardReference.swift"; sourceTree = "<group>"; };
CD2C63AC1D786C1F0075BC14 /* RelationshipReference1.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = RelationshipReference1.storyboard; sourceTree = "<group>"; };
CD2C63AE1D786CD70075BC14 /* RelationshipReference2.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = RelationshipReference2.storyboard; sourceTree = "<group>"; };
CD3AB1981DC3A851001A45FA /* AnimalPagesViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AnimalPagesViewController.swift; sourceTree = "<group>"; };
CD3AB1A81DC3A858001A45FA /* Pages.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Pages.storyboard; sourceTree = "<group>"; };
CD3AB1AD1DC3A8CD001A45FA /* AnimalPagesViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AnimalPagesViewController.swift; sourceTree = "<group>"; };
CD3AB1AF1DC3A8D6001A45FA /* Pages.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Pages.storyboard; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -537,8 +547,10 @@
isa = PBXGroup;
children = (
983DFEF01CDB426100D39731 /* AnimalViewController.swift */,
CD3AB1AD1DC3A8CD001A45FA /* AnimalPagesViewController.swift */,
983DFEF11CDB426100D39731 /* AnimalWindowController.swift */,
983DFEEF1CDB426100D39731 /* Animals.storyboard */,
CD3AB1AF1DC3A8D6001A45FA /* Pages.storyboard */,
983DFEF51CDB426100D39731 /* Tabs.storyboard */,
983DFEF61CDB426100D39731 /* ViewController1.swift */,
CD2C63AC1D786C1F0075BC14 /* RelationshipReference1.storyboard */,
Expand All @@ -553,8 +565,10 @@
isa = PBXGroup;
children = (
983DFED91CDB425600D39731 /* AnimalViewController.swift */,
CD3AB1981DC3A851001A45FA /* AnimalPagesViewController.swift */,
983DFED81CDB425600D39731 /* Animals.storyboard */,
983DFEDD1CDB425600D39731 /* Tabs.storyboard */,
CD3AB1A81DC3A858001A45FA /* Pages.storyboard */,
983DFEDA1CDB425600D39731 /* Storyboard1.storyboard */,
983DFEDB1CDB425600D39731 /* Storyboard2.storyboard */,
983DFED71CDB425600D39731 /* AnimalPlayerViewController.swift */,
Expand Down Expand Up @@ -1138,6 +1152,7 @@
983DFEEC1CDB425600D39731 /* Tabs.storyboard in Resources */,
983DFEDE1CDB425600D39731 /* AnimalPlayerViewController.storyboard in Resources */,
983DFEE61CDB425600D39731 /* Storyboard1.storyboard in Resources */,
CD3AB1A91DC3A858001A45FA /* Pages.storyboard in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -1158,6 +1173,7 @@
983DFEFA1CDB426100D39731 /* Storyboard1.storyboard in Resources */,
CD2C63AD1D786C1F0075BC14 /* RelationshipReference1.storyboard in Resources */,
CD2C63AF1D786CD70075BC14 /* RelationshipReference2.storyboard in Resources */,
CD3AB1B01DC3A8D6001A45FA /* Pages.storyboard in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -1179,6 +1195,7 @@
983DFEED1CDB425600D39731 /* Tabs.storyboard in Resources */,
983DFEDF1CDB425600D39731 /* AnimalPlayerViewController.storyboard in Resources */,
983DFEE71CDB425600D39731 /* Storyboard1.storyboard in Resources */,
CD3AB1AA1DC3A858001A45FA /* Pages.storyboard in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -1207,6 +1224,7 @@
buildActionMask = 2147483647;
files = (
983DFED21CDB423800D39731 /* ViewController+SwinjectSpec.swift in Sources */,
CD3AB1991DC3A851001A45FA /* AnimalPagesViewController.swift in Sources */,
983DFEE41CDB425600D39731 /* AnimalViewController.swift in Sources */,
983DFEEA1CDB425600D39731 /* SwinjectStoryboardSpec.swift in Sources */,
983DFEC91CDB423800D39731 /* Container+SwinjectStoryboardSpec.swift in Sources */,
Expand Down Expand Up @@ -1247,6 +1265,7 @@
983DFF081CDB433A00D39731 /* FoodType.swift in Sources */,
983DFEFC1CDB426100D39731 /* SwinjectStoryboardSpec.swift in Sources */,
983DFED01CDB423800D39731 /* Storyboard+SwizzlingSpec.swift in Sources */,
CD3AB1AE1DC3A8CD001A45FA /* AnimalPagesViewController.swift in Sources */,
983DFECD1CDB423800D39731 /* NSWindowController+SwinjectSpec.swift in Sources */,
983DFEF81CDB426100D39731 /* AnimalViewController.swift in Sources */,
983DFEF91CDB426100D39731 /* AnimalWindowController.swift in Sources */,
Expand Down Expand Up @@ -1276,6 +1295,7 @@
buildActionMask = 2147483647;
files = (
983DFED41CDB423800D39731 /* ViewController+SwinjectSpec.swift in Sources */,
CD3AB19A1DC3A851001A45FA /* AnimalPagesViewController.swift in Sources */,
983DFEE51CDB425600D39731 /* AnimalViewController.swift in Sources */,
983DFEEB1CDB425600D39731 /* SwinjectStoryboardSpec.swift in Sources */,
983DFECB1CDB423800D39731 /* Container+SwinjectStoryboardSpec.swift in Sources */,
Expand Down
23 changes: 23 additions & 0 deletions Tests/OSX/AnimalPagesViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// AnimalPagesViewController.swift
// Swinject
//
// Created by Jakub Vaňo on 27/10/16.
// Copyright © 2016 Swinject Contributors. All rights reserved.
//

import AppKit
import Swinject

internal class AnimalPagesViewController: NSPageController {
let animalPage: AnimalViewController

required init?(coder aDecoder: NSCoder) {
animalPage = NSStoryboard(
name: "Pages",
bundle: Bundle(for: AnimalPagesViewController.self)
).instantiateController(withIdentifier: "AnimalPage") as! AnimalViewController

super.init(coder: aDecoder)
}
}
35 changes: 35 additions & 0 deletions Tests/OSX/Pages.storyboard
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="11201" systemVersion="15G1004" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="DpY-PQ-6TH">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11201"/>
</dependencies>
<scenes>
<!--Animal Pages View Controller-->
<scene sceneID="ajh-jW-cvc">
<objects>
<pagecontroller id="DpY-PQ-6TH" customClass="AnimalPagesViewController" customModule="SwinjectTests" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" id="O2u-zU-y44">
<rect key="frame" x="0.0" y="0.0" width="450" height="300"/>
<autoresizingMask key="autoresizingMask"/>
</view>
</pagecontroller>
<customObject id="Kah-4j-UwY" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-189" y="-5"/>
</scene>
<!--Animal View Controller-->
<scene sceneID="F7O-wN-Mlm">
<objects>
<viewController storyboardIdentifier="AnimalPage" id="laR-VI-hPN" customClass="AnimalViewController" customModule="SwinjectTests" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" id="kEW-PC-iVW">
<rect key="frame" x="0.0" y="0.0" width="450" height="300"/>
<autoresizingMask key="autoresizingMask"/>
</view>
</viewController>
<customObject id="dRT-QK-Lv6" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="282" y="-5"/>
</scene>
</scenes>
</document>
12 changes: 12 additions & 0 deletions Tests/OSX/SwinjectStoryboardSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ class SwinjectStoryboardSpec: QuickSpec {
expect(animalViewController.hasAnimal(named: "Mimi")) == true
}
}
context("with second controller instantiation during instantiation of initial one") {
it("injects second controller.") {
container.storyboardInitCompleted(AnimalViewController.self) { r, c in
c.animal = r.resolve(AnimalType.self)
}
container.register(AnimalType.self) { _ in Cat(name: "Mimi") }

let storyboard = SwinjectStoryboard.create(name: "Pages", bundle: bundle, container: container)
let pagesController = storyboard.instantiateInitialController() as! AnimalPagesViewController
expect(pagesController.animalPage.hasAnimal(named: "Mimi")) == true
}
}
}
describe("Initial controller") {
it("injects dependency definded by initCompleted handler.") {
Expand Down
23 changes: 23 additions & 0 deletions Tests/iOS-tvOS/AnimalPagesViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// AnimalPagesViewController.swift
// Swinject
//
// Created by Jakub Vaňo on 27/10/16.
// Copyright © 2016 Swinject Contributors. All rights reserved.
//

import UIKit
import Swinject

internal class AnimalPagesViewController: UIPageViewController {
let animalPage: AnimalViewController

required init?(coder aDecoder: NSCoder) {
animalPage = UIStoryboard(
name: "Pages",
bundle: Bundle(for: AnimalPagesViewController.self)
).instantiateViewController(withIdentifier: "AnimalPage") as! AnimalViewController

super.init(coder: aDecoder)
}
}
35 changes: 35 additions & 0 deletions Tests/iOS-tvOS/Pages.storyboard
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11201" systemVersion="15G1004" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="c9R-0n-AJU">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11161"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Animal Pages View Controller-->
<scene sceneID="wdC-vN-RNz">
<objects>
<pageViewController autoresizesArchivedViewToFullSize="NO" transitionStyle="pageCurl" navigationOrientation="horizontal" spineLocation="min" id="c9R-0n-AJU" customClass="AnimalPagesViewController" customModule="SwinjectTests" customModuleProvider="target" sceneMemberID="viewController"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="OWH-1u-wrP" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-340" y="121"/>
</scene>
<!--Animal View Controller-->
<scene sceneID="IxS-yc-Y2y">
<objects>
<viewController storyboardIdentifier="AnimalPage" id="DEB-S9-zld" customClass="AnimalViewController" customModule="SwinjectTests" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="TLP-Zd-ePG"/>
<viewControllerLayoutGuide type="bottom" id="gcx-MT-IDE"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="EsB-wj-vOr">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="4nP-pU-g0r" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="340" y="121"/>
</scene>
</scenes>
</document>
12 changes: 12 additions & 0 deletions Tests/iOS-tvOS/SwinjectStoryboardSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@ class SwinjectStoryboardSpec: QuickSpec {
expect(animalViewController.hasAnimal(named: "Mimi")) == true
}
}
context("with second controller instantiation during instantiation of initial one") {
it("injects second controller.") {
container.storyboardInitCompleted(AnimalViewController.self) { r, c in
c.animal = r.resolve(AnimalType.self)
}
container.register(AnimalType.self) { _ in Cat(name: "Mimi") }

let storyboard = SwinjectStoryboard.create(name: "Pages", bundle: bundle, container: container)
let pagesController = storyboard.instantiateInitialViewController() as! AnimalPagesViewController
expect(pagesController.animalPage.hasAnimal(named: "Mimi")) == true
}
}
}
describe("Initial view controller") {
it("injects dependency definded by initCompleted handler.") {
Expand Down

0 comments on commit 83d3aa5

Please sign in to comment.