Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mocking an subclass of ManagedObject #8

Open
jyaunches opened this issue Jan 30, 2017 · 5 comments
Open

Mocking an subclass of ManagedObject #8

jyaunches opened this issue Jan 30, 2017 · 5 comments

Comments

@jyaunches
Copy link

jyaunches commented Jan 30, 2017

Is it possible? I'm just starting out and am receiving some build errors that I don't quite understand.

@jyaunches jyaunches changed the title Has anyone used this library with Quick? Mocking an subclass of ManagedObject Jan 30, 2017
@sabirvirtuoso
Copy link
Owner

Hi there. Can you be more specific and come with a use case where you would want to mock a subclass of ManagedObject.

@Nicolas-Trutet
Copy link

Hello there.
Coming from OCMock I am now using Mockit and I'm enjoying it.
However, there is something about stubbing properties that I do not seem to understand.

I've tried to override a property and override the getter and setter as describe in the example below.

class MCKMyCustomView: MyCustomView, Mock {
    
    let callHandler: CallHandler
    
    init(testCase: XCTestCase, frame: CGRect) {
        self.callHandler = CallHandlerImpl(withTestCase: testCase)
        
        super.init(frame: frame)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func instanceType() -> MCKMyCustomView {
        return self
    }
    
    
    override open var infosLabel: UILabel? {
        get {
            return self.callHandler.accept(nil, ofFunction: #function, atFile: #file, inLine: #line, withArgs: nil) as? UILabel

        }
        set {
            self.callHandler.accept(nil, ofFunction: #function, atFile: #file, inLine: #line, withArgs: nil)
        }
    }
}

My attempt was to stub the property in my testing class as follow:

// Mock
let mck_view = MCKMyCustomView(testCase: self, frame: frame)

// Stub
mck_view.when().call(withReturnValue: mck_view.infosLabel).thenReturn(nil)

But stubbing this way was not always successful. I sometimes observed weird behaviours like Xcode telling me that the property has been called or not called once as if I was doing a check like a Once() or Never() on a method. I did observed property behaving as it was not stubbed.

I am wondering if the Mockit framework allows to stub properties or am I doing it the wrong way ?

Thanks for you time.

@sabirvirtuoso
Copy link
Owner

sabirvirtuoso commented Oct 18, 2018 via email

@Nicolas-Trutet
Copy link

Nicolas-Trutet commented Oct 25, 2018

Thanks for contacting mate. I m a bit in a rush. Will get back to you tomorrow. Thanks.
On Thu, Oct 18, 2018 at 10:15 PM JC-Nicolas @.***> wrote: Hello there. Coming from OCMock I am now using Mockit and I'm enjoying it. However, there is something about stubbing properties that I do not seem to understand. I've tried to override a property and override the getter and setter as describe in the example below. class MCKMyCustomView: MyCustomView, Mock { let callHandler: CallHandler init(testCase: XCTestCase, frame: CGRect) { self.callHandler = CallHandlerImpl(withTestCase: testCase) super.init(frame: frame) } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } func instanceType() -> MCKMyCustomView { return self } override open var infosLabel: UILabel? { get { return self.callHandler.accept(nil, ofFunction: #function, atFile: #file, inLine: #line, withArgs: nil) as? UILabel } set { self.callHandler.accept(nil, ofFunction: #function, atFile: #file, inLine: #line, withArgs: nil) } } } My attempt was to stub the property in my testing class as follow: // Mock let mck_view = MCKMyCustomView(testCase: self, frame: frame) // Stub mck_view.when().call(withReturnValue: mck_view.infosLabel).thenReturn(nil) But stubbing this way was not always successful. I sometimes observed weird behaviours like Xcode telling me that the property has been called or not called once as if I was doing a check like a Once() or Never() on a method. I did observed property behaving as it was not stubbed. I am wondering if the Mockit framework allows to stub properties or am I doing it the wrong way ? Thanks for you time. — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#8 (comment)>, or mute the thread https://github.com/notifications/unsubscribe-auth/AKNcGHwujJ8iz2TU6Wj9iPnvH7iC8JUwks5umKkGgaJpZM4Lx51i .
-- Regards, Syed Sabir Salman-Al-Musawi Software Engineer Dynamic Solution Innovators, http://www.dsinnovators.com/ Phone: +8801680464463 Github: https://github.com/sabirvirtuoso https://github.com/sabirvirtuoso

Hello sabirvirtuoso, did you find the time to look at the issue ?
Have a nice day.

@sabirvirtuoso
Copy link
Owner

Hi,

stubbing properties, more specifically getters and setter seems to be out of scope of the current implementation. Please feel free to add this feature and send me a PR.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants