Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate Connectivity + Example Project #16

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Example/Cara.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
4858291A21DD4611007EB5D9 /* DemoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4858291921DD4611007EB5D9 /* DemoViewController.swift */; };
4858291C21DD4659007EB5D9 /* NetworkReachability.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4858291B21DD4659007EB5D9 /* NetworkReachability.storyboard */; };
4858291E21DD4662007EB5D9 /* NetworkReachabilityViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4858291D21DD4662007EB5D9 /* NetworkReachabilityViewController.swift */; };
4858292121DD4C79007EB5D9 /* NetworkReachabilitySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4858292021DD4C79007EB5D9 /* NetworkReachabilitySpec.swift */; };
9D0E402C21B3FC490088D678 /* CaraQuickConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D0E402B21B3FC490088D678 /* CaraQuickConfiguration.swift */; };
9D21FEF121D8EE98006EF131 /* PublicKeyPinningServiceSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D21FEF021D8EE98006EF131 /* PublicKeyPinningServiceSpec.swift */; };
9D21FEF321D8F02F006EF131 /* SecTrust+Apple.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D21FEF221D8F02F006EF131 /* SecTrust+Apple.swift */; };
Expand Down Expand Up @@ -46,6 +47,7 @@
4858291921DD4611007EB5D9 /* DemoViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DemoViewController.swift; sourceTree = "<group>"; };
4858291B21DD4659007EB5D9 /* NetworkReachability.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = NetworkReachability.storyboard; sourceTree = "<group>"; };
4858291D21DD4662007EB5D9 /* NetworkReachabilityViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkReachabilityViewController.swift; sourceTree = "<group>"; };
4858292021DD4C79007EB5D9 /* NetworkReachabilitySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkReachabilitySpec.swift; sourceTree = "<group>"; };
4988D65755E7E3702B299D5A /* Pods_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; };
4C18691E9CCE6AA5DA2037B9 /* Pods-Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Tests.release.xcconfig"; path = "Pods/Target Support Files/Pods-Tests/Pods-Tests.release.xcconfig"; sourceTree = "<group>"; };
607FACE51AFB9204008FA782 /* Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Tests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -136,6 +138,14 @@
path = Demo;
sourceTree = "<group>";
};
4858291F21DD4C65007EB5D9 /* Reachability */ = {
isa = PBXGroup;
children = (
4858292021DD4C79007EB5D9 /* NetworkReachabilitySpec.swift */,
);
path = Reachability;
sourceTree = "<group>";
};
607FACC71AFB9204008FA782 = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -179,6 +189,7 @@
62263AAD1D0704F700393E94 /* Specs */ = {
isa = PBXGroup;
children = (
4858291F21DD4C65007EB5D9 /* Reachability */,
9DAD37C321B45A860042C19C /* Request */,
9DAD37BE21B4399F0042C19C /* Serializer */,
9DAD37BD21B439990042C19C /* Service */,
Expand Down Expand Up @@ -510,6 +521,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
4858292121DD4C79007EB5D9 /* NetworkReachabilitySpec.swift in Sources */,
9D446A9C21B3EAC100FEA1F7 /* ServiceSpec.swift in Sources */,
9D21FF0621D97196006EF131 /* NetworkServiceSpec.swift in Sources */,
9DAD37C521B45A900042C19C /* RequestSpec.swift in Sources */,
Expand Down
43 changes: 43 additions & 0 deletions Example/Tests/Specs/Reachability/NetworkReachabilitySpec.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// NetworkReachabilitySpec.swift
// Tests
//
// Created by Dylan Gyesbreghs on 02/01/2019.
// Copyright © 2019 icapps. All rights reserved.
//

import Quick
import Nimble
import Mockingjay
import Connectivity

@testable import Cara

class NetworkReachabilitySpec: QuickSpec {

class MockedNetworkReachability: NetworkReachability {
override func startListening() {
guard let listener = listener else { return }
listener(ConnectivityStatus.connectedViaWiFi)
}
}

override func spec() {
describe("CodableSerializer") {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I mostly do when testing external libraries like these. I create a mock object like you did above and I stub all the methods that could potentially be called by Cara.

ex.

class MockedNetworkReachability: NetworkReachability {
    private(set) var didTriggerStartListening: Bool = false
    override func startListening() {
        didTriggerStartListening = true
    }
}

Here is what I test:

it("should trigger start listening") {
    service.theFunctionThatTriggersStartListening()
    expect(networkReachability.didTriggerStartListening) == true
}

I would not trigger it on the mocked object though. What I would do in this case I would create a MockedConnectivity and test if the correct method is triggered on that class.

If it's unclear, I can show you in one of my projects somewhere this week.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have made a couple of changes, but it will be useful if you can show a example next week 🙂

var networkReachability: NetworkReachability!
beforeEach {
networkReachability = MockedNetworkReachability()
}

it("should return ConnectivityStatus.connectedViaWiFi.") {
waitUntil { done in
networkReachability.listener = { status in
expect(status) == ConnectivityStatus.connectedViaWiFi
done()
}
networkReachability.startListening()
}
}
}
}
}