8000 GitHub - bdlindsay/Parrot: Parrot is a compile-time Mock Generator for Swift - written completely in Swift. It's geared towards use in Xcode and works for any kind of swift project (e.g. server side, iOS, or command line tools). The mock structure is modeled off of the sinon.js APIs
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Parrot is a compile-time Mock Generator for Swift - written completely in Swift. It's geared towards use in Xcode and works for any kind of swift project (e.g. server side, iOS, or command line tools). The mock structure is modeled off of the sinon.js APIs

License

Notifications You must be signed in to change notification settings

bdlindsay/Parrot

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Installation:

Adding to a Project

Command Line(assuming in base of project directory):

git submodule add git@github.com:MonsantoCo/Parrot.git

cd Parrot

git submodule update --init

  • Open the Parrot xcode project and select a signing certificate (the next step will fail if a valid signing certificate is not selected)

xcodebuild

Open project

  • Go to Project File
  • Select the target for your unit tests
  • Select 'Build Phases'
  • Select '+' -> 'New Run Script'
  • Drag the run script to be before the 'Compile Sources' step, but after the 'Target Dependencies' step
  • Example Script (Bash):
PARROT=$PROJECT_DIR/Parrot/build/Release/Parrot
SOURCE=$PROJECT_DIR/[YourAppDirectoryName]
TESTS=$PROJECT_DIR/[YourAppTestDirectoryName]

if [ -f "$PARROT" ]; then
    echo "💚 Running Parrot - SQUAAWWWKKKK 💚"
    $PARROT $SOURCE $TESTS || exit 0
else
    echo "⚠️ xcodebuild gitsubmodule Parrot to enable mock generation"
fi

Usage:

  • Add the annotation //@@parrot-mockabove any class definition conforming to a protocol somewhere in the project (protocols defined inside frameworks will not be found yet)
  • Example:
@testable import [AppName] // All lines above the annotation will be preserved

//@@parrot-mock
class MockClass: ClassProtocol {

}
  • When your test target builds, a mock will be generated before compile time

Non-Basic and Custom Types:

  • If you use types like UUID or Date you'll see that Parrot doesn't know how to generate instantiations for these types or any of your custom classes and structs. It will just leave placeholders in generated mocks. parrot-defaults.swift is the solution for telling Parrot how to instantiate types it wouldn't otherwise know how to create.
  • Add a file called parrot-defaults.swift to the base of your test directory.
  • Each line can teach parrot how to instantiate a type by defining a variable with an explicitly named type and then proceeding to instantiate that type. (e.g. let parrotUUID: UUID = UUID(), "let anyCustomType: CustomType = CustomType()")
  • Parrot will always check this list first before generating a mock so if you want to override some of the defaults for basics types, you can do that as well. let newIntDefaultValue: Int = 1 will make all Int types instantiate to 1 instead of 0 in your mocks.
  • Friendly Reminder: Don't forget to have appropriate import statements both in parrot-defaults.swift and your mocks.

About

Parrot is a compile-time Mock Generator for Swift - written completely in Swift. It's geared towards use in Xcode and works for any kind of swift project (e.g. server side, iOS, or command line tools). The mock structure is modeled off of the sinon.js APIs

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 100.0%
0