Git Product home page Git Product logo

instantmock's People

Contributors

abarisain avatar alkenso avatar gillfrost avatar pirishd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

instantmock's Issues

Verify if a closure was called

Hi,

Is there a way to know when some closure was called? Follow the example below:

func someFunction(success: @escaping SuccessClosure, failure: @escaping ErrorClosure) {
    let apiUrl = ""
    networkingProvider.get(apiUrl, success: success, failure: failure)
}

I made a mock of networkingProvider and I'd like knowing when the success closure was called. Follow the test example below:

func test_Example() {
     repository.someFunction(success: Arg.closure(), failure: Arg.closure())
}

Is there a way to verify when success/failure closure is called?

Arg.eq with dictionary throws `Ambiguous use of eq`

@pirishd When trying to use Arg.eq with a dictionary, i.e.

Arg<[String: Any]>.eq(someDictionary)

the compiler throws this error: Ambiguous use of 'eq'
Is there anything I need to do in order for this to work ?

Thanks and great work on the library :)

Using InstantMock in a Swift 4.2 project using the package-manager

Hello,

I'm excited to try InstantMock, but unfortunately I'm running into issues installing it in my project. I've created a new project using the swift package manager (4.2) and the issue I'm getting is this:

'foobar' /path/to/the/project: error: product dependency 'InstantMock' not found
warning: dependency 'InstantMock' is not used by any target

My Package.swift looks similar to this (I've removed my project's actual names, etc):

let package = Package(
	name: "foobar",
	dependencies: [
		.package(url: "https://github.com/apple/swift-package-manager.git", from: "0.3.0"),
		.package(url: "https://github.com/pirishd/InstantMock", from: "2.2.1")
	],
	targets: [
		.target(name: "foobar", dependencies: [
			"Utility"
		]),
		.testTarget(name: "foobarTests", dependencies: [
			"foobar",
            		"InstantMock"
		])
    	]
)

It's strange because it knows that "InstantMock" is a dependency, but when I have a target depend on it, swift seems to forget what it is.

Thoughts?

Can't build InstantMock because of bitcode?

Error when running tests:
ld: '/Applications/Xcode 10.3.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Frameworks/XCTest.framework/XCTest' does not contain bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target. file '/Applications/Xcode 10.3.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Frameworks/XCTest.framework/XCTest' for architecture arm64

Xcode 10.3.
Deployment Target 12.3
Swift 5

Podfile:
`target 'RecipePuppy' do
use_frameworks!
pod 'RxSwift'
pod 'RxCocoa'
pod 'SDWebImage'

target 'RecipePuppyUnitTests' do
use_frameworks!
inherit! :search_paths
pod 'InstantMock'
end
end`

Idea: clear determined expectation/stub

I'd like to have a block of setUp with some pre determined default expectations.
And I'd like to have an option to clear some pre determined one(s) at some test cases.

Is this a good idea? Is this worth it?

Thanks.

Problem implementing MockUsable when there are inheritances

Do you have any solution for the case below?
AuthenticationSession extends Model. However, I need to make both of then implement MockUsable. Since you are using static var, its impossible to override..

extension AuthenticationSession_: MockUsable {
    public static var any: AuthenticationSession_ {
        let ret = AuthenticationSession_()
        ret.id = "anyId"
        return ret
    }
    
    public static var anyValue: MockUsable {
        return self.any
    }
    
    public func equal(to value: MockUsable?) -> Bool {
        guard let mock = value as? AuthenticationSession_ else { return false }
        return self.id == mock.id
    }
}

extension Model: MockUsable {
    public static var any: Model {
        let ret = Model()
        return ret
    }
    
    public static var anyValue: MockUsable {
        return self.any
    }
    
    public func equal(to value: MockUsable?) -> Bool {
        guard let mock = value as? Model else { return false }
        return false
    }
}

Problem adding MockUsable extension

XCode 10.2.1 (10E1001)
InstantMock (2.5.0)

I created a new XCode project and installed InstantMock via Cocoapods. My Podfile is

platform :ios, '10.0'
use_frameworks!

target 'MyApp' do

    target 'MyAppTests' do
        pod 'InstantMock'
    end
end

I created protocol with function that contains UInt parameter

protocol DatabaseService {    
    func fetchMessages(count: UInt, completion: @escaping ([String]) -> ())
}

Because InstantMock does not support UInt type by default, I added extension UInt+MockUsable with target membership assigned to MyAppTests target

extension UInt: MockUsable {
    
    public static let any = 49
    
    public static var anyValue: MockUsable {
        return UInt.any
    }
    
    public func equal(to value: MockUsable?) -> Bool {
        guard let uintValue = value as? UInt else { return false }
        return self == uintValue
    }
}

Then I created a simple test

func testThatControllerWillFetchMessagesOnAppearEvent() {
    
    let controller = MessagesViewController()
    let databaseServiceMock = DatabaseServiceMock()
    controller.databaseService = self.databaseServiceMock

    // when
    controller.viewWillAppear(false)
    
    // then
    databaseServiceMock.expect().call(databaseServiceMock.fetchMessages(count: Arg.any(), completion: Arg.closure()))
}

class DatabaseServiceMock: Mock, DatabaseService {
    
    func fetchMessages(count: UInt, completion: @escaping ([String]) -> ()) {
        return super.call(count, completion)
    }
}

But it falls with error
Fatal error: Unexpected type, only MockUsable types can be used with any: file Arg.swift, line 126

That I missed?
Thank you

Key order dependent dictionary comparison

Hi.

After swift 5 migration we faced a problem: expectations with dictionary arguments are not always working. According to the investigation the reason of that behaviour is a dictionary comparison algorithm. As keys array order is generally unpredictable the next test is failing floatly:

    func testEqual_toWrongOrder() {
        let dict1: [String: Any] = [
            "foo": 1,
            "bar": 2
        ]
        let dict2: [String: Any] = [
            "bar": 2,
            "foo": 1
        ]

        XCTAssertTrue(dict1.equal(to: dict2))
    }

ArgumentStorageImpl singleton retains arguments even after resetStubs and resetExpectations calls on the mock

Hi faced an issue when writing an expectation like
objectUserMock .it .expect() .call(objectUserMock.useObject(Arg.eq(objectStub!)), count: 1)

will retain objectStub inside ArgumentStorageImpl.instance even after calling resetStubs and resetExpectations.
As a temporary workaround you may use objectUserMock.expect() which will clear retained arguments
Here is an example repo which reproduce the issue https://github.com/vladislavsosiuk/InstantMockRetainArgumentIssue.
@pirishd Please let me know if you need more info

Ambiguous use of 'eq'

I'm receiving this when I try to pass Arg.eq(nil) to a param that is 'Any?' type.

Any tip?

Setting expectation on a static method

Hi, I'm trying to set an expectation for a static method by adding a static mock to the mock class so I can use it to use the call function in the static method

private static let mock = Mock()
	
static var it: Mock {
     return mock
}

static func staticMethod(_ arg1:String?) {
     mock.call(arg1)
}

and then in the test itself

mock.it.expect().call(mock.staticMethod("test")

But that generates this error :

Fatal error: Invalid argument configuration, see Arg class for more information

Is there a way to do achieve something like this ?

Mocking variables (get and set)

Is there any way to mock variables?

Suppose this class:

class Car {
   var brand: String?
}

And I'd like to have a MockCar, which I could return my pre-determined brand.

Thanks.

Stub method that returns Promise

I'm using PromiseKit, and I have methods like:

func doSomething() -> Promise<String> { ... }

How could I mock and stub so as to use .andReturn with "myString" for example?

Thanks

MockUsable typealias

@pirishd Is there a way to make a typealias MockUsable ? I'm getting this message when I try to implement it :

Conformance of 'Dictionary<Key, Value>' to protocol 'MockUsable' conflicts with that stated in the protocol's module 'InstantMock' and will be ignored; there cannot be more than one conformance, even with different conditional bounds

Arg.eq(protocol)

How to do that since I cant make a protocol extends MockUsable?

stub andReturns for Promises/Awaitkit

I'd like to know why its not returning my response:

let response = ["data": "fake-data"]
self.connection.stub().call(
self.connection.post(
Arg.any()
)
).andReturn(response)

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.