Comments (4)
Hi,
- Which version of
OHHTTPStubs
? - Using
NSURLConnection
,[NSURLSession sharedSession]
, or[NSURLSession sessionWithConfiguration:]
? - Did you try breakpoints anywhere? Checked that you passed in the method that installs the stubs?
Are you sure you did restore the context at the end of each of your test methods? Especially, maybe in the test that is just before the one you are trying there is a test that disables the stubs, and then you forget to reenable them at the end. Or forget to uninstall some stubs in the previous tests. Thus maybe test A disables the stubs, then test B runs but the stubs are still disabled if you didn't restore the context at the end of test A or in the -tearDown
method. Whereas if you execute test B on its own, the stubs are not previously disabled by test A and they work fine.
Best way to check this is to take advantage of the various debugging methods available:
- Like give a name to your stubs (see
<OHHTTPStubsDescription>
protocol), and then use theallStubs
method in your concerned test to check which stub are installed at the moment this problematic test of yours is run (see README for details which explains this technique). - You should also log in that test of yours at some point a message to tell the value of
[OHHTTPStubs isEnabled]
or force theirsetEnabled:
state
from ohhttpstubs.
I'm using OHHTTPStubs 3.0.2
I'm using AFNetworking2 with an AFHTTPSessionManager created with just a base URL - which use [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]]
I have three test files all using Specta and Expecta (the latest versions compatible with XCTest) Only one of the files uses OHHTTPStubs. In the very first before block I have:
[OHHTTPStubs onStubActivation:^(NSURLRequest *request, id<OHHTTPStubsDescriptor> stub) {
NSLog(@"\n\nStub activation for Request %@\nstub %@\nAll Stubs %@\n\n", request, stub, [OHHTTPStubs allStubs]);
}];
I name all my stubs and when I run the test file as a standalone test (by clicking on the diamond in the gutter) it works properly, and the Logs are shown.
For each test context I have something like this:
_successStub = [OHHTTPStubs stubRequestsPassingTest:^BOOL(NSURLRequest *request) {
return [request.URL.lastPathComponent isEqualToString:@"venues"];
} withStubResponse:^OHHTTPStubsResponse *(NSURLRequest *request) {
return [OHHTTPStubsResponse responseWithFileAtPath:OHPathForFileInBundle(@"VenuesSuccess.json", nil) statusCode:200 headers:httpHeaders];
}];
_successStub.name = @"Success stub";
To create and name the stubs. Again. This works when I run the file in isolation. I can but breakpoints on the two return lines and they are hit while running the tests.
But, if I run all the tests with cmd+u, which runs the two other test files, that do not use OHHTTPStubs, so are not enabling or disabling any stubs; then I am not seeing the logs from the onStubActivation``handler, nor are the breakpoints on the return lines being hit. Adding
[OHHTTPStubs setEnabled:YES];` just above the stub test does not have any affect.
from ohhttpstubs.
Okay - After creating a simple test example to try and reproduce the issue - I found the problem in my singleton initialiser.
Sorry, and thanks for this extremely helpful library.
from ohhttpstubs.
Thanks for the feedback.
Could you give an example / quote a code extract to explain the problem you had with your singleton? This way if others make the same mistake they can easily understand why it was not working and what they did wrong ;)
Thanks
from ohhttpstubs.
Related Issues (20)
- Mocktail support HOT 2
- pod 'AFNetworking', '~> 3.0'
- Incorrect example for onStubActivation on Usage Examples page
- [wiki] OHHTTPStubsResponse to HTTPStubsResponse with Swift HOT 4
- Module 'OHHTTPStubs' has no member named 'removeAllStubs' in 9.0.0 HOT 2
- Xcode Analyze: Logic error
- N HOT 1
- Travis CI has seemed to be moved. HOT 3
- How to use in a UITest HOT 9
- OHHTTPStubs with SPM in Xcode 12.5 HOT 1
- Fluent API for stubbing
- how do i use it HOT 1
- Liscense HOT 1
- 4 da world HOT 1
- - [ ] Submitting a maybeaplle @mtodd []()![image](https://user-images.githubusercontent.com/122186144/230750410-f43c3ffb-f6a7-4bd4-9970-8b065670ea28.jpeg)@craystyle1212
- Won't build with Carthage and Xcode 14.3 HOT 7
- App Crashes on Device When OHHTTPStubsSwift Added to iOS Framework via Swift Package Manager HOT 1
- FEATURE REQUEST: Ability to control response stream
- `canInitWithRequest` not called in Xcode 15 preventing stubbing being setup correctly
- Request to provide Privacy Manifest file for OHHTTPStubs SDK HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ohhttpstubs.