Code Monkey home page Code Monkey logo

swiftymocky's People

Contributors

amichnia avatar andlang avatar andrzejmichnia avatar chuckluck44 avatar demalex avatar earlofego avatar emn-mun avatar erneestoc avatar g-amichnia avatar gemmakbarlow avatar glyuck avatar gu3st avatar igorbulyga avatar jicedessaint avatar kkirsten avatar lammertw avatar laxmorek avatar migonin avatar mpdifran avatar navartis avatar ohitsdaniel avatar przemyslaw-wosko avatar siarheifedartsou avatar spaluchiewicz avatar tgyhlsb avatar timedelta 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

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

swiftymocky's Issues

Refactor and simplify template code

Also, add some additional library methods, like:

func stubFatalError(methodName: Stirng) -> Never {
  let failureMessage = "MESSAGE" 
  print(failureMessage)
  fatalError(failureMessage)
}

For sake of handling matcher and stub issues.

Support for multiple Given return values

Would be nice, if given will support following:

Given(mock, .method(willReturn: 0,1,2,3,4))

_ = mock.method() // 0
_ = mock.method() // 1
_ = mock.method() // 2
_ = mock.method() // 3
_ = mock.method() // 4

Mock does not conform to protocol when functions differ only in their return type

There is a problem when a protocol has overloaded functions where the signatures differ only in their return type. For example:

//sourcery: AutoMockable
protocol FunctionsThatDifferOnlyInReturnType {
    func foo(bar: String) -> String
    func foo(bar: String) -> Int
}

In that case only for the first function a mock is created and the build fails since the generated class does not conform to the protocol.

Is there a solution for the problem, except of renaming one of the functions?

swift templates broken with sourcery when using Xcode 9.3

I know this isn't really an issue with SwiftyMocky since the fix needs to happen in Sourcery but I wanted to bring it up over here since this where I got the swifttemplate from. I also created an issue here krzysztofzablocki/Sourcery#565

Error I get is here:

Using configuration file at '.sourcery-streetyapi.yml'. WARNING: Ignoring the parameters passed in the command line.
Scanning sources...
Found 116 types.
Loading templates...
Loaded 4 templates.
Generating code...
error: Error Domain=NSOSStatusErrorDomain Code=-1 "kCFStreamErrorHTTPParseFailure / kCFSocketError / kCFStreamErrorDomainCustom / kCSIdentityUnknownAuthorityErr / qErr / telGenericError / dsNoExtsMacsBug / kMovieLoadStateError / cdevGenErr: Could not parse the request/response. /  / custom to the kind of stream in question  /  / queue element not found during deletion /  / not a SysErr, just a placeholder  /  / General error; gray cdev w/o alert" UserInfo={terminationReason=__ObjC.NSTask.TerminationReason, error=dyld: Symbol not found: __T0s11_StringCoreV22isRepresentableAsASCIISbyFSbs6UInt16VcfU_
  Referenced from: /Users/<username>/Library/Caches/Sourcery/AutoMockable.swifttemplate/../SourceryRuntime.framework/Versions/A/SourceryRuntime
  Expected in: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/libswiftCore.dylib
 in /Users/<username>/Library/Caches/Sourcery/AutoMockable.swifttemplate/../SourceryRuntime.framework/Versions/A/SourceryRuntime
}

Extending Matcher for all basic types.

For basic types, we should register default comparators.

Types to handle:

  • Bool
  • String
  • Float
  • Double
  • Character
  • Int
  • Int8
  • Int16
  • Int32
  • Int64
  • UInt
  • UInt8
  • UInt16
  • UInt32
  • UInt64

Handle NSObjectProtocol requirements

SwiftyMocky does not currently handle the case for a protocol that inherits a requirement of NSObjectProcol. The derived mock needs to be a subclass of NSObject for this to compile.

fix for generic methods that differ only in return type

I found a bug when generic methods differ only in a generic return type:

    func foo<T>(bar: String) -> Array<T>
    func foo<T>(bar: String) -> Set<T>

At least for that simple example I fixed it in #112. I’m not sure, if it still works, when the functions have several/other generic parameters.

Compiler error with protocol using generic methods and types

I have this protocol:

public protocol Networking: AutoMockable {
    func upload<T>(resource: Resource<T>) -> Observable<Response<T>>
    func responseUpload<T>(resource: Resource<T>) -> Observable<(HTTPURLResponse, Data)>
    
    func load<T>(resource: Resource<T>) -> Observable<Response<T>>
    func responseLoad<T>(resource: Resource<T>) -> Observable<(HTTPURLResponse, Data)>
}

Which generated this code and fails to compile:
screen shot 2018-03-20 at 1 44 15 pm

Support for perform method

Perform method, that will be called by mocked method, allowing to perform action for passed attributes.

Handling completion block methods.

Support for non XCTest subsclasses

For now Mocky supports only XCTestCase, i'd be nice to separate framework completely from XCTest, and open support for other platforms.

Update testing on for older Swift versions.

At this point, our travis runs tests with same config as whole example project, so Swift 4 etc.

We might need environment, to constantly verify, if our setup is also valid for swift versions 3.x

Invocations count

Currently we can just describe how many invocations we are expecting.

func Verify<T: Mock>(_ object: T, _ count: UInt, _ method: T.Verify, file: StaticString = #file, line: UInt = #line)

We need to add ranges, for instance:

  • at least once
  • never
  • moreThan
  • lessThan

Mocking objects with generic metatype as a method parameter

During development I have encountered a problem with mocking the objects with generic metatype like:

func example<T>(with typeParam: T.Type)

After mocking an object with function like the one above, the resulting generated Mock fails the build with error
Swift Compiler Error (in Mock.generated.swift): Use of undeclared type ‘T’

I would like to ask if the issue is known for you and if there is solution for the problem?

Rename Mocky to SwiftyMocky

Update docs, specs and project for final project name.

Update project structure (needed for docs generation).

[TBD] mock for classes - stubbing real implementations

For some cases, it might make sense (might it?) to stub "real" implementations. That would require to enable adding AutoMockable not only for protocols, but also for non-final classes.

What Mock version could add is:

  • stubbing return values (otherwise super called?)
  • perform on method called (similar for properties?)
  • verify method calls and properties get/set calls

Thing to be discussed.

Full documentation

Prepare full documentation for:

  1. wiki
  2. cocoadocs (jazzy generated? - include additional doc files)
  3. simplify readme

Still needs to be done:

  • Examples
  • verify links to docs in readme

Build error with XCode 9.3 beta

I just tried SwiftyMocky with the newest XCode 9.3 beta. But I couldn’t compile it, since there is an ambiguous use of 'Matcher.register()' and 'Parameter.compare(lhs:rhs:with:)' when the parameters are arrays. I guess, this is related with changes in Swift 4.1.

Verify for properties

Verify getters and setters being called. For setters, we might want to utilise Parameter concept, to verify explicit setters called.

In general, it could look something like:

Verify(mock, getter: .propertyName)
Verify(mock, setter: .propertyName(with: .any))
Verify(mock, setter: .propertyName(with: .value(...)))

Same concept for generation as for other mock cases, So Mock.Setter and Mock.Getter associated types maybe?

Help Wanted - protocol confirming to another protocol

Hi Team,

While integrating SwiftyMocky, we found one issue. Thought of sharing it here -
If one protocol, say B, is conforming to another protocol, say A and we use SwiftyMocky to generate mocks for both A & B. In that case, since methods of protocol A are not generated/added into BMock, code doesn't compiles and throws error as below:
"BMock doesn't confirm to the protocol A."

Please let us know if we have a workaround for this or it is being fixed soon.

Can’t generate mock for generics with type

Hi,

I have an issue when I try to generate a mock from a protocol that has a function like the following:

func decode<T: Decodable>(_ type: T.Type, from data: Data) -> T

Due to the .Type the generic is lost in the generation.

Do you know about this? And does a workaround exist?

Articles about SwiftyMocky

We have quite good documentation, but we need articles that will introduce new users to concept of using this library.
I'd be nice to prepare following articles:

  • Unit testing on iOS, best practices, how to write code to be testable
  • SwiftyMocky - how to use it, how to start, live coding video?
  • Comparison SwiftyMocky vs Cuckoo

@amichnia what do you think?

Skipping *.generated.swift for code generation

As @CurlyHeir mentioned - Mock.generated.swift could be quite big, making future generations slower if being scanned as well.

We should probably exclude all *.generated.swift files from scanning by default.

Version 1.0 release

TODO:

  • regenerate docs
  • add changelog
  • check podspec - should be expandable on github?
  • bump version
  • pod trunk

Error: module compiled with Swift 4.0 cannot be imported in Swift 4.0.3 - SourceryRuntime

Hi guys,

First of all thanks for all the hard work you've put into this project, it looks great. I wanted to try out SwiftMocky in one of our projects and hit an error right away at the mock generation phase.

I am using Xcode 9.2, Swift 4.0.3. I installed SwiftMocky (1.0.2) through Cocoapods (1.3.1) configured the mocky.yml file as instructed in the docs and run :

Pods/Sourcery/bin/Sourcery.app/Contents/MacOS/Sourcery --config mocky.yml

I get the following output

Using configuration file at 'mocky.yml'
Scanning sources...
Found 582 types.
Loading templates...
Loaded 1 templates.
Generating code...
error: /var/folders/s2/xq1bmrbn2y9grg4m2_lppplr0000gq/T/Sourcery.build/main.swift:2:8: error: module compiled with Swift 4.0 cannot be imported in Swift 4.0.3: /var/folders/s2/xq1bmrbn2y9grg4m2_lppplr0000gq/T/SourceryRuntime.framework/Modules/SourceryRuntime.swiftmodule/x86_64.swiftmodule
import SourceryRuntime

I suspect that the SourceryRuntime lib is precompiled using a different version of Swift. Do you have a workaround to this issue?

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.