AliSoftware / AliSoftware/OHHTTPStubs

Stub not working for shared configuration

オープン
#273 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Objective-C
スター
5.1k
フォーク
597
PR マージ指標
30日以内にマージされた PR はありません

説明

### New Issue Checklist

- [x] I have tried with the latest version of OHHTTPStubs
- [x] I have read the [README](https://github.com/AliSoftware/OHHTTPStubs/blob/master/README.md)
- [x] I have read the [Using the right Swift Version of `OHHTTPStubs` for your project](https://github.com/AliSoftware/OHHTTPStubs#using-the-right-swift-version-of-ohhttpstubs-for-your-project) section
- [x] I have searched in the [existing issues](https://github.com/AliSoftware/OHHTTPStubs/issues?utf8=✓&q=is%3Aissue)
- [x] I have read [the OHHTTPStubs wiki](https://github.com/AliSoftware/OHHTTPStubs/wiki) to see if there wasn't a detailed page talking about my issue

### Environment

- version of OHHTTPStubs: [LIB VERSION HERE]
- integration method you are using:
* [x] Cocoapods
* [ ] Carthage
* [ ] submodule
* [ ] other
- version of the tool you use: 6.1.0

### Issue Description

OHHTTPStubs does not intercept custom URLSessions. When using `URLSession.shared.dataTask` everything is working as expected. However when creating an own instance or URLSession the stub does not work anymore.

```
func testExample() {
let expectation = self.expectation(description: "")

stub(condition: isMethodGET()) { _ in
return OHHTTPStubsResponse(
jsonObject: [],
statusCode: 333,
headers: [ "Content-Type": "application/json" ]
)
}

// intercepted by OHHTTPStubs
URLSession.shared.dataTask(with: URL(string: "https://www.google.com/")!) { (data, response, error) in
print((response as! HTTPURLResponse).statusCode) // returns 333 as expected
}.resume()

// not intercepted by OHHTTPStubs
let session = URLSession(configuration: URLSession.shared.configuration)
session.dataTask(with: URL(string: "https://www.google.com/")!) { (data, response, error) in
print((response as! HTTPURLResponse).statusCode) // returns 200
}.resume()

waitForExpectations(timeout: 3)
}
```

**Update**

It is working with
```
let session = URLSession(configuration: URLSessionConfiguration.default)
session.dataTask(with: URL(string: "https://www.google.com/")!) { (data, response, error) in
print((response as! HTTPURLResponse).statusCode) // returns 333
}.resume()
```

Shouldn't `let session = URLSession(configuration: URLSessionConfiguration.default)` and `let session = URLSession(configuration: URLSession.shared.configuration)` behave the same way?

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。