Skip to content

Commit

Permalink
Merge pull request #159 from devxoul/feature/update-github-actions-ci
Browse files Browse the repository at this point in the history
Fix Unit Tests
  • Loading branch information
OhKanghoon authored Jun 19, 2022
2 parents 37bc2b0 + 5951e5b commit 03cbf96
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 121 deletions.
32 changes: 16 additions & 16 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ jobs:
build:
runs-on: macOS-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v1

- name: Generate Xcode Project
run: swift package generate-xcodeproj
- name: Generate Xcode Project
run: swift package generate-xcodeproj

- name: Carthage Build
run: carthage build --no-skip-current --platform $CARTHAGE_PLATFORMS
- name: Carthage Build
run: carthage build --no-skip-current --platform $CARTHAGE_PLATFORMS

- name: Carthage Archive
run: carthage archive $CARTHAGE_FRAMEWORKS
- name: Carthage Archive
run: carthage archive $CARTHAGE_FRAMEWORKS

- name: Upload Carthage Framework
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ${{ env.CARTHAGE_FRAMEWORK_NAME }}
asset_name: ${{ env.CARTHAGE_FRAMEWORK_NAME }}
asset_content_type: application/zip
- name: Upload Carthage Framework
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ${{ env.CARTHAGE_FRAMEWORK_NAME }}
asset_name: ${{ env.CARTHAGE_FRAMEWORK_NAME }}
asset_content_type: application/zip
63 changes: 32 additions & 31 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@ name: CI

on:
push:
branches:
- master
pull_request:

jobs:
test:
runs-on: macOS-latest
env:
PROJECT: URLNavigator.xcodeproj
SCHEME: URLNavigator-Package
CODECOV_PACKAGE_NAME: URLNavigator
strategy:
matrix:
env:
- sdk: iphonesimulator
destination: platform=iOS Simulator,name=iPhone 11 Pro,OS=latest
destination: platform=iOS Simulator,name=iPhone 13 Pro,OS=latest

- sdk: macosx
destination: arch=x86_64
Expand All @@ -24,32 +25,32 @@ jobs:
destination: platform=tvOS Simulator,name=Apple TV,OS=latest

steps:
- uses: actions/checkout@v1

- name: List SDKs and Devices
run: xcodebuild -showsdks; instruments -s

- name: Generate Xcode Project
run: swift package generate-xcodeproj --enable-code-coverage

- name: Build and Test
run: |
set -o pipefail && xcodebuild clean build test \
-project "$PROJECT" \
-scheme "$SCHEME" \
-sdk "$SDK" \
-destination "$DESTINATION" \
-configuration Debug \
-enableCodeCoverage YES \
CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO | xcpretty -c;
env:
SDK: ${{ matrix.env.sdk }}
DESTINATION: ${{ matrix.env.destination }}

- name: Upload Code Coverage
run: |
bash <(curl -s https://codecov.io/bash) \
-X xcodeplist \
-J "$CODECOV_PACKAGE_NAME"
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- uses: actions/checkout@v3

- name: List SDKs and Devices
run: xcodebuild -showsdks; xcrun xctrace list devices

- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: latest

- name: Build and Test
run: |
set -o pipefail && xcodebuild clean build test \
-scheme "$SCHEME" \
-sdk "$SDK" \
-destination "$DESTINATION" \
-configuration Debug \
-enableCodeCoverage YES \
CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO | xcpretty -c;
env:
SDK: ${{ matrix.env.sdk }}
DESTINATION: ${{ matrix.env.destination }}

- name: Upload Code Coverage
run: |
bash <(curl -s https://codecov.io/bash) \
-X xcodeplist \
-J "$CODECOV_PACKAGE_NAME"
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@
**/xcshareddata
Pods/
Carthage/

# spm
.build/
Packages/
.swiftpm
31 changes: 20 additions & 11 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,39 @@
"object": {
"pins": [
{
"package": "Nimble",
"repositoryURL": "https://github.com/Quick/Nimble.git",
"package": "CwlCatchException",
"repositoryURL": "https://github.com/mattgallagher/CwlCatchException.git",
"state": {
"branch": null,
"revision": "f8657642dfdec9973efc79cc68bcef43a653a2bc",
"version": "8.0.2"
"revision": "35f9e770f54ce62dd8526470f14c6e137cef3eea",
"version": "2.1.1"
}
},
{
"package": "Quick",
"repositoryURL": "https://github.com/Quick/Quick.git",
"package": "CwlPreconditionTesting",
"repositoryURL": "https://github.com/mattgallagher/CwlPreconditionTesting.git",
"state": {
"branch": null,
"revision": "94df9b449508344667e5afc7e80f8bcbff1e4c37",
"revision": "c21f7bab5ca8eee0a9998bbd17ca1d0eb45d4688",
"version": "2.1.0"
}
},
{
"package": "Stubber",
"repositoryURL": "https://github.com/devxoul/Stubber.git",
"package": "Nimble",
"repositoryURL": "https://github.com/Quick/Nimble.git",
"state": {
"branch": null,
"revision": "1f3bde57bde12f5e7b07909848c071e9b73d6edc",
"version": "10.0.0"
}
},
{
"package": "Quick",
"repositoryURL": "https://github.com/Quick/Quick.git",
"state": {
"branch": null,
"revision": "1c1bbdf1e9e1d04009c6c0bdb030af38b503a612",
"version": "1.4.0"
"revision": "f9d519828bb03dfc8125467d8f7b93131951124c",
"version": "5.0.1"
}
}
]
Expand Down
11 changes: 5 additions & 6 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
// swift-tools-version:5.0
// swift-tools-version:5.4

import PackageDescription

let package = Package(
name: "URLNavigator",
platforms: [
.iOS(.v8), .tvOS(.v9),
.iOS(.v9), .tvOS(.v9),
],
products: [
.library(name: "URLMatcher", targets: ["URLMatcher"]),
.library(name: "URLNavigator", targets: ["URLNavigator"]),
],
dependencies: [
.package(url: "https://github.com/Quick/Quick.git", .upToNextMajor(from: "2.1.0")),
.package(url: "https://github.com/Quick/Nimble.git", .upToNextMajor(from: "8.0.2")),
.package(url: "https://github.com/devxoul/Stubber.git", .upToNextMajor(from: "1.4.0")),
.package(url: "https://github.com/Quick/Quick.git", .upToNextMajor(from: "5.0.0")),
.package(url: "https://github.com/Quick/Nimble.git", .upToNextMajor(from: "10.0.0")),
],
targets: [
.target(name: "URLMatcher"),
.target(name: "URLNavigator", dependencies: ["URLMatcher"]),
.testTarget(name: "URLMatcherTests", dependencies: ["URLMatcher", "Quick", "Nimble"]),
.testTarget(name: "URLNavigatorTests", dependencies: ["URLNavigator", "Quick", "Nimble", "Stubber"]),
.testTarget(name: "URLNavigatorTests", dependencies: ["URLNavigator", "Quick", "Nimble"]),
]
)
4 changes: 2 additions & 2 deletions Sources/URLNavigator/UIViewControllerType.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#if os(iOS) || os(tvOS)
import UIKit

public protocol UINavigationControllerType {
public protocol UINavigationControllerType: AnyObject {
func pushViewController(_ viewController: UIViewController, animated: Bool)
}

public protocol UIViewControllerType {
public protocol UIViewControllerType: AnyObject {
func present(_ viewControllerToPresent: UIViewController, animated flag: Bool, completion: (() -> Void)?)
}

Expand Down
72 changes: 32 additions & 40 deletions Tests/URLNavigatorTests/NavigatorSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import UIKit

import Nimble
import Quick
import Stubber

import URLNavigator

Expand Down Expand Up @@ -88,20 +87,18 @@ final class NavigatorSpec: QuickSpec {
let navigationController = StubNavigationController()
navigator.push("myapp://article/123", from: navigationController)

let executions = Stubber.executions(navigationController.pushViewController)
expect(executions.count) == 1
expect(executions[0].arguments.0).to(beAKindOf(ArticleViewController.self))
expect(executions[0].arguments.1) == true
expect(navigationController.pushViewControllerCallCount) == 1
expect(navigationController.pushViewControllerParams?.viewController).to(beAKindOf(ArticleViewController.self))
expect(navigationController.pushViewControllerParams?.animated) == true
}

it("executes pushViewController() with given arguments") {
let navigationController = StubNavigationController()
navigator.push("myapp://article/123", from: navigationController, animated: false)

let executions = Stubber.executions(navigationController.pushViewController)
expect(executions.count) == 1
expect(executions[0].arguments.0).to(beAKindOf(ArticleViewController.self))
expect(executions[0].arguments.1) == false
expect(navigationController.pushViewControllerCallCount) == 1
expect(navigationController.pushViewControllerParams?.viewController).to(beAKindOf(ArticleViewController.self))
expect(navigationController.pushViewControllerParams?.animated) == false
}
}

Expand Down Expand Up @@ -131,11 +128,10 @@ final class NavigatorSpec: QuickSpec {
let rootViewController = StubViewController()
navigator.present("myapp://article/123", from: rootViewController)

let executions = Stubber.executions(rootViewController.present)
expect(executions.count) == 1
expect(executions[0].arguments.0).to(beAKindOf(ArticleViewController.self))
expect(executions[0].arguments.1) == true
expect(executions[0].arguments.2).to(beNil())
expect(rootViewController.presentCallCount) == 1
expect(rootViewController.presentParams?.viewControllerToPresent).to(beAKindOf(ArticleViewController.self))
expect(rootViewController.presentParams?.animated) == true
expect(rootViewController.presentParams?.completion).to(beNil())
}

it("executes present() with given arguments") {
Expand All @@ -145,12 +141,10 @@ final class NavigatorSpec: QuickSpec {
completionExecutionCount += 1
})

let executions = Stubber.executions(rootViewController.present)
expect(executions.count) == 1
expect(executions[0].arguments.0).to(beAKindOf(MyNavigationController.self))
expect(executions[0].arguments.1) == false
expect(executions[0].arguments.2).notTo(beNil())
expect(completionExecutionCount) == 1
expect(rootViewController.presentCallCount) == 1
expect(rootViewController.presentParams?.viewControllerToPresent).to(beAKindOf(MyNavigationController.self))
expect(rootViewController.presentParams?.animated) == false
expect(rootViewController.presentParams?.completion).notTo(beNil())
}
}

Expand Down Expand Up @@ -266,32 +260,31 @@ final class NavigatorSpec: QuickSpec {
context("on push()") {
it("doesn't get called for a not matching url") {
navigator.push("myapp://user/10", from: fromNavigationController)
expect(Stubber.executions(delegate.shouldPush).count) == 0
expect(delegate.shouldPushCallCount) == 0
}

it("doesn't get called when the factory returns nil") {
navigator.push("myapp://article/-1", from: fromNavigationController)
expect(Stubber.executions(delegate.shouldPush).count) == 0
expect(delegate.shouldPushCallCount) == 0
}

it("gets called for a valid url") {
navigator.push("myapp://article/123", from: fromNavigationController)
let executions = Stubber.executions(delegate.shouldPush)
expect(executions.count) == 1
expect(executions[0].arguments.0).to(beAKindOf(ArticleViewController.self))
expect(executions[0].arguments.1) === fromNavigationController
expect(delegate.shouldPushCallCount) == 1
expect(delegate.shouldPushParams?.viewController).to(beAKindOf(ArticleViewController.self))
expect(delegate.shouldPushParams?.from) === fromNavigationController
}

it("doesn't prevent from pushing when returns true") {
Stubber.register(delegate.shouldPush) { _ in true }
delegate.shouldPushStub = true
navigator.push("myapp://article/123", from: fromNavigationController)
expect(Stubber.executions(fromNavigationController.pushViewController).count) == 1
expect(fromNavigationController.pushViewControllerCallCount) == 1
}

it("prevents from pushing when returns false") {
Stubber.register(delegate.shouldPush) { _ in false }
delegate.shouldPushStub = false
navigator.push("myapp://article/123", from: fromNavigationController)
expect(Stubber.executions(fromNavigationController.pushViewController).count) == 0
expect(fromNavigationController.pushViewControllerCallCount) == 0
}
}

Expand All @@ -312,32 +305,31 @@ final class NavigatorSpec: QuickSpec {
context("on present()") {
it("doesn't get called for a not matching url") {
navigator.present("myapp://user/10", from: fromViewController)
expect(Stubber.executions(delegate.shouldPresent).count) == 0
expect(delegate.shouldPresentCallCount) == 0
}

it("doesn't get called when the factory returns nil") {
navigator.present("myapp://article/-1", from: fromViewController)
expect(Stubber.executions(delegate.shouldPresent).count) == 0
expect(delegate.shouldPresentCallCount) == 0
}

it("gets called for a valid url") {
navigator.present("myapp://article/123", from: fromViewController)
let executions = Stubber.executions(delegate.shouldPresent)
expect(executions.count) == 1
expect(executions[0].arguments.0).to(beAKindOf(ArticleViewController.self))
expect(executions[0].arguments.1) === fromViewController
expect(delegate.shouldPresentCallCount) == 1
expect(delegate.shouldPresentParams?.viewController).to(beAKindOf(ArticleViewController.self))
expect(delegate.shouldPresentParams?.from) === fromViewController
}

it("doesn't prevent from presenting when returns true") {
Stubber.register(delegate.shouldPresent) { _ in true }
delegate.shouldPresentStub = true
navigator.present("myapp://article/123", from: fromViewController)
expect(Stubber.executions(fromViewController.present).count) == 1
expect(fromViewController.presentCallCount) == 1
}

it("prevents from presenting when returns false") {
Stubber.register(delegate.shouldPresent) { _ in false }
delegate.shouldPresentStub = false
navigator.present("myapp://article/123", from: fromViewController)
expect(Stubber.executions(fromViewController.present).count) == 0
expect(fromViewController.presentCallCount) == 0
}
}
}
Expand Down
Loading

0 comments on commit 03cbf96

Please sign in to comment.