pivotal-legacy / PivotalCoreKit

Shared library and test code for iOS and macOS projects
http://pivotallabs.com
Other
169 stars 85 forks source link

PivotalCoreKit — Common library code for iOS projects.

Build Status

CHANGES

Why PivotalCoreKit

PivotalCoreKit lets you keep creating beautiful apps without having to rewrite the same boilerplate code in every project.

While it has useful functionality in a few different domains, it has a particular focus on helping developers test drive their iOS applications.

What can PivotalCoreKit help with

Highlights

Full list

PivotalCoreKit is split along framework lines, with separate Xcode projects for the Foundation, UIKit, and CoreLocation frameworks. Each project is then separated again out into sub-sections: Core, SpecHelper, and SpecHelperStubs.

Core methods are meant to be used anywhere they're useful, whether in specs or in the primary application. SpecHelper extends built-in classes to make testing easier and more seamless. SpecHelperStubs stub out (and replace) a class's functionality to allow a developer to more easily inspect its state.

Here is a (hopefully exhaustive but inevitably out of date) list of PivotalCoreKit functionality, separated by framework/section:

PivotalCoreKit is test-driven and includes Specs in each project.

That sounds great, give me some examples

Maybe you have a bunch of quarterly reports and want to collect all the finances from the first week for each report. After linking to Foundation+PivotalCore

#import "NSArray+PivotalCore.h"
/* ... */
Week week = FirstWeek;
NSArray *firstWeekFinances = [reports collect:^id(PLReport *report) {
    return [report financesForWeek:week];
}];

Or maybe you're testing that tapping a button properly fires off a network request After linking to UIKit+PivotalSpecHelper

#import "UIControl+Spec.h"
/* ... */
describe(@"when the button is tapped", ^{
    beforeEach(^{
        [button tap];
    });

    it(@"fires a network request", ^{
        apiClient should have_received(@selector(requestNewestRecipes));
    });
});

Say you want to check what URL a webview was asked to load. After linking to UIKit+PivotalSpecHelperStubs

#import "UIWebView+Spec.h"
/* ... */
it(@"webview should load example.com", ^{
    controller.webView.request.URL.absoluteString should equal(@"http://example.com");
});

Without PivotalCoreKit's UIWebView stubs, the webView's NSURLRequest will be nil because the real UIWebView hasn't started actually making the request. A stubbed UIWebView updates the request property immediately.

How do I install PivotalCoreKit

Via CocoaPods

  1. Install CocoaPods with gem install cocoapods.
  2. Create a file in your Xcode project called Podfile and add the following line:
pod 'PivotalCoreKit'

The PivotalCoreKit cocoapod is split into multiple sub pods to allow users to pick-and-choose what parts of the library they want to use. so examine the podspec to choose what pieces you want. An example of a more complicated PodFile would look like this:

target 'ImplementationTarget' do
  pod 'PivotalCoreKit'
end

target 'Specs' do
  pod 'PivotalCoreKit'
  pod 'PivotalCoreKit/UIKit/SpecHelper/Extensions'
  pod 'PivotalCoreKit/Foundation/SpecHelper/Fakes'
end

For OSX Projects - since Foundation is the only OSX-compatible framework, just add the Foundation sub pod to your Podfile.

pod 'PivotalCoreKit/Foundation'
  1. Run pod install in your xcode project directory. CocoaPods should download and install the correct portions of the PivotalCoreKit library, and create a new Xcode workspace. Open up this workspace in Xcode.

Via Git Submodules

Example, adding -[UIButton tap] to a spec target

Library Documentation

Documentation for specific methods and functionality can be found at http://cocoadocs.org/docsets/PivotalCoreKit/

MIT License

Copyright (c) 2014-2018 Pivotal Labs (http://pivotal.io) Contact email: tjarratt@pivotal.io

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.