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

Improve testing #695

Merged
merged 9 commits into from
Jan 2, 2025
3 changes: 0 additions & 3 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
opt_in_rules:
- all
disabled_rules:
- balanced_xctest_lifecycle
- closure_body_length
- contrasted_opening_brace
- explicit_acl
Expand All @@ -17,7 +16,6 @@ disabled_rules:
- explicit_type_interface
- file_header
- file_name
- final_test_case
- force_unwrapping
- function_body_length
- inert_defer
Expand All @@ -26,7 +24,6 @@ disabled_rules:
- no_grouping_extension
- number_separator
- one_declaration_per_file
- prefer_nimble
- prefixed_toplevel_constant
- quick_discouraged_call
- quick_discouraged_pending_test
Expand Down
1 change: 1 addition & 0 deletions Tests/masTests/.swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ disabled_rules:
- force_cast
- force_try
- implicitly_unwrapped_optional
- large_tuple
- no_magic_numbers
14 changes: 5 additions & 9 deletions Tests/masTests/Commands/AccountSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,15 @@ import Quick

@testable import mas

/// Deprecated test.
public class AccountSpec: QuickSpec {
public final class AccountSpec: QuickSpec {
override public func spec() {
beforeSuite {
MAS.initialize()
}
// account command disabled since macOS 12 Monterey https://github.com/mas-cli/mas#known-issues
describe("Account command") {
it("displays active account") {
expect {
try MAS.Account.parse([]).run()
}
.to(throwError(MASError.notSupported))
describe("account command") {
it("displays not supported warning") {
expect(consequencesOf(try MAS.Account.parse([]).run()))
== (error: MASError.notSupported, stdout: "", stderr: "")
}
}
}
Expand Down
8 changes: 3 additions & 5 deletions Tests/masTests/Commands/HomeSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,15 @@ import Quick

@testable import mas

public class HomeSpec: QuickSpec {
public final class HomeSpec: QuickSpec {
override public func spec() {
beforeSuite {
MAS.initialize()
}
describe("home command") {
it("can't find app with unknown ID") {
expect {
try MAS.Home.parse(["999"]).run(searcher: MockAppStoreSearcher())
}
.to(throwError(MASError.unknownAppID(999)))
expect(consequencesOf(try MAS.Home.parse(["999"]).run(searcher: MockAppStoreSearcher())))
== (MASError.unknownAppID(999), "", "")
}
}
}
Expand Down
37 changes: 19 additions & 18 deletions Tests/masTests/Commands/InfoSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,20 @@
// Copyright © 2018 mas-cli. All rights reserved.
//

import Foundation
import Nimble
import Quick

@testable import mas

public class InfoSpec: QuickSpec {
public final class InfoSpec: QuickSpec {
override public func spec() {
beforeSuite {
MAS.initialize()
}
describe("Info command") {
it("can't find app with unknown ID") {
expect {
try MAS.Info.parse(["999"]).run(searcher: MockAppStoreSearcher())
}
.to(throwError(MASError.unknownAppID(999)))
expect(consequencesOf(try MAS.Info.parse(["999"]).run(searcher: MockAppStoreSearcher())))
== (MASError.unknownAppID(999), "", "")
}
it("displays app details") {
let mockResult = SearchResult(
Expand All @@ -36,21 +33,25 @@ public class InfoSpec: QuickSpec {
trackViewUrl: "https://awesome.app",
version: "1.0"
)
expect {
try captureStream(stdout) {
expect(
consequencesOf(
try MAS.Info.parse([String(mockResult.trackId)])
.run(searcher: MockAppStoreSearcher([mockResult.trackId: mockResult]))
}
}
== """
Awesome App 1.0 [$2.00]
By: Awesome Dev
Released: 2019-01-07
Minimum OS: 10.14
Size: 1 KB
From: https://awesome.app
)
)
== (
nil,
"""
Awesome App 1.0 [$2.00]
By: Awesome Dev
Released: 2019-01-07
Minimum OS: 10.14
Size: 1 KB
From: https://awesome.app

"""
""",
""
)
}
}
}
Expand Down
14 changes: 8 additions & 6 deletions Tests/masTests/Commands/InstallSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@ import Quick

@testable import mas

public class InstallSpec: QuickSpec {
public final class InstallSpec: QuickSpec {
override public func spec() {
beforeSuite {
MAS.initialize()
}
xdescribe("install command") {
xit("installs apps") {
expect {
try MAS.Install.parse([]).run(appLibrary: MockAppLibrary(), searcher: MockAppStoreSearcher())
}
.toNot(throwError())
it("installs apps") {
expect(
consequencesOf(
try MAS.Install.parse([]).run(appLibrary: MockAppLibrary(), searcher: MockAppStoreSearcher())
)
)
== (nil, "", "")
}
}
}
Expand Down
11 changes: 3 additions & 8 deletions Tests/masTests/Commands/ListSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,20 @@
// Copyright © 2018 mas-cli. All rights reserved.
//

import Foundation
import Nimble
import Quick

@testable import mas

public class ListSpec: QuickSpec {
public final class ListSpec: QuickSpec {
override public func spec() {
beforeSuite {
MAS.initialize()
}
describe("list command") {
it("lists apps") {
expect {
try captureStream(stderr) {
try MAS.List.parse([]).run(appLibrary: MockAppLibrary())
}
}
== "Error: No installed apps found\n"
expect(consequencesOf(try MAS.List.parse([]).run(appLibrary: MockAppLibrary())))
== (nil, "", "Error: No installed apps found\n")
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions Tests/masTests/Commands/LuckySpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Quick

@testable import mas

public class LuckySpec: QuickSpec {
public final class LuckySpec: QuickSpec {
override public func spec() {
let networkSession = MockFromFileNetworkSession(responseFile: "search/slack.json")
let searcher = ITunesSearchAppStoreSearcher(networkManager: NetworkManager(session: networkSession))
Expand All @@ -20,11 +20,11 @@ public class LuckySpec: QuickSpec {
MAS.initialize()
}
xdescribe("lucky command") {
xit("installs the first app matching a search") {
expect {
try MAS.Lucky.parse(["Slack"]).run(appLibrary: MockAppLibrary(), searcher: searcher)
}
.toNot(throwError())
it("installs the first app matching a search") {
expect(
consequencesOf(try MAS.Lucky.parse(["Slack"]).run(appLibrary: MockAppLibrary(), searcher: searcher))
)
== (nil, "", "")
}
}
}
Expand Down
9 changes: 3 additions & 6 deletions Tests/masTests/Commands/OpenSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,20 @@
// Copyright © 2019 mas-cli. All rights reserved.
//

import Foundation
import Nimble
import Quick

@testable import mas

public class OpenSpec: QuickSpec {
public final class OpenSpec: QuickSpec {
override public func spec() {
beforeSuite {
MAS.initialize()
}
describe("open command") {
it("can't find app with unknown ID") {
expect {
try MAS.Open.parse(["999"]).run(searcher: MockAppStoreSearcher())
}
.to(throwError(MASError.unknownAppID(999)))
expect(consequencesOf(try MAS.Open.parse(["999"]).run(searcher: MockAppStoreSearcher())))
== (MASError.unknownAppID(999), "", "")
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions Tests/masTests/Commands/OutdatedSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Quick

@testable import mas

public class OutdatedSpec: QuickSpec {
public final class OutdatedSpec: QuickSpec {
override public func spec() {
beforeSuite {
MAS.initialize()
Expand All @@ -32,8 +32,8 @@ public class OutdatedSpec: QuickSpec {
version: "1.28"
)

expect {
try captureStream(stdout) {
expect(
consequencesOf(
try MAS.Outdated.parse([])
.run(
appLibrary: MockAppLibrary(
Expand All @@ -47,9 +47,9 @@ public class OutdatedSpec: QuickSpec {
),
searcher: MockAppStoreSearcher([mockSearchResult.trackId: mockSearchResult])
)
}
}
== "490461369 Bandwidth+ (1.27 -> 1.28)\n"
)
)
== (nil, "490461369 Bandwidth+ (1.27 -> 1.28)\n", "")
}
}
}
Expand Down
15 changes: 9 additions & 6 deletions Tests/masTests/Commands/PurchaseSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@ import Quick

@testable import mas

public class PurchaseSpec: QuickSpec {
public final class PurchaseSpec: QuickSpec {
override public func spec() {
beforeSuite {
MAS.initialize()
}
xdescribe("purchase command") {
xit("purchases apps") {
expect {
try MAS.Purchase.parse(["999"]).run(appLibrary: MockAppLibrary(), searcher: MockAppStoreSearcher())
}
.toNot(throwError())
it("purchases apps") {
expect(
consequencesOf(
try MAS.Purchase.parse(["999"])
.run(appLibrary: MockAppLibrary(), searcher: MockAppStoreSearcher())
)
)
== (nil, "", "")
}
}
}
Expand Down
28 changes: 0 additions & 28 deletions Tests/masTests/Commands/ResetSpec.swift

This file was deleted.

19 changes: 8 additions & 11 deletions Tests/masTests/Commands/SearchSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
// Copyright © 2018 mas-cli. All rights reserved.
//

import Foundation
import Nimble
import Quick

@testable import mas

public class SearchSpec: QuickSpec {
public final class SearchSpec: QuickSpec {
override public func spec() {
beforeSuite {
MAS.initialize()
Expand All @@ -25,19 +24,17 @@ public class SearchSpec: QuickSpec {
trackViewUrl: "mas preview url",
version: "0.0"
)
expect {
try captureStream(stdout) {
expect(
consequencesOf(
try MAS.Search.parse(["slack"])
.run(searcher: MockAppStoreSearcher([mockResult.trackId: mockResult]))
}
}
== " 1111 slack (0.0)\n"
)
)
== (nil, " 1111 slack (0.0)\n", "")
}
it("fails when searching for nonexistent app") {
expect {
try MAS.Search.parse(["nonexistent"]).run(searcher: MockAppStoreSearcher())
}
.to(throwError(MASError.noSearchResultsFound))
expect(consequencesOf(try MAS.Search.parse(["nonexistent"]).run(searcher: MockAppStoreSearcher())))
== (MASError.noSearchResultsFound, "", "")
}
}
}
Expand Down
Loading
Loading