Commit eb5895f
committed
Trying to solve issue #47 in a tricky case when OHHTTPStubs is used both in the App target and the UnitTest targets, in the case UnitTests use the App as their host app (which is the default for new Xcode5 projects)
In such case, two OHHTTPStubs classes where loaded (one in the App Bundle, one in the Test bundle), leading to double swizzling, but only the first OHHTTPStubsProtocol (generally the one loaded by the app bundle) were used, leading to stubs from UnitTest bundle not being called.
To fix this, I now:
* The swizzling of `NSURLSessionConfiguration` is done using an `NSURLSessionConfiguration` category and its `+load` method to be done only once (much more logical by the way) to avoid double-swizzling (and a callstack overflow)
* The insertion of the `OHHTTPStubsProtocol` class in the `protocolClasses` property is done via `[OHHTTPStubs setEnabled:forSessionConfiguration:]` (instead of relying to `objc_getClass()`), to be sure that it uses the `OHHTTPStubsProtocol` class loaded by the current `NSBundle` (and not the one returned by objc_getClass() which is generally the one from the `mainBundle` / App bundle)1 parent 7aefa6c commit eb5895f
File tree
3 files changed
+10
-23
lines changed- OHHTTPStubs/Sources
3 files changed
+10
-23
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
Lines changed: 8 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | 43 | | |
54 | 44 | | |
55 | 45 | | |
56 | | - | |
| 46 | + | |
57 | 47 | | |
58 | 48 | | |
59 | 49 | | |
60 | 50 | | |
61 | 51 | | |
62 | 52 | | |
63 | | - | |
| 53 | + | |
64 | 54 | | |
65 | 55 | | |
66 | 56 | | |
67 | | - | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
68 | 60 | | |
69 | 61 | | |
70 | 62 | | |
71 | 63 | | |
72 | 64 | | |
73 | 65 | | |
| 66 | + | |
74 | 67 | | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | 68 | | |
| 69 | + | |
| 70 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
104 | | - | |
105 | | - | |
106 | 104 | | |
107 | 105 | | |
108 | 106 | | |
109 | 107 | | |
110 | 108 | | |
111 | | - | |
112 | 109 | | |
113 | 110 | | |
114 | 111 | | |
| |||
182 | 179 | | |
183 | 180 | | |
184 | 181 | | |
185 | | - | |
| 182 | + | |
186 | 183 | | |
187 | 184 | | |
188 | 185 | | |
| |||
0 commit comments