Last active
December 14, 2015 11:39
-
-
Save AlexDenisov/5081104 to your computer and use it in GitHub Desktop.
Additional Cedar matchers
https://github.com/pivotal/cedar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ConformsTo.h | |
// | |
// Created by Alex Denisov on 01.03.13. | |
// | |
#pragma once | |
#import <Foundation/Foundation.h> | |
#import <Cedar-iOS/Cedar-iOS.h> | |
namespace Cedar { namespace Matchers { | |
class ConformsTo : public Base<> { | |
private: | |
ConformsTo & operator=(const ConformsTo &); | |
public: | |
explicit ConformsTo(Protocol *protocol); | |
ConformsTo(NSString *protocolName); | |
~ConformsTo(); | |
bool matches(const id) const; | |
protected: | |
virtual NSString * failure_message_end() const; | |
private: | |
const Protocol *expectedProtocol_; | |
}; | |
inline ConformsTo conforms_to(Protocol *protocol) { | |
return ConformsTo(protocol); | |
} | |
inline ConformsTo conforms_to(NSString *protocolName) { | |
return ConformsTo(protocolName); | |
} | |
inline ConformsTo::ConformsTo(Protocol *protocol) | |
: Base<>(), expectedProtocol_(protocol) {} | |
inline ConformsTo::ConformsTo(NSString *protocolName) | |
: Base<>(), expectedProtocol_(NSProtocolFromString(protocolName)) { } | |
inline ConformsTo::~ConformsTo() {} | |
inline /*virtual*/ NSString * ConformsTo::failure_message_end() const { | |
return [NSString stringWithFormat:@"conform <%@> protocol", | |
NSStringFromProtocol((Protocol *)expectedProtocol_)]; | |
} | |
#pragma mark Generic | |
inline bool ConformsTo::matches(const id actualValue) const { | |
return [actualValue conformsToProtocol:(Protocol *)expectedProtocol_]; | |
} | |
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// RespondsTo.h | |
// | |
// Created by Alex Denisov on 21.02.13. | |
// | |
#pragma once | |
#import <Foundation/Foundation.h> | |
#import <Cedar-iOS/Cedar-iOS.h> | |
namespace Cedar { namespace Matchers { | |
class RespondsTo : public Base<> { | |
private: | |
RespondsTo & operator=(const RespondsTo &); | |
public: | |
explicit RespondsTo(const SEL selector); | |
RespondsTo(NSString * selectorName); | |
~RespondsTo(); | |
bool matches(const id) const; | |
protected: | |
virtual NSString * failure_message_end() const; | |
private: | |
const SEL expectedSelector_; | |
}; | |
inline RespondsTo responds_to(const SEL selector) { | |
return RespondsTo(selector); | |
} | |
inline RespondsTo responds_to(NSString *selectorName) { | |
return RespondsTo(NSSelectorFromString(selectorName)); | |
} | |
inline RespondsTo::RespondsTo(const SEL selector) | |
: Base<>(), expectedSelector_(selector) {} | |
inline RespondsTo::RespondsTo(NSString *selectorName) | |
: Base<>(), expectedSelector_(NSSelectorFromString(selectorName)) {} | |
inline RespondsTo::~RespondsTo() {} | |
inline /*virtual*/ NSString * RespondsTo::failure_message_end() const { | |
return [NSString stringWithFormat:@"respond <%@> selector", | |
NSStringFromSelector(expectedSelector_)]; | |
} | |
#pragma mark Generic | |
inline bool RespondsTo::matches(const id actualValue) const { | |
return [actualValue respondsToSelector:expectedSelector_]; | |
} | |
}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Crasava!