GithubHelp home page GithubHelp logo

brightify / cuckoo Goto Github PK

View Code? Open in Web Editor NEW
1.6K 1.6K 168.0 2.55 MB

Boilerplate-free mocking framework for Swift!

License: MIT License

Ruby 1.32% Swift 96.29% Objective-C 1.67% Shell 0.58% Makefile 0.14%
cocoapods cuckoo matcher mock mocking mockito protocol stub swift unit-testing

cuckoo's Introduction

IMPORTANT: This project is currently under heavy development and the API is not stable and might change with upcoming versions. Once beta is released, the API is considered stable and shouldn't change change unless some critical bug is found, which fixing would mean changing the API.

Torch logo

Current status:
Build Status

Support this project using Flattr:
Flattr this git repo

Torch is an Open Source library that makes data storage on Android easy.


Development of Torch ORM is sponsored by Brightify

githalytics.com alpha

cuckoo's People

Contributors

ajpallares avatar arnlen avatar chaoscoder avatar dependabot[bot] avatar dmazzoni avatar dylanmaryk avatar ecoopnet avatar filipdolnik avatar jrg-developer avatar kabiroberai avatar kainjow avatar kaosdg avatar karolbielski avatar kelvinharron avatar louis-van-der-stam avatar luiyen avatar marekslk avatar matyaskriz avatar mgray88 avatar miguelbassila avatar nanashiki avatar nisin avatar nxtstep avatar polandtyler avatar rencevio-philips avatar rolandkakonyi avatar sk409 avatar tadeaskriz avatar watanavex avatar zero3nna 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cuckoo's Issues

GeneratedMocks is empty

I have followed the README but when I run the tests the GeneratedMocks file is empty.

I'm not sure where to go from here. How do I specify which protocols Cuckoo should mock?

Thanks

Issue with mocks for multiple items in a single file

When generating multiple mocks within single file, imports are being duplicated that causes compilation errors.
I'm using slightly modificated script for this purpose.

OUTPUT_FILE="./${PROJECT_NAME}Tests/CuckooMocks/GeneratedMocks.swift"
INPUT_DIR="./${PROJECT_NAME}/Classes"

find ${INPUT_DIR} -name *.swift | xargs \
cuckoo generate \
    --runtime $CUCKOO_VERSION \
    --testable ${PROJECT_NAME} \
    --output ${OUTPUT_FILE}

As an alternative, you create mirror of your application's target directory tree structure inside testing target directory and generate mocks for each file separately. The only problem with this is that you have to manually add generated files and directories into Xcode project.

INPUT_DIR="./${PROJECT_NAME}/Classes"
OUTPUT_DIR="./${PROJECT_NAME}Tests/CuckooMocks"

# Recursively run through the $INPUT_DIR and find files with .swift extension
find ${INPUT_DIR} -type f -iname "*.swift" -print0 | while IFS= read -r -d $'\0' filepath; do
    # Generate mirror path inside $OUTPUT_DIR
    output=${OUTPUT_DIR}${filepath#$INPUT_DIR}
    # Modify filenames by adding 'Mocks' suffix
    output=${output%".swift"}"Mocks.swift"
    # Create mirror directory tree inside $OUTPUT_DIR
    dir=$(dirname ${output})
    mkdir -p ${dir}

    # Run Cuckoo script to generate mock for each file
    cuckoo generate \
        --runtime $CUCKOO_VERSION \
        --testable ${PROJECT_NAME} \
        --output ${output} \
        "$filepath"
done

Can I mock view controllers?

Hi.
I've tried to use this pod for mocking view controllers but I got a lot of errors in generated mock file. For example, if I create a subclass of UIViewController, I will have two errors:

Initializer does not override a designated initializer from its superclass
'required' initializer 'init(coder:)' must be provided by subclass of 'DetailsRegistrationController'

And I want to clarify - do I need to write some additional code to get things work or it is currently impossible?

XCode Run Script step broken after commit aeb465339afed5b6f5a9ae2d06ffc7853467609f

I needed the fix for #55, so I updated to 0.7.0, which then broke the XCode build step (see logs below). I then went back and reinstalled my pods pointing Cuckoo to every commit before the fix for #55. It turns out that commit aeb4653 broke the script that I had, which I copied out of the Readme.md.

Generated Mocks File = ./XYZTests/Mocks/GeneratedMocks.swift
Mocks Input Directory = ./XYZ/Code
/Users/.../XYZ/Pods/Cuckoo/build_generator: line 4: cd: Generator: No such file or directory
Build settings from command line:
    CONFIGURATION_BUILD_DIR = /Users/.../XYZ/Build

xcodebuild: error: 'CuckooGenerator.xcodeproj' does not exist.
mv: rename Build/cuckoo_generator.app to cuckoo_generator.app: No such file or directory
/Users/.../XYZ/smartcom-swift/Pods/Cuckoo/run: line 11: /Users/.../XYZ/Pods/Cuckoo/Generator/cuckoo_generator.app/Contents/MacOS/cuckoo_generator: No such file or directory

Swift 2.2.1 code fails to parse

I have a swift file with a protocol followed by protocol extensions. There are some comments in the file, including // MARK: - declarations.
When I run cuckoo console utility, parsing fails with errors
Unknown kind: source.lang.swift.syntaxtype.comment.mark Unknown kind: source.lang.swift.decl.extension

As a result, the generated file, contains public without any declaration following it. The generated protocol mock looks ok, though.

Problems with project name containing spaces

Hi guys,

there might be some problems, if the project name contains spaces.

Cuckoo generated this file in the project folder:

// MARK: - Mocks generated from file: Scrum at 2016-07-16 06:42:52 +0000


import Cuckoo
@testable import Scrum

The project name is "Scrum Poker"

Greets
Michael

Cuckoo support for objective c

I want to avoid writing my own mocks for objective c classes. FYI my project contains both objective c and swift implementations.

Does cuckoo support objective c class mocks?

Run script not downloading with CocoaPods

I have recently tried installing Cuckoo with CocoaPods and followed the steps exactly as mentioned in the README. However, when the test build reaches the Run Script execution, the build fails with the following error:

/Users/akashgupta/Library/Developer/Xcode/DerivedData/MyProject-fuzogkowjcqugqfvytlccugpuhiw/Build/Intermediates/MyProject.build/Debug-iphonesimulator/MyProjectTests.build/Script-5A21C7261D39029400856AD6.sh: line 11: /Users/akashgupta/Desktop/Workspace/MyProject/Pods/Cuckoo/run: No such file or directory

Apparently, the run script file does not exist. Perhaps it does not get downloaded via CocoaPods?

Moreover, I tried creating the run script file myself, but that led to another failure with the error:

/Users/akashgupta/Library/Developer/Xcode/DerivedData/MyProject-fuzogkowjcqugqfvytlccugpuhiw/Build/Intermediates/MyProject.build/Debug-iphonesimulator/MyProjectTests.build/Script-5A21C7261D39029400856AD6.sh: line 11: /Users/akashgupta/Desktop/Workspace/MyProject/Pods/Cuckoo/run: Permission denied

Is there something I am missing while integrating this framework?

custom initializers causing errors in generated mock file

following code

  init(userName: String, password: String)  {
    self.userName = userName
    self.password = password
    self.sessionId = (self.userName+self.password).hash.description
  }

generates this:

    override init(userName userName: String, password: String) {
        return manager.call("init(userName:String, password:String)", parameters: (userName: userName, password: password), original: observed.map { o in return { (userName userName: String, password: String) in o.init(userName: userName, password: password) } })
    }

removing the double designation doesn't help

Swift 2.2 support.

Sadly it's not working with Swift 2.3.
There is one error in this line:
XCTFail(description.description, file: sourceLocation.file, line: sourceLocation.line)
changing it to this:
XCTFail(description.description, file: "sourceLocation.file", line: sourceLocation.line)
made it work (I know it's not proper solution).
But then I had a bunch of error that labels are not allowed in closures (Xcode can auto fix that).
But at the end all tests are failing with fatal error. "No stuff for method was provided." (Tests were passing before the update).

Any plans to solving that?

Example with equalTo

Hey,
Could you provide example of mock that will expect specific value of argument. I know that there is an example with String in readme, but for it doesn't work for me with any other class/struct.

"Illegal instruction" with master version

I am attempting to use the project with a Swift 3 app, which requires I use the master branch rather than the released version. Unfortunately, when following the installation instructions I get this error:

./Pods/Cuckoo/run: line 18: 85564 Illegal instruction: 4  $FILE_PATH/Contents/MacOS/cuckoo_generator "$@" ${INPUT_FILES}

The generator builds correctly before this error.

I am running 10.11.6 on a Macbook Retina Pro 15" 2014.

Thanks!

What is the relevance of spy in the sample code?

This isn't really an issue more of a question.

Anyway, in the sample code you create a spy variable using MockGenerator but then it isn't referenced again in the code.

Please could someone explain the relevance of this? Is it required?

Thanks

No homebrew formula for cuckoo

I tried to install the generator via homebrew and got the following message:

bash-3.2$ brew install cuckoo
Error: No available formula with the name "cuckoo" 
==> Searching for similarly named formulae...
Error: No similarly named formulae found.
==> Searching taps...
Error: No formulae found in taps.

Optional closure

How can I mock a function that have an optional closure?

func optinalClosure(optionalClosure: (String -> ())?)

I get this error:

Value of type 'Stubbing' (aka 'MockTestedProtocol.__StubbingProxy_TestedProtocol') has no member 'MatchedType'

[Feature request] Generate mocks only for annotated classes/protocols

Hi, I'm starting to use Cuckoo and find it absolutely amazing! Thousands of kudos for the great work!
I am wondering if you already have on your roadmap support for annotations, so that mocks will get generated only for manually annotated classes/protocols, e.g.:

/// @GenerateMock
protocol AwesomeProtocol {
}

Thanks!

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.