Giter Club home page Giter Club logo

miles's Introduction

Miles

A thin wrapper around XCTest Macros to make tests just a bit more readable.

Carthage compatible

Miles is a simple solution to an XCTest readability problem.

It feels like every 6 months or so I hop on the Quick/Kiwi bandwagon (because of my frustration with the readability of XCTest) only to grow frustrated with some of the limitations that Xcode imposes. Miles is the simplest solution to the problem that I could come up with.

Miles is named after Darius Miles, a former professional basketball player who also had a role in the 2004 Movie 'The Perfect Score', where he and 5 students try to steal the SAT.

Background

Apple's Xcode includes the XCTest framework, which provides assertion macros to test whether code behaves properly. For example, to assert that 1 + 1 = 2, XCTest has you write:

XCTAssertEqual(1 + 1, 2, "expected one plus one to equal two")

In a more robust matcher framework like Nimble you get the much more readable:

expect(1 + 1).to(equal(2))

In Miles you get something that I think is even more readable:

(1+1).shouldEqual(2)

Usage

Miles.swift defines all the extensions, so make sure it's either included in your Test Target or that you import Miles in the class you're trying to test. Then when you want to validate that the 5+5 = 10 you can do this:

func testThatFivePlusFiveEqualsTen() {
	10.shouldEqual(5 + 5)
}

If you wanted to do something a bit more complicated like validate that a certain string has a suffix, that would look like this:

func testThatMilesEndsInLes() {
	let miles = "miles"
	miles.shouldHaveSuffix("les")
}

Miles currently provides extensions for many of the swift standard types including:

  • String
  • Character
  • Int
  • Float
  • Double
  • Bool
  • NSObject

Because Swift doesn't currently support public extensions on generic types, Miles provides Global functions to validate Array, Dictionary and Optional types.

Installation

The following instructions were taken and repurposed from Quick because it is the best resource I've seen for integrating with a Test Target. As such please note that instead of dragging in Quick and Nimble you'll be dragging in Miles.

How to Install Miles using Carthage

As Test targets do not have the "Embedded Binaries" section, the frameworks must be added to the target's "Link Binary With Libraries" as well as a "Copy Files" build phase to copy them to the target's Frameworks destination.

As Carthage builds dynamic frameworks, you will need a valid code signing identity set up.

  1. Add Miles to your Cartfile.private

    github "MadeByHecho/Miles"
    
  2. Run carthage update

  3. From your Carthage/Build/[platform]/ directory, add Miles to your test target's Link Binary With Libraries build phase

  4. For your test target, create a new build phase of type Copy Files

  5. Set the Destination to Frameworks, then add the Miles framework

This is not 'the one and only way' to use Carthage to manage dependencies, for further reference check out the Carthage documentation

miles's People

Contributors

scottpetit avatar scottconrad avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

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.