Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1cb19f8

Browse files
committed
no message
1 parent c8a613c commit 1cb19f8

File tree

7 files changed

+42
-8
lines changed

7 files changed

+42
-8
lines changed

.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LocalServer.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "LocalServer"
3-
s.version = "1.5.0"
3+
s.version = "2.0.0"
44
s.summary = "Micro Feature"
55
s.description = <<-DESC
66
LocalServer is resposible for ...

LocalServer/Source/StubResponse.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,27 @@ open class StubResponse {
6161
}
6262
}
6363

64+
/// Initializes the response with a real request being performed.
65+
///
66+
/// - Parameter request: URLRequest
67+
init(withReal request: URLRequest) {
68+
let semaphore = DispatchSemaphore(value: 0)
69+
70+
URLSession.realShared.dataTask(with: request) {(data, response, error) in
71+
72+
if let httpResponse = response as? HTTPURLResponse {
73+
self.statusCode = httpResponse.statusCode
74+
self.headers = (httpResponse.allHeaderFields as? [String : String]) ?? self.headers
75+
}
76+
77+
self.body = data
78+
self.error = error
79+
80+
semaphore.signal()
81+
}.resume()
82+
semaphore.wait()
83+
}
84+
6485
// MARK: - Exposed Methods
6586

6687
/// Returns the same response object with a new delay. The delay can be used to simulate

LocalServer/Source/StubServer.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public class StubServer {
6565
// MARK: - Properties
6666

6767
fileprivate var routes = [HTTPMethod : Router]()
68-
static var shared: StubServer = { StubServer() }()
68+
static var shared: StubServer = { StubServer(allowRealRequests: true) }()
6969

7070
/// Current instance of any Local Server.
7171
public static var instance: LocalServerDelegate? {
@@ -78,12 +78,17 @@ public class StubServer {
7878
}
7979

8080
/// The default response for this server in case there is no given match for the response.
81-
public var defaultResponse = StubResponse().withStatusCode(404)
81+
public var defaultResponse: StubResponse = StubResponse().withStatusCode(404)
82+
83+
/// When `true` this server will allow non-set routes to go through real requests. By default it's `false`.
84+
public var allowRealRequests: Bool
8285

8386
// MARK: - Constructors
8487

85-
/// The default initializer for an empty StubServer
86-
public init() { }
88+
/// The default initializer for an empty StubServer.
89+
public init(allowRealRequests: Bool = false) {
90+
self.allowRealRequests = allowRealRequests
91+
}
8792

8893
// MARK: - Protected Methods
8994

@@ -126,6 +131,6 @@ extension StubServer : LocalServerDelegate {
126131
return response
127132
}
128133

129-
return defaultResponse
134+
return allowRealRequests ? StubResponse(withReal: urlRequest) : defaultResponse
130135
}
131136
}

LocalServer/Source/StubURLSession.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ extension URLSession : Exchangeable {
3838
return URLSession.stubShared
3939
}
4040

41+
class var realShared: URLSession { .stubShared }
42+
4143
static func exchange() {
4244
exchangeClass(#selector(getter: shared), #selector(getter: stubShared))
4345
}

SampleAppUITests/Features/WebPageSpec.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ final class WebPageSpec : XCTestCase {
3131

3232
then("I should see the user detail") {
3333
XCTAssert(main.on(screen: WebPageScreen.self).isGreetingsShown())
34-
XCTAssert(main.on(screen: WebPageScreen.self).isTextShown(UserType.female.shortName))
3534
}
3635
}
3736
}

SampleAppUITests/Screens/WebPageScreen.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class WebPageScreen : Screen {
2929

3030
@discardableResult
3131
func waitForWebView() -> Bool {
32-
return exists(webView)
32+
return webView.waitForExistence(timeout: 10)
3333
}
3434

3535
func isGreetingsShown() -> Bool {

0 commit comments

Comments
 (0)