Git Product home page Git Product logo

msspec's Introduction

MSSpec

What is it?

MSSpec is a Kiwi Spec with support to inject mocks using Objection. Using mocks in your specs is now as easy as this:

MSSPEC_BEGIN(MSCarSpec)

MSMockClass(MSEngine);

__block MSCar *car;
__block MSEngine *engine;

beforeEach(^{
	// this instance will be created using the default injector
	car = MSInjectionCreateObject(MSCar);
	
	// this will be the same mock injected to car
	engine = MSInjectionCreateObject(MSEngine);
});

it(@"has a configured engine", ^{
	NSString *name = @"name";
	[engine stub:@selector(name) andReturn:name];

	[[car.engine.name should] equal:name];
});

MSSPEC_END

Using Objection is much easier

<MSSpec/MSInjection.h> also includes a series of macros to make working with Objection much easier:

  • MSInjectionRequireProperties: defines a list of properties to be injected into the class. Example: MSInjectionRequireProperties(car, engine)
  • MSInjectionDesignatedInitializer: defines the designated initializer for the class (default is init).
  • MSInjectionCreateObject: instantiates an object of the specified class and injects it all its dependencies. This object is initialized with init: unless MSInjectionDesignatedInitializer has been used.
  • MSInjectionInjectDependencies: if the object has declared its dependencies using MSInjectionRequireProperties, but was allocated outside of the injector's life cycle, use this to immediately inject dependencies.

Dependencies can then be injected in one of two ways:

  • Instantiate the object using MSInjectionCreateObject(ClassName).
  • Calling MSInjectionInjectDependencies() somewhere in the initialization.

Installation:

Using CocoaPods:

target :App do
	pod 'MSSpec' # this gives you access to the MSInjection.h macros in your app.

	target :Tests do
		pod 'MSSpec/Tests' # MSSPEC macros for your tests.
	end
end

You don't need to add Objection or Kiwi.

Finally:

  • #import <MSSpec/MSInjection.h> in your main target's pch file.
  • And #import <MSSpec/MSSpec.h> in your test's target pch file.

msspec's People

Contributors

nachosoto avatar miguelcarranza avatar

Watchers

Gilad Gurantz avatar James Cloos 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.