Coder Social home page Coder Social logo

Comments (4)

AliSoftware avatar AliSoftware commented on May 18, 2024

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 the allStubs 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 their setEnabled: state

from ohhttpstubs.

Abizern avatar Abizern commented on May 18, 2024

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.

Abizern avatar Abizern commented on May 18, 2024

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.

AliSoftware avatar AliSoftware commented on May 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.