From 5f6c7f204112995acfb7347ef14e010712f3fd45 Mon Sep 17 00:00:00 2001 From: sergdort Date: Thu, 19 Oct 2017 14:28:01 +0100 Subject: [PATCH] Add `System` operator tests (#3) * Make ReactiveFeedback framework inside of workspace * Add `system` tests * Fix merge conflicts * refactor tests using `Nimble` * Fix podspec * Extract into expected variable * Configure ReactiveFeedback schema for testing * Stop tracking my user data * Remove Sources folder * Revert to previous changes * Remove extra file --- ReactiveFeedback.xcodeproj/project.pbxproj | 24 ++-- .../xcschemes/Example.xcscheme | 93 -------------- .../xcschemes/ReactiveFeedback.xcscheme | 82 ------------ .../xcschemes/xcschememanagement.plist | 22 ---- .../xcschemes/ReactiveFeedback.xcscheme | 31 ----- .../xcschemes/xcschememanagement.plist | 14 --- .../ReactiveFeedbackTests.swift | 8 -- ReactiveFeedbackTests/SystemTests.swift | 118 ++++++++++++++++++ 8 files changed, 130 insertions(+), 262 deletions(-) delete mode 100644 ReactiveFeedback.xcodeproj/xcuserdata/sergdort.xcuserdatad/xcschemes/Example.xcscheme delete mode 100644 ReactiveFeedback.xcodeproj/xcuserdata/sergdort.xcuserdatad/xcschemes/ReactiveFeedback.xcscheme delete mode 100644 ReactiveFeedback.xcodeproj/xcuserdata/sergdort.xcuserdatad/xcschemes/xcschememanagement.plist delete mode 100644 ReactiveFeedback.xcodeproj/xcuserdata/sergey.shulga.xcuserdatad/xcschemes/ReactiveFeedback.xcscheme delete mode 100644 ReactiveFeedback.xcodeproj/xcuserdata/sergey.shulga.xcuserdatad/xcschemes/xcschememanagement.plist delete mode 100644 ReactiveFeedbackTests/ReactiveFeedbackTests.swift create mode 100644 ReactiveFeedbackTests/SystemTests.swift diff --git a/ReactiveFeedback.xcodeproj/project.pbxproj b/ReactiveFeedback.xcodeproj/project.pbxproj index 13cbe48..78c2a33 100644 --- a/ReactiveFeedback.xcodeproj/project.pbxproj +++ b/ReactiveFeedback.xcodeproj/project.pbxproj @@ -7,17 +7,15 @@ objects = { /* Begin PBXBuildFile section */ - 25CC87BB1F92859800A6EBFC /* SignalProducer+System.swift in Sources */ = {isa = PBXBuildFile; fileRef = 25E1D2331F54951100D90192 /* SignalProducer+System.swift */; }; - 25CC87BC1F92859800A6EBFC /* Feedback.swift in Sources */ = {isa = PBXBuildFile; fileRef = 25E1D2351F54A20F00D90192 /* Feedback.swift */; }; 25E1D2211F5493D000D90192 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 25E1D2201F5493D000D90192 /* AppDelegate.swift */; }; 25E1D2231F5493D000D90192 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 25E1D2221F5493D000D90192 /* ViewController.swift */; }; 25E1D2261F5493D000D90192 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 25E1D2241F5493D000D90192 /* Main.storyboard */; }; 25E1D2281F5493D000D90192 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 25E1D2271F5493D000D90192 /* Assets.xcassets */; }; 25E1D22B1F5493D000D90192 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 25E1D2291F5493D000D90192 /* LaunchScreen.storyboard */; }; 25E1D2381F56091A00D90192 /* PaginationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 25E1D2371F56091A00D90192 /* PaginationViewController.swift */; }; + 5898B6D11F97ADDD005EEAEC /* SystemTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5898B6D01F97ADDD005EEAEC /* SystemTests.swift */; }; 9A4CCB0B1F95D5CA00ACF758 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9A4CCB0C1F95D5CA00ACF758 /* Nimble.framework */; }; 9A4CCB0D1F95D5D500ACF758 /* Nimble.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 9A4CCB0C1F95D5CA00ACF758 /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - 9AE181B91F95A71B00A07551 /* ReactiveFeedbackTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9AE181B81F95A71B00A07551 /* ReactiveFeedbackTests.swift */; }; 9AE181BB1F95A71B00A07551 /* ReactiveFeedback.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 25CC87AE1F92855300A6EBFC /* ReactiveFeedback.framework */; }; 9AE181C21F95A77500A07551 /* ReactiveSwift.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 9AFA212A1F95135B001DBF7C /* ReactiveSwift.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 9AE181C31F95A77500A07551 /* Result.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 9AFA212B1F95135B001DBF7C /* Result.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; @@ -36,6 +34,8 @@ 9AFA213D1F9514E4001DBF7C /* ReactiveFeedback.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 25CC87AE1F92855300A6EBFC /* ReactiveFeedback.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 9AFA21441F951828001DBF7C /* Kingfisher.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9AFA21431F95181E001DBF7C /* Kingfisher.framework */; }; 9AFA21451F951828001DBF7C /* Kingfisher.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9AFA21431F95181E001DBF7C /* Kingfisher.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + A950943401765BB90FA846B2 /* SignalProducer+System.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9509880213192F0D80EC2B3 /* SignalProducer+System.swift */; }; + A9509BE4551098F4A5503820 /* Feedback.swift in Sources */ = {isa = PBXBuildFile; fileRef = A95097E70D3CBFF05FA7B8CC /* Feedback.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -95,18 +95,18 @@ 25E1D2271F5493D000D90192 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 25E1D22A1F5493D000D90192 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 25E1D22C1F5493D000D90192 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 25E1D2331F54951100D90192 /* SignalProducer+System.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "SignalProducer+System.swift"; sourceTree = ""; }; - 25E1D2351F54A20F00D90192 /* Feedback.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Feedback.swift; sourceTree = ""; }; 25E1D2371F56091A00D90192 /* PaginationViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PaginationViewController.swift; sourceTree = ""; }; + 5898B6D01F97ADDD005EEAEC /* SystemTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SystemTests.swift; sourceTree = ""; }; 9A4CCB0C1F95D5CA00ACF758 /* Nimble.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Nimble.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 9AE181B61F95A71B00A07551 /* ReactiveFeedbackTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ReactiveFeedbackTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; - 9AE181B81F95A71B00A07551 /* ReactiveFeedbackTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReactiveFeedbackTests.swift; sourceTree = ""; }; 9AE181BA1F95A71B00A07551 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 9AFA21251F9511A5001DBF7C /* ReactiveFeedback.podspec */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ReactiveFeedback.podspec; sourceTree = ""; }; 9AFA212A1F95135B001DBF7C /* ReactiveSwift.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = ReactiveSwift.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 9AFA212B1F95135B001DBF7C /* Result.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Result.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 9AFA21391F951435001DBF7C /* ReactiveCocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = ReactiveCocoa.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 9AFA21431F95181E001DBF7C /* Kingfisher.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Kingfisher.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + A95097E70D3CBFF05FA7B8CC /* Feedback.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Feedback.swift; sourceTree = ""; }; + A9509880213192F0D80EC2B3 /* SignalProducer+System.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "SignalProducer+System.swift"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -148,9 +148,9 @@ 25CC87AF1F92855300A6EBFC /* ReactiveFeedback */ = { isa = PBXGroup; children = ( - 25E1D2331F54951100D90192 /* SignalProducer+System.swift */, + A95097E70D3CBFF05FA7B8CC /* Feedback.swift */, + A9509880213192F0D80EC2B3 /* SignalProducer+System.swift */, 25CC87B11F92855300A6EBFC /* Info.plist */, - 25E1D2351F54A20F00D90192 /* Feedback.swift */, ); path = ReactiveFeedback; sourceTree = ""; @@ -194,7 +194,7 @@ 9AE181B71F95A71B00A07551 /* ReactiveFeedbackTests */ = { isa = PBXGroup; children = ( - 9AE181B81F95A71B00A07551 /* ReactiveFeedbackTests.swift */, + 5898B6D01F97ADDD005EEAEC /* SystemTests.swift */, 9AE181BA1F95A71B00A07551 /* Info.plist */, ); path = ReactiveFeedbackTests; @@ -357,8 +357,8 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 25CC87BC1F92859800A6EBFC /* Feedback.swift in Sources */, - 25CC87BB1F92859800A6EBFC /* SignalProducer+System.swift in Sources */, + A9509BE4551098F4A5503820 /* Feedback.swift in Sources */, + A950943401765BB90FA846B2 /* SignalProducer+System.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -376,7 +376,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 9AE181B91F95A71B00A07551 /* ReactiveFeedbackTests.swift in Sources */, + 5898B6D11F97ADDD005EEAEC /* SystemTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/ReactiveFeedback.xcodeproj/xcuserdata/sergdort.xcuserdatad/xcschemes/Example.xcscheme b/ReactiveFeedback.xcodeproj/xcuserdata/sergdort.xcuserdatad/xcschemes/Example.xcscheme deleted file mode 100644 index 4fd6b25..0000000 --- a/ReactiveFeedback.xcodeproj/xcuserdata/sergdort.xcuserdatad/xcschemes/Example.xcscheme +++ /dev/null @@ -1,93 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/ReactiveFeedback.xcodeproj/xcuserdata/sergdort.xcuserdatad/xcschemes/ReactiveFeedback.xcscheme b/ReactiveFeedback.xcodeproj/xcuserdata/sergdort.xcuserdatad/xcschemes/ReactiveFeedback.xcscheme deleted file mode 100644 index f9d41fa..0000000 --- a/ReactiveFeedback.xcodeproj/xcuserdata/sergdort.xcuserdatad/xcschemes/ReactiveFeedback.xcscheme +++ /dev/null @@ -1,82 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/ReactiveFeedback.xcodeproj/xcuserdata/sergdort.xcuserdatad/xcschemes/xcschememanagement.plist b/ReactiveFeedback.xcodeproj/xcuserdata/sergdort.xcuserdatad/xcschemes/xcschememanagement.plist deleted file mode 100644 index bd300ac..0000000 --- a/ReactiveFeedback.xcodeproj/xcuserdata/sergdort.xcuserdatad/xcschemes/xcschememanagement.plist +++ /dev/null @@ -1,22 +0,0 @@ - - - - - SchemeUserState - - ReactiveFeedback.xcscheme - - orderHint - 0 - - - SuppressBuildableAutocreation - - 25E1D21C1F5493D000D90192 - - primary - - - - - diff --git a/ReactiveFeedback.xcodeproj/xcuserdata/sergey.shulga.xcuserdatad/xcschemes/ReactiveFeedback.xcscheme b/ReactiveFeedback.xcodeproj/xcuserdata/sergey.shulga.xcuserdatad/xcschemes/ReactiveFeedback.xcscheme deleted file mode 100644 index 1624617..0000000 --- a/ReactiveFeedback.xcodeproj/xcuserdata/sergey.shulga.xcuserdatad/xcschemes/ReactiveFeedback.xcscheme +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - - - - - - - - - - diff --git a/ReactiveFeedback.xcodeproj/xcuserdata/sergey.shulga.xcuserdatad/xcschemes/xcschememanagement.plist b/ReactiveFeedback.xcodeproj/xcuserdata/sergey.shulga.xcuserdatad/xcschemes/xcschememanagement.plist deleted file mode 100644 index 80ae823..0000000 --- a/ReactiveFeedback.xcodeproj/xcuserdata/sergey.shulga.xcuserdatad/xcschemes/xcschememanagement.plist +++ /dev/null @@ -1,14 +0,0 @@ - - - - - SchemeUserState - - ReactiveFeedback.xcscheme - - orderHint - 5 - - - - diff --git a/ReactiveFeedbackTests/ReactiveFeedbackTests.swift b/ReactiveFeedbackTests/ReactiveFeedbackTests.swift deleted file mode 100644 index 666d605..0000000 --- a/ReactiveFeedbackTests/ReactiveFeedbackTests.swift +++ /dev/null @@ -1,8 +0,0 @@ -import XCTest -import ReactiveSwift -import Result -import Nimble - -class ReactiveFeedbackTests: XCTestCase { - func testPlaceholder() {} -} diff --git a/ReactiveFeedbackTests/SystemTests.swift b/ReactiveFeedbackTests/SystemTests.swift new file mode 100644 index 0000000..962a30d --- /dev/null +++ b/ReactiveFeedbackTests/SystemTests.swift @@ -0,0 +1,118 @@ +import XCTest +import Nimble +import ReactiveSwift +import enum Result.NoError +@testable import ReactiveFeedback + +class SystemTests: XCTestCase { + + func test_emits_initial() { + let initial = "initial" + let feedback = Feedback { state in + return SignalProducer(value: "_a") + } + let system = SignalProducer.system( + initial: initial, + reduce: { (state: String, event: String) in + return state + event + }, + feedbacks: feedback) + let result = system.first()?.value + + expect(result) == initial + } + + func test_reducer_with_one_feedback_loop() { + let feedback = Feedback { state in + return SignalProducer(value: "_a") + } + let system = SignalProducer.system( + initial: "initial", + reduce: { (state: String, event: String) in + return state + event + }, + feedbacks: feedback) + + var result: [String]! + system.take(first: 3) + .collect() + .startWithValues { + result = $0 + } + + let expected = [ + "initial", + "initial_a", + "initial_a_a" + ] + expect(result).toEventually(equal(expected)) + } + + func test_reduce_with_two_immediate_feedback_loops() { + let feedback1 = Feedback { state in + return SignalProducer(value: "_a") + } + let feedback2 = Feedback { state in + return SignalProducer(value: "_b") + } + let system = SignalProducer.system( + initial: "initial", + reduce: { (state: String, event: String) in + return state + event + }, + feedbacks: feedback1, feedback2) + + var result: [String]! + system.take(first: 5) + .collect() + .startWithValues { + result = $0 + } + + let expected = [ + "initial", + "initial_a", + "initial_a_b", + "initial_a_b_a", + "initial_a_b_a_b", + ] + expect(result).toEventually(equal(expected)) + } + + func test_reduce_with_async_feedback_loop() { + let feedback = Feedback { state -> SignalProducer in + if state == "initial" { + return SignalProducer(value: "_a") + .delay(0.1, on: QueueScheduler.main) + } + if state == "initial_a" { + return SignalProducer(value: "_b") + } + if state == "initial_a_b" { + return SignalProducer(value: "_c") + } + return SignalProducer.empty + } + let system = SignalProducer.system( + initial: "initial", + reduce: { (state: String, event: String) in + return state + event + }, + feedbacks: feedback) + + var result: [String]! + system.take(first: 4) + .collect() + .startWithValues { + result = $0 + } + + let expected = [ + "initial", + "initial_a", + "initial_a_b", + "initial_a_b_c" + ] + expect(result).toEventually(equal(expected)) + } +}