Giter VIP home page Giter VIP logo

Comments (5)

akitchen avatar akitchen commented on August 17, 2024

from cedar.

markcarl avatar markcarl commented on August 17, 2024

Thanks for your message!

I looked further and see that the exception for the test example I referenced is in the beforeEach block for the test. The exception occurs when the bold line below is executed:

    describe(@"#drawRect2:", ^{
        __block UIBezierPath *fakePath;
        __block CGRect passedRect;
        __block Swizzlean *bezierSwizz;
        __block struct CGPath *path;
        
        beforeEach(^{
            fakePath = nice_fake_for([UIBezierPath class]);
            
            bezierSwizz = [[Swizzlean alloc] initWithClassToSwizzle:[UIBezierPath class]];
            [bezierSwizz swizzleClassMethod:@selector(bezierPathWithRect:) withReplacementImplementation:^(id self, CGRect rect) {
                passedRect = rect;
                return [fakePath retain];
            }];
            
            path = CGPathCreateMutable();
            fakePath stub_method(@selector(CGPath)).and_return(path);
            
            view.bounds = CGRectMake(0,0,200,200);
            [view drawRect:CGRectZero];
        });
        
        afterEach(^{
            [bezierSwizz resetSwizzledClassMethod];
        });
        
        fit(@"sets the shadow color", ^{
            view.layer.shadowColor should equal([UIColor blackColor].CGColor);
        });
        
    });

If I add a const specifier to the declaration for path, the exception goes away.

__block const struct CGPath *path;

Thanks again for your help!

from cedar.

tjarratt avatar tjarratt commented on August 17, 2024

The invalid return type message sounds really similar to the error messages for Cedar's fakes.

My guess is that you have a fake that returns a CGPath * but the UIKit api now returns a const CGPath *.

What's happening under the hood is that Cedar's fakes try to verify that your stubbed values are correct - it wants to catch errors about mismatched return types early, so that you aren't surprised when your tests are wrong. Perhaps as part of building up your subview, or the label, there's a fake somewhere that's providing a CGPath?

That's all just my intuition, but if I'm wrong, I'd try tracking down the "invalid return value type" message, set the appropriate breakpoint in Cedar and try to walk back up the call stack and understand how that happened.

from cedar.

tjarratt avatar tjarratt commented on August 17, 2024

Oh sorry @markcarl I didn't see your response, I'm glad you got it to work again. Just a few thoughts and kind words of advice:

  • Don't make fakes for UIBezierPath -- you don't own that API and apple can change it. Those tests will be brittle and break again in the future.
  • In general, try not to make fakes for value types like bezier paths, arrays or dictionaries

Only mentioning that because I've been bit by that a dozen times before personally, and it's always a tough issue to troubleshoot.

from cedar.

tjarratt avatar tjarratt commented on August 17, 2024

Closing now as resolved, but feel free to re-open if you'd like to discuss it more. Always happy to talk to Cedar users :)

from cedar.

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.