Skip to content

Commit

Permalink
Merge pull request #9 from SwiftRex/MiddlewareIO
Browse files Browse the repository at this point in the history
Update SwiftRex to use Middleware IO
  • Loading branch information
luizmb authored Nov 30, 2021
2 parents 0868734 + 616997a commit 1fd043f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let package = Package(
],
dependencies: [
.package(name: "SnapshotTesting", url: "https://github.com/pointfreeco/swift-snapshot-testing.git", .upToNextMajor(from: "1.8.2")),
.package(name: "SwiftRex", url: "https://github.com/SwiftRex/SwiftRex.git", .upToNextMajor(from: "0.8.6"))
.package(name: "SwiftRex", url: "https://github.com/SwiftRex/SwiftRex.git", .upToNextMajor(from: "0.8.8"))
],
targets: [
.target(
Expand Down
26 changes: 12 additions & 14 deletions Sources/TestingExtensions/UseCaseTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import Combine
import CombineRex
import Foundation
import SwiftRex
@testable import SwiftRex
import XCTest

#if swift(>=5.4)
Expand Down Expand Up @@ -219,7 +219,7 @@ public enum Step<ActionType, StateType>: StepProtocol {

extension XCTestCase {
#if swift(>=5.4)
public func assert<M: Middleware>(
public func assert<M: MiddlewareProtocol>(
initialValue: M.StateType,
reducer: Reducer<M.InputActionType, M.StateType>,
middleware: M,
Expand All @@ -238,7 +238,7 @@ extension XCTestCase {
)
}

public func assert<M: Middleware>(
public func assert<M: MiddlewareProtocol>(
initialValue: M.StateType,
reducer: Reducer<M.InputActionType, M.StateType>,
middleware: M,
Expand All @@ -259,7 +259,7 @@ extension XCTestCase {
}
#endif

public func assert<M: Middleware>(
public func assert<M: MiddlewareProtocol>(
initialValue: M.StateType,
reducer: Reducer<M.InputActionType, M.StateType>,
middleware: M,
Expand All @@ -278,7 +278,7 @@ extension XCTestCase {
)
}

public func assert<M: Middleware>(
public func assert<M: MiddlewareProtocol>(
initialValue: M.StateType,
reducer: Reducer<M.InputActionType, M.StateType>,
middleware: M,
Expand All @@ -298,7 +298,7 @@ extension XCTestCase {
)
}

private func assert<M: Middleware>(
private func assert<M: MiddlewareProtocol>(
initialValue: M.StateType,
reducer: Reducer<M.InputActionType, M.StateType>,
middleware: M,
Expand Down Expand Up @@ -329,16 +329,15 @@ extension XCTestCase {
""", file: file, line: line)
}

var afterReducer: AfterReducer = .doNothing()
let action = action()
middleware.handle(
let io = middleware.handle(
action: action,
from: .init(file: "\(file)", function: "", line: line, info: nil),
afterReducer: &afterReducer
state: { state }
)
reducer.reduce(action, &state)
#if DEBUG
afterReducer.performBlock()
io.runIO(anyActionHandler)
#else
XCTFail("Please run the tests in DEBUG otherwise after reducer won't be called")
#endif
Expand All @@ -363,15 +362,14 @@ extension XCTestCase {
let first = middlewareResponses.removeFirst()
XCTAssertTrue(action(first), file: file, line: line)

var afterReducer: AfterReducer = .doNothing()
middleware.handle(
let io = middleware.handle(
action: first,
from: .init(file: "\(file)", function: "", line: line, info: nil),
afterReducer: &afterReducer
state: { state }
)
reducer.reduce(first, &state)
#if DEBUG
afterReducer.performBlock()
io.runIO(anyActionHandler)
#else
XCTFail("Please run the tests in DEBUG otherwise after reducer won't be called")
#endif
Expand Down

0 comments on commit 1fd043f

Please sign in to comment.