Giter Site home page Giter Site logo

Ignore extension methods about mockingbird HOT 5 CLOSED

paiv avatar paiv commented on August 15, 2024
Ignore extension methods

from mockingbird.

Comments (5)

andrewchang-bird avatar andrewchang-bird commented on August 15, 2024

What’s the primary concern against generating mocks for extended methods / variables?

from mockingbird.

paiv avatar paiv commented on August 15, 2024

I have no followup

from mockingbird.

paiv avatar paiv commented on August 15, 2024

I wanted to test implementation of extension method:

Protocol:

protocol First {
    func greet(_ name: String)
}

extension First {
    func greetGuests() {
        greet("guests")
    }
}

Test:

import Mockingbird
import XCTest
@testable import Sample


class FirstTests: XCTestCase {
    
    func testGreet() {
        let first = mock(First.self)
        
        first.greetGuests() as Void
        
        verify(first.greet("guests")).wasCalled()
// failed - Incorrect total invocations of ``greet`(_ name: String) -> Void` matching (guests)
    }
}

from mockingbird.

paiv avatar paiv commented on August 15, 2024

Second, this generated code doesn't look right to me:

  public func `greetGuests`() -> Void {
    let invocation: Mockingbird.Invocation = Mockingbird.Invocation(selectorName: "`greetGuests`() -> Void", arguments: [])
    mockingContext.didInvoke(invocation)
    let implementation = stubbingContext.implementation(for: invocation, optional: true)
    if let concreteImplementation = implementation as? () -> Void {
      concreteImplementation()
    } else {
      (implementation as? () -> Void)?()
// if the cast failed on the `if let` line, casting it again to the same type surely will fail again, resulting in a nil call
    }
  }

from mockingbird.

paiv avatar paiv commented on August 15, 2024

I can get the test passing with this change:

    func testGreet() {
        let first = mock(First.self)
        
        (first as First).greetGuests()
        
        verify(first.greet("guests")).wasCalled()
    }

So I guess this works as intended.

from mockingbird.

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.