First API implementation, yay!
This commit is contained in:
parent
6782e2b212
commit
61a0e0f681
|
@ -0,0 +1,30 @@
|
|||
#
|
||||
# Be sure to run `pod lib lint Mockery.podspec' to ensure this is a
|
||||
# valid spec before submitting.
|
||||
#
|
||||
# Any lines starting with a # are optional, but their use is encouraged
|
||||
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
|
||||
#
|
||||
|
||||
Pod::Spec.new do |s|
|
||||
s.name = "Mockery"
|
||||
s.version = "0.1.0"
|
||||
s.summary = "Mockery - first boilerplate-free Swift mocking framework."
|
||||
s.description = <<-DESC
|
||||
DESC
|
||||
|
||||
s.homepage = "https://github.com/SwiftKit/Mockery"
|
||||
s.license = 'MIT'
|
||||
s.author = { "Tadeas Kriz" => "tadeas@brightify.org" }
|
||||
s.source = {
|
||||
:git => "https://github.com/SwiftKit/Mockery.git",
|
||||
:tag => s.version.to_s
|
||||
}
|
||||
|
||||
s.ios.deployment_target = '8.0'
|
||||
s.osx.deployment_target = '10.9'
|
||||
s.watchos.deployment_target = '2.0'
|
||||
s.tvos.deployment_target = '9.0'
|
||||
s.source_files = 'Source/**/*.swift'
|
||||
s.frameworks = 'XCTest'
|
||||
end
|
|
@ -0,0 +1,432 @@
|
|||
// !$*UTF8*$!
|
||||
{
|
||||
archiveVersion = 1;
|
||||
classes = {
|
||||
};
|
||||
objectVersion = 46;
|
||||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
181F419F1C46C6B3005BAB70 /* StubbingFunctions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 181F419E1C46C6B3005BAB70 /* StubbingFunctions.swift */; };
|
||||
181F41A11C46C6E7005BAB70 /* Verification.swift in Sources */ = {isa = PBXBuildFile; fileRef = 181F41A01C46C6E7005BAB70 /* Verification.swift */; };
|
||||
181F41A31C46C716005BAB70 /* VerificationFunctions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 181F41A21C46C716005BAB70 /* VerificationFunctions.swift */; };
|
||||
181F41A51C46CBBD005BAB70 /* Matcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 181F41A41C46CBBD005BAB70 /* Matcher.swift */; };
|
||||
181F41A71C46CC3D005BAB70 /* Matchers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 181F41A61C46CC3D005BAB70 /* Matchers.swift */; };
|
||||
181F41A91C46D491005BAB70 /* MatcherFunctions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 181F41A81C46D491005BAB70 /* MatcherFunctions.swift */; };
|
||||
183D03FF1C4691C600EBAEF3 /* Mockery.h in Headers */ = {isa = PBXBuildFile; fileRef = 183D03FE1C4691C600EBAEF3 /* Mockery.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
183D04061C4691C600EBAEF3 /* Mockery.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 183D03FB1C4691C600EBAEF3 /* Mockery.framework */; };
|
||||
183D040B1C4691C600EBAEF3 /* MockeryAPITest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 183D040A1C4691C600EBAEF3 /* MockeryAPITest.swift */; };
|
||||
183D04161C46926A00EBAEF3 /* Mockery.swift in Sources */ = {isa = PBXBuildFile; fileRef = 183D04151C46926A00EBAEF3 /* Mockery.swift */; };
|
||||
183D041A1C46C14000EBAEF3 /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 183D04191C46C14000EBAEF3 /* Utils.swift */; };
|
||||
183D041C1C46C65300EBAEF3 /* Stubbing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 183D041B1C46C65300EBAEF3 /* Stubbing.swift */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXContainerItemProxy section */
|
||||
183D04071C4691C600EBAEF3 /* PBXContainerItemProxy */ = {
|
||||
isa = PBXContainerItemProxy;
|
||||
containerPortal = 183D03F21C4691C600EBAEF3 /* Project object */;
|
||||
proxyType = 1;
|
||||
remoteGlobalIDString = 183D03FA1C4691C600EBAEF3;
|
||||
remoteInfo = Mockery;
|
||||
};
|
||||
/* End PBXContainerItemProxy section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
181F419E1C46C6B3005BAB70 /* StubbingFunctions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StubbingFunctions.swift; sourceTree = "<group>"; };
|
||||
181F41A01C46C6E7005BAB70 /* Verification.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Verification.swift; sourceTree = "<group>"; };
|
||||
181F41A21C46C716005BAB70 /* VerificationFunctions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VerificationFunctions.swift; sourceTree = "<group>"; };
|
||||
181F41A41C46CBBD005BAB70 /* Matcher.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Matcher.swift; sourceTree = "<group>"; };
|
||||
181F41A61C46CC3D005BAB70 /* Matchers.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Matchers.swift; sourceTree = "<group>"; };
|
||||
181F41A81C46D491005BAB70 /* MatcherFunctions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MatcherFunctions.swift; sourceTree = "<group>"; };
|
||||
183D03FB1C4691C600EBAEF3 /* Mockery.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Mockery.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
183D03FE1C4691C600EBAEF3 /* Mockery.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Mockery.h; sourceTree = "<group>"; };
|
||||
183D04001C4691C600EBAEF3 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
183D04051C4691C600EBAEF3 /* MockeryTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MockeryTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
183D040A1C4691C600EBAEF3 /* MockeryAPITest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockeryAPITest.swift; sourceTree = "<group>"; };
|
||||
183D040C1C4691C600EBAEF3 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
183D04151C46926A00EBAEF3 /* Mockery.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Mockery.swift; sourceTree = "<group>"; };
|
||||
183D04191C46C14000EBAEF3 /* Utils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Utils.swift; sourceTree = "<group>"; };
|
||||
183D041B1C46C65300EBAEF3 /* Stubbing.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Stubbing.swift; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
183D03F71C4691C600EBAEF3 /* Frameworks */ = {
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
183D04021C4691C600EBAEF3 /* Frameworks */ = {
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
183D04061C4691C600EBAEF3 /* Mockery.framework in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXFrameworksBuildPhase section */
|
||||
|
||||
/* Begin PBXGroup section */
|
||||
183D03F11C4691C600EBAEF3 = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
183D03FD1C4691C600EBAEF3 /* Source */,
|
||||
183D04091C4691C600EBAEF3 /* Tests */,
|
||||
183D03FC1C4691C600EBAEF3 /* Products */,
|
||||
);
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
183D03FC1C4691C600EBAEF3 /* Products */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
183D03FB1C4691C600EBAEF3 /* Mockery.framework */,
|
||||
183D04051C4691C600EBAEF3 /* MockeryTests.xctest */,
|
||||
);
|
||||
name = Products;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
183D03FD1C4691C600EBAEF3 /* Source */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
183D03FE1C4691C600EBAEF3 /* Mockery.h */,
|
||||
183D04001C4691C600EBAEF3 /* Info.plist */,
|
||||
183D04151C46926A00EBAEF3 /* Mockery.swift */,
|
||||
183D04191C46C14000EBAEF3 /* Utils.swift */,
|
||||
183D041B1C46C65300EBAEF3 /* Stubbing.swift */,
|
||||
181F419E1C46C6B3005BAB70 /* StubbingFunctions.swift */,
|
||||
181F41A01C46C6E7005BAB70 /* Verification.swift */,
|
||||
181F41A21C46C716005BAB70 /* VerificationFunctions.swift */,
|
||||
181F41A41C46CBBD005BAB70 /* Matcher.swift */,
|
||||
181F41A61C46CC3D005BAB70 /* Matchers.swift */,
|
||||
181F41A81C46D491005BAB70 /* MatcherFunctions.swift */,
|
||||
);
|
||||
path = Source;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
183D04091C4691C600EBAEF3 /* Tests */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
183D040A1C4691C600EBAEF3 /* MockeryAPITest.swift */,
|
||||
183D040C1C4691C600EBAEF3 /* Info.plist */,
|
||||
);
|
||||
path = Tests;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXGroup section */
|
||||
|
||||
/* Begin PBXHeadersBuildPhase section */
|
||||
183D03F81C4691C600EBAEF3 /* Headers */ = {
|
||||
isa = PBXHeadersBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
183D03FF1C4691C600EBAEF3 /* Mockery.h in Headers */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXHeadersBuildPhase section */
|
||||
|
||||
/* Begin PBXNativeTarget section */
|
||||
183D03FA1C4691C600EBAEF3 /* Mockery */ = {
|
||||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = 183D040F1C4691C600EBAEF3 /* Build configuration list for PBXNativeTarget "Mockery" */;
|
||||
buildPhases = (
|
||||
183D03F61C4691C600EBAEF3 /* Sources */,
|
||||
183D03F71C4691C600EBAEF3 /* Frameworks */,
|
||||
183D03F81C4691C600EBAEF3 /* Headers */,
|
||||
183D03F91C4691C600EBAEF3 /* Resources */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
dependencies = (
|
||||
);
|
||||
name = Mockery;
|
||||
productName = Mockery;
|
||||
productReference = 183D03FB1C4691C600EBAEF3 /* Mockery.framework */;
|
||||
productType = "com.apple.product-type.framework";
|
||||
};
|
||||
183D04041C4691C600EBAEF3 /* MockeryTests */ = {
|
||||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = 183D04121C4691C600EBAEF3 /* Build configuration list for PBXNativeTarget "MockeryTests" */;
|
||||
buildPhases = (
|
||||
183D04011C4691C600EBAEF3 /* Sources */,
|
||||
183D04021C4691C600EBAEF3 /* Frameworks */,
|
||||
183D04031C4691C600EBAEF3 /* Resources */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
dependencies = (
|
||||
183D04081C4691C600EBAEF3 /* PBXTargetDependency */,
|
||||
);
|
||||
name = MockeryTests;
|
||||
productName = MockeryTests;
|
||||
productReference = 183D04051C4691C600EBAEF3 /* MockeryTests.xctest */;
|
||||
productType = "com.apple.product-type.bundle.unit-test";
|
||||
};
|
||||
/* End PBXNativeTarget section */
|
||||
|
||||
/* Begin PBXProject section */
|
||||
183D03F21C4691C600EBAEF3 /* Project object */ = {
|
||||
isa = PBXProject;
|
||||
attributes = {
|
||||
LastSwiftUpdateCheck = 0720;
|
||||
LastUpgradeCheck = 0720;
|
||||
ORGANIZATIONNAME = Brightify;
|
||||
TargetAttributes = {
|
||||
183D03FA1C4691C600EBAEF3 = {
|
||||
CreatedOnToolsVersion = 7.2;
|
||||
};
|
||||
183D04041C4691C600EBAEF3 = {
|
||||
CreatedOnToolsVersion = 7.2;
|
||||
};
|
||||
};
|
||||
};
|
||||
buildConfigurationList = 183D03F51C4691C600EBAEF3 /* Build configuration list for PBXProject "Mockery" */;
|
||||
compatibilityVersion = "Xcode 3.2";
|
||||
developmentRegion = English;
|
||||
hasScannedForEncodings = 0;
|
||||
knownRegions = (
|
||||
en,
|
||||
);
|
||||
mainGroup = 183D03F11C4691C600EBAEF3;
|
||||
productRefGroup = 183D03FC1C4691C600EBAEF3 /* Products */;
|
||||
projectDirPath = "";
|
||||
projectRoot = "";
|
||||
targets = (
|
||||
183D03FA1C4691C600EBAEF3 /* Mockery */,
|
||||
183D04041C4691C600EBAEF3 /* MockeryTests */,
|
||||
);
|
||||
};
|
||||
/* End PBXProject section */
|
||||
|
||||
/* Begin PBXResourcesBuildPhase section */
|
||||
183D03F91C4691C600EBAEF3 /* Resources */ = {
|
||||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
183D04031C4691C600EBAEF3 /* Resources */ = {
|
||||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXResourcesBuildPhase section */
|
||||
|
||||
/* Begin PBXSourcesBuildPhase section */
|
||||
183D03F61C4691C600EBAEF3 /* Sources */ = {
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
181F41A11C46C6E7005BAB70 /* Verification.swift in Sources */,
|
||||
181F419F1C46C6B3005BAB70 /* StubbingFunctions.swift in Sources */,
|
||||
183D04161C46926A00EBAEF3 /* Mockery.swift in Sources */,
|
||||
181F41A71C46CC3D005BAB70 /* Matchers.swift in Sources */,
|
||||
181F41A91C46D491005BAB70 /* MatcherFunctions.swift in Sources */,
|
||||
181F41A51C46CBBD005BAB70 /* Matcher.swift in Sources */,
|
||||
183D041A1C46C14000EBAEF3 /* Utils.swift in Sources */,
|
||||
181F41A31C46C716005BAB70 /* VerificationFunctions.swift in Sources */,
|
||||
183D041C1C46C65300EBAEF3 /* Stubbing.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
183D04011C4691C600EBAEF3 /* Sources */ = {
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
183D040B1C4691C600EBAEF3 /* MockeryAPITest.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXSourcesBuildPhase section */
|
||||
|
||||
/* Begin PBXTargetDependency section */
|
||||
183D04081C4691C600EBAEF3 /* PBXTargetDependency */ = {
|
||||
isa = PBXTargetDependency;
|
||||
target = 183D03FA1C4691C600EBAEF3 /* Mockery */;
|
||||
targetProxy = 183D04071C4691C600EBAEF3 /* PBXContainerItemProxy */;
|
||||
};
|
||||
/* End PBXTargetDependency section */
|
||||
|
||||
/* Begin XCBuildConfiguration section */
|
||||
183D040D1C4691C600EBAEF3 /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
|
||||
CLANG_CXX_LIBRARY = "libc++";
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CLANG_ENABLE_OBJC_ARC = YES;
|
||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
|
||||
COPY_PHASE_STRIP = NO;
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
DEBUG_INFORMATION_FORMAT = dwarf;
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||
ENABLE_TESTABILITY = YES;
|
||||
GCC_C_LANGUAGE_STANDARD = gnu99;
|
||||
GCC_DYNAMIC_NO_PIC = NO;
|
||||
GCC_NO_COMMON_BLOCKS = YES;
|
||||
GCC_OPTIMIZATION_LEVEL = 0;
|
||||
GCC_PREPROCESSOR_DEFINITIONS = (
|
||||
"DEBUG=1",
|
||||
"$(inherited)",
|
||||
);
|
||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
||||
GCC_WARN_UNDECLARED_SELECTOR = YES;
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 9.2;
|
||||
MTL_ENABLE_DEBUG_INFO = YES;
|
||||
ONLY_ACTIVE_ARCH = YES;
|
||||
SDKROOT = iphoneos;
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||
TARGETED_DEVICE_FAMILY = "1,2";
|
||||
VERSIONING_SYSTEM = "apple-generic";
|
||||
VERSION_INFO_PREFIX = "";
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
183D040E1C4691C600EBAEF3 /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
|
||||
CLANG_CXX_LIBRARY = "libc++";
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CLANG_ENABLE_OBJC_ARC = YES;
|
||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
|
||||
COPY_PHASE_STRIP = NO;
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
||||
ENABLE_NS_ASSERTIONS = NO;
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||
GCC_C_LANGUAGE_STANDARD = gnu99;
|
||||
GCC_NO_COMMON_BLOCKS = YES;
|
||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
||||
GCC_WARN_UNDECLARED_SELECTOR = YES;
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 9.2;
|
||||
MTL_ENABLE_DEBUG_INFO = NO;
|
||||
SDKROOT = iphoneos;
|
||||
TARGETED_DEVICE_FAMILY = "1,2";
|
||||
VALIDATE_PRODUCT = YES;
|
||||
VERSIONING_SYSTEM = "apple-generic";
|
||||
VERSION_INFO_PREFIX = "";
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
183D04101C4691C600EBAEF3 /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
DEFINES_MODULE = YES;
|
||||
DYLIB_COMPATIBILITY_VERSION = 1;
|
||||
DYLIB_CURRENT_VERSION = 1;
|
||||
DYLIB_INSTALL_NAME_BASE = "@rpath";
|
||||
INFOPLIST_FILE = "$(SRCROOT)/Source/Info.plist";
|
||||
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = org.brightify.Mockery;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SKIP_INSTALL = YES;
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
183D04111C4691C600EBAEF3 /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
DEFINES_MODULE = YES;
|
||||
DYLIB_COMPATIBILITY_VERSION = 1;
|
||||
DYLIB_CURRENT_VERSION = 1;
|
||||
DYLIB_INSTALL_NAME_BASE = "@rpath";
|
||||
INFOPLIST_FILE = "$(SRCROOT)/Source/Info.plist";
|
||||
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = org.brightify.Mockery;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SKIP_INSTALL = YES;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
183D04131C4691C600EBAEF3 /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
INFOPLIST_FILE = Tests/Info.plist;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = org.brightify.MockeryTests;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
183D04141C4691C600EBAEF3 /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
INFOPLIST_FILE = Tests/Info.plist;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = org.brightify.MockeryTests;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
/* End XCBuildConfiguration section */
|
||||
|
||||
/* Begin XCConfigurationList section */
|
||||
183D03F51C4691C600EBAEF3 /* Build configuration list for PBXProject "Mockery" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
183D040D1C4691C600EBAEF3 /* Debug */,
|
||||
183D040E1C4691C600EBAEF3 /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
183D040F1C4691C600EBAEF3 /* Build configuration list for PBXNativeTarget "Mockery" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
183D04101C4691C600EBAEF3 /* Debug */,
|
||||
183D04111C4691C600EBAEF3 /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
183D04121C4691C600EBAEF3 /* Build configuration list for PBXNativeTarget "MockeryTests" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
183D04131C4691C600EBAEF3 /* Debug */,
|
||||
183D04141C4691C600EBAEF3 /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
/* End XCConfigurationList section */
|
||||
};
|
||||
rootObject = 183D03F21C4691C600EBAEF3 /* Project object */;
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Workspace
|
||||
version = "1.0">
|
||||
<FileRef
|
||||
location = "self:Mockery.xcodeproj">
|
||||
</FileRef>
|
||||
</Workspace>
|
30
README.md
30
README.md
|
@ -1 +1,29 @@
|
|||
# Mockery
|
||||
# Mockery
|
||||
|
||||
[](https://travis-ci.org/Tadeas Kriz/Mockery)
|
||||
[](http://cocoapods.org/pods/Mockery)
|
||||
[](http://cocoapods.org/pods/Mockery)
|
||||
[](http://cocoapods.org/pods/Mockery)
|
||||
|
||||
## Usage
|
||||
|
||||
To run the example project, clone the repo, and run `pod install` from the Example directory first.
|
||||
|
||||
## Requirements
|
||||
|
||||
## Installation
|
||||
|
||||
Mockery is available through [CocoaPods](http://cocoapods.org). To install
|
||||
it, simply add the following line to your Podfile:
|
||||
|
||||
```ruby
|
||||
pod "Mockery"
|
||||
```
|
||||
|
||||
## Author
|
||||
|
||||
Tadeas Kriz, tadeas@brightify.org
|
||||
|
||||
## License
|
||||
|
||||
Mockery is available under the MIT license. See the LICENSE file for more info.
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>$(PRODUCT_NAME)</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>$(CURRENT_PROJECT_VERSION)</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string></string>
|
||||
</dict>
|
||||
</plist>
|
|
@ -0,0 +1,29 @@
|
|||
//
|
||||
// Matcher.swift
|
||||
// Mockery
|
||||
//
|
||||
// Created by Tadeas Kriz on 13/01/16.
|
||||
// Copyright © 2016 Brightify. All rights reserved.
|
||||
//
|
||||
|
||||
public protocol Matcher {
|
||||
typealias MatchedType
|
||||
|
||||
/**
|
||||
Returns description for this matcher when applied to the given input.
|
||||
|
||||
This is used to give user more information why the matcher did not match for example.
|
||||
*/
|
||||
func describe(input: MatchedType) -> String
|
||||
|
||||
/**
|
||||
Returns true if the input is matched by this matcher, false otherwise.
|
||||
*/
|
||||
func matches(input: MatchedType) -> Bool
|
||||
}
|
||||
|
||||
extension Matcher {
|
||||
func typeErased() -> AnyMatcher<MatchedType> {
|
||||
return AnyMatcher(self)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
//
|
||||
// VerificationMatchers.swift
|
||||
// Mockery
|
||||
//
|
||||
// Created by Tadeas Kriz on 13/01/16.
|
||||
// Copyright © 2016 Brightify. All rights reserved.
|
||||
//
|
||||
|
||||
private func compareCalls(count: Int, whenNil: Bool = false, using function: (Int, Int) -> Bool)(stub: Stub?) -> Bool {
|
||||
return stub.map { function(count, $0.calledTimes) } ?? whenNil
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func times(count: Int) -> AnyMatcher<Stub?> {
|
||||
return FunctionMatcher(function: compareCalls(count, using: ==)) {
|
||||
"expected to be called exactly <\(count)> times, but was called <\($0)> times"
|
||||
}.typeErased()
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func never() -> AnyMatcher<Stub?> {
|
||||
return FunctionMatcher(function: compareCalls(0, whenNil: true, using: ==)) {
|
||||
"expected to not be called, but was called <\($0)> times"
|
||||
}.typeErased()
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func atLeastOnce() -> AnyMatcher<Stub?> {
|
||||
return atLeast(1)
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func atLeast(count: Int) -> AnyMatcher<Stub?> {
|
||||
return FunctionMatcher(function: compareCalls(count, using: >=)) {
|
||||
"expected to be called at least <\(count)> times, but was called only <\($0)> times"
|
||||
}.typeErased()
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func atMost(count: Int) -> AnyMatcher<Stub?> {
|
||||
return FunctionMatcher(function: compareCalls(count, whenNil: true, using: <=)) {
|
||||
"expected to be called at most <\(count)> times, but was called <\($0)> times"
|
||||
}.typeErased()
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func equalTo<T: Equatable>(value: T) -> AnyMatcher<T> {
|
||||
return equalTo(value, equalWhen: ==)
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func equalTo<T: AnyObject>(value: T) -> AnyMatcher<T> {
|
||||
return equalTo(value, equalWhen: ===)
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func equalTo<T>(value: T, equalWhen equalityFunction: (T, T) -> Bool) -> AnyMatcher<T> {
|
||||
return FunctionMatcher(original: value, function: equalityFunction) {
|
||||
"expected value equal to <\($0)> got <\($1)"
|
||||
}.typeErased()
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func anyInt() -> AnyMatcher<Int> {
|
||||
return AnyMatcher()
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func anyString() -> AnyMatcher<String> {
|
||||
return AnyMatcher()
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func any() -> AnyMatcher<Any> {
|
||||
return AnyMatcher()
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
//
|
||||
// Matchers.swift
|
||||
// Mockery
|
||||
//
|
||||
// Created by Tadeas Kriz on 13/01/16.
|
||||
// Copyright © 2016 Brightify. All rights reserved.
|
||||
//
|
||||
|
||||
// Heavy type erasure in this class. Might be very dangerous!
|
||||
public struct AnyMatcher<T>: Matcher {
|
||||
let targetType: Any.Type
|
||||
let describeFunction: T throws -> String
|
||||
let matchesFunction: T throws -> Bool
|
||||
|
||||
init<M: Matcher>(_ wrapped: M) {
|
||||
self.targetType = M.MatchedType.self
|
||||
self.describeFunction = stripInputTypeInformation(wrapped.describe)
|
||||
self.matchesFunction = stripInputTypeInformation(wrapped.matches)
|
||||
}
|
||||
|
||||
init() {
|
||||
self.targetType = T.self
|
||||
|
||||
// Stubs to enable simple type matching
|
||||
self.describeFunction = stripInputTypeInformation(T.self, from: { _ in "" })
|
||||
self.matchesFunction = stripInputTypeInformation(T.self, from: { _ in true })
|
||||
}
|
||||
|
||||
public func describe(input: T) -> String {
|
||||
do {
|
||||
return try describeFunction(input)
|
||||
} catch TypeStripingError.CalledWithIncorrectType {
|
||||
return "expected instance of <\(targetType)> got <\(input.dynamicType.self)>"
|
||||
} catch let error {
|
||||
return "Unknown error occured while matching: \(error)"
|
||||
}
|
||||
}
|
||||
|
||||
public func matches(input: T) -> Bool {
|
||||
do {
|
||||
return try matchesFunction(input)
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public struct FunctionMatcher<T>: Matcher {
|
||||
private let function: T -> Bool
|
||||
private let description: T -> String
|
||||
|
||||
public init(original: T, function: (T, T) -> Bool, description: (T, T) -> String) {
|
||||
self.function = curry(function)(original)
|
||||
self.description = curry(description)(original)
|
||||
}
|
||||
|
||||
public init(function: T -> Bool, description: T -> String) {
|
||||
self.function = function
|
||||
self.description = description
|
||||
}
|
||||
|
||||
public func describe(input: T) -> String {
|
||||
return description(input)
|
||||
}
|
||||
|
||||
public func matches(input: T) -> Bool {
|
||||
return function(input)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
//
|
||||
// Mockery.h
|
||||
// Mockery
|
||||
//
|
||||
// Created by Tadeas Kriz on 13/01/16.
|
||||
// Copyright © 2016 Brightify. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
//! Project version number for Mockery.
|
||||
FOUNDATION_EXPORT double MockeryVersionNumber;
|
||||
|
||||
//! Project version string for Mockery.
|
||||
FOUNDATION_EXPORT const unsigned char MockeryVersionString[];
|
||||
|
||||
// In this header, you should import all the public headers of your framework using statements like #import <Mockery/PublicHeader.h>
|
||||
|
||||
|
|
@ -0,0 +1,104 @@
|
|||
//
|
||||
// Mockery.swift
|
||||
// Mockery
|
||||
//
|
||||
// Created by Tadeas Kriz on 13/01/16.
|
||||
// Copyright © 2016 Brightify. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
enum Mode {
|
||||
case Stubbing
|
||||
case Verification
|
||||
case Default
|
||||
}
|
||||
|
||||
enum ReturnValueOrError {
|
||||
case ReturnValue(Any)
|
||||
case Error(ErrorType)
|
||||
}
|
||||
|
||||
public class MockManager<STUBBING: StubbingProxy, VERIFICATION: VerificationProxy> {
|
||||
public var callOriginalIfNotStubbed: Bool = false
|
||||
|
||||
private var mode: Mode = .Default
|
||||
|
||||
private var stubs: [String: [Stub]] = [:]
|
||||
|
||||
public init() {
|
||||
}
|
||||
|
||||
public func call<OUT>(method: String) -> OUT {
|
||||
return call(method, parameters: Void())
|
||||
}
|
||||
|
||||
public func call<IN, OUT>(method: String, parameters: IN) -> OUT {
|
||||
return try! callThrows(method, parameters: parameters)
|
||||
}
|
||||
|
||||
public func callThrows<OUT>(method: String) throws -> OUT {
|
||||
return try callThrows(method, parameters: Void())
|
||||
}
|
||||
|
||||
public func callThrows<IN, OUT>(method: String, parameters: IN, original: (IN -> OUT)? = nil) throws -> OUT {
|
||||
if let stub = findStub(method, parameters: parameters) {
|
||||
switch stub.call() {
|
||||
case .ReturnValue(let value):
|
||||
return value as! OUT
|
||||
case .Error(let error):
|
||||
throw error
|
||||
}
|
||||
} else {
|
||||
if callOriginalIfNotStubbed == false {
|
||||
fatalError("No stub for method `\(method)` using parameters \(parameters) and forwarding to original is disabled!")
|
||||
}
|
||||
}
|
||||
|
||||
print(method, parameters)
|
||||
fatalError("\(method) -- \(parameters)")
|
||||
}
|
||||
|
||||
private func findStub<IN>(method: String, parameters: IN) -> Stub? {
|
||||
guard let stubsWithSameName = stubs[method] else { return nil }
|
||||
return stubsWithSameName.filter { $0.inputMatcher.matches(parameters) }.first
|
||||
}
|
||||
|
||||
private func createNewStub(stub: Stub) {
|
||||
if !stubs.keys.contains(stub.name) {
|
||||
stubs[stub.name] = []
|
||||
}
|
||||
|
||||
stubs[stub.name]?.insert(stub, atIndex: 0)
|
||||
}
|
||||
|
||||
private func verify<IN>(method: String, parameters: IN, matcher: AnyMatcher<Stub?>) {
|
||||
let foundStub = findStub(method, parameters: parameters)
|
||||
assert(matcher.matches(foundStub), matcher.describe(foundStub))
|
||||
}
|
||||
}
|
||||
|
||||
extension MockManager {
|
||||
|
||||
public func getStubbingProxy() -> STUBBING {
|
||||
return STUBBING(handler: StubbingHandler(createNewStub: createNewStub))
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
extension MockManager {
|
||||
|
||||
public func getVerificationProxy(matcher: AnyMatcher<Stub?>) -> VERIFICATION {
|
||||
return VERIFICATION(handler: VerificationHandler(matcher: matcher, verifyCall: verify))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public protocol Mock {
|
||||
typealias Stubbing: StubbingProxy
|
||||
typealias Verification: VerificationProxy
|
||||
|
||||
var manager: MockManager<Stubbing, Verification> { get }
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
//
|
||||
// Stubbing.swift
|
||||
// Mockery
|
||||
//
|
||||
// Created by Tadeas Kriz on 13/01/16.
|
||||
// Copyright © 2016 Brightify. All rights reserved.
|
||||
//
|
||||
|
||||
public protocol StubbingProxy {
|
||||
init(handler: StubbingHandler)
|
||||
}
|
||||
|
||||
public class Stub {
|
||||
let name: String
|
||||
let inputMatcher: AnyMatcher<Any>
|
||||
let output: () -> ReturnValueOrError
|
||||
|
||||
var calledTimes: Int = 0
|
||||
|
||||
init(name: String, inputMatcher: AnyMatcher<Any>, output: () -> ReturnValueOrError) {
|
||||
self.name = name
|
||||
self.inputMatcher = inputMatcher
|
||||
self.output = output
|
||||
}
|
||||
|
||||
func call() -> ReturnValueOrError {
|
||||
calledTimes += 1
|
||||
|
||||
return output()
|
||||
}
|
||||
}
|
||||
|
||||
public struct ToBeStubbedFunction<IN, OUT> {
|
||||
let handler: StubbingHandler
|
||||
|
||||
let name: String
|
||||
let parameters: IN
|
||||
|
||||
func setInputMatcher(matcher: AnyMatcher<IN>, @autoclosure(escaping) andOutput output: Void -> ReturnValueOrError) {
|
||||
handler.createStubReturningValue(name, inputMatcher: matcher, output: output)
|
||||
}
|
||||
}
|
||||
|
||||
public struct ToBeStubbedThrowingFunction<IN, OUT> {
|
||||
let handler: StubbingHandler
|
||||
|
||||
let name: String
|
||||
let parameters: IN
|
||||
|
||||
func setInputMatcher(matcher: AnyMatcher<IN>, @autoclosure(escaping) andOutput output: Void -> ReturnValueOrError) {
|
||||
handler.createStubReturningValue(name, inputMatcher: matcher, output: output)
|
||||
}
|
||||
}
|
||||
|
||||
public struct StubbingHandler {
|
||||
let createNewStub: Stub -> ()
|
||||
|
||||
public func stub<IN, OUT>(method: String, parameters: IN) -> ToBeStubbedFunction<IN, OUT> {
|
||||
return ToBeStubbedFunction(handler: self, name: method, parameters: parameters)
|
||||
}
|
||||
|
||||
public func stubThrowing<IN, OUT>(method: String, parameters: IN) -> ToBeStubbedThrowingFunction<IN, OUT> {
|
||||
return ToBeStubbedThrowingFunction(handler: self, name: method, parameters: parameters)
|
||||
}
|
||||
|
||||
private func createStubReturningValue<IN>(method: String, inputMatcher: AnyMatcher<IN>, output: Void -> ReturnValueOrError) {
|
||||
let stub = Stub(name: method, inputMatcher: AnyMatcher(inputMatcher), output: output)
|
||||
|
||||
self.createNewStub(stub)
|
||||
}
|
||||
|
||||
private func inputEqualWith<IN>(input: IN, equalWhen: (IN, IN) -> Bool)(otherInput: Any) -> Bool {
|
||||
guard let castOtherInput = otherInput as? IN else { return false }
|
||||
|
||||
return equalWhen(input, castOtherInput)
|
||||
}
|
||||
}
|
||||
|
||||
public struct ThenReturnValue<IN, OUT> {
|
||||
public let thenReturn: OUT -> ()
|
||||
}
|
||||
|
||||
public struct ThenReturnValueOrThrow<IN, OUT> {
|
||||
public let thenReturn: OUT -> ()
|
||||
|
||||
public let thenThrow: ErrorType -> ()
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
//
|
||||
// StubbingFunctions.swift
|
||||
// Mockery
|
||||
//
|
||||
// Created by Tadeas Kriz on 13/01/16.
|
||||
// Copyright © 2016 Brightify. All rights reserved.
|
||||
//
|
||||
|
||||
public func stub<M: Mock>(mock: M, @noescape block: M.Stubbing -> Void) {
|
||||
block(mock.manager.getStubbingProxy())
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func when<OUT>(stub: ToBeStubbedFunction<Void, OUT>) -> ThenReturnValue<Void, OUT> {
|
||||
return when(stub, equalWhen: { _ in true })
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func when<IN: Equatable, OUT>(stub: ToBeStubbedFunction<IN, OUT>) -> ThenReturnValue<IN, OUT> {
|
||||
return when(stub, equalWhen: ==)
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func when<IN: AnyObject, OUT>(stub: ToBeStubbedFunction<IN, OUT>) -> ThenReturnValue<IN, OUT> {
|
||||
return when(stub, equalWhen: ===)
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func when<IN, OUT>(stub: ToBeStubbedFunction<IN, OUT>, equalWhen equalityFunction: (IN, IN) -> Bool) -> ThenReturnValue<IN, OUT> {
|
||||
let matcher = equalTo(stub.parameters, equalWhen: equalityFunction)
|
||||
return ThenReturnValue(thenReturn: { stub.setInputMatcher(matcher, andOutput: .ReturnValue($0)) })
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func when<OUT>(stub: ToBeStubbedThrowingFunction<Void, OUT>) -> ThenReturnValueOrThrow<Void, OUT> {
|
||||
return when(stub, equalWhen: { _ in true })
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func when<IN: Equatable, OUT>(stub: ToBeStubbedThrowingFunction<IN, OUT>) -> ThenReturnValueOrThrow<IN, OUT> {
|
||||
return when(stub, equalWhen: ==)
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func when<IN: AnyObject, OUT>(stub: ToBeStubbedThrowingFunction<IN, OUT>) -> ThenReturnValueOrThrow<IN, OUT> {
|
||||
return when(stub, equalWhen: ===)
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func when<IN, OUT>(stub: ToBeStubbedThrowingFunction<IN, OUT>, equalWhen equalityFunction: (IN, IN) -> Bool) -> ThenReturnValueOrThrow<IN, OUT> {
|
||||
let matcher = equalTo(stub.parameters, equalWhen: equalityFunction)
|
||||
return ThenReturnValueOrThrow(
|
||||
thenReturn: { stub.setInputMatcher(matcher, andOutput: .ReturnValue($0)) },
|
||||
thenThrow: { stub.setInputMatcher(matcher, andOutput: .Error($0)) })
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
//
|
||||
// Utils.swift
|
||||
// Mockery
|
||||
//
|
||||
// Created by Tadeas Kriz on 13/01/16.
|
||||
// Copyright © 2016 Brightify. All rights reserved.
|
||||
//
|
||||
|
||||
internal func curry<A>(function: A -> ())(_ a: A)() {
|
||||
function(a)
|
||||
}
|
||||
|
||||
internal func curry<A, B>(function: A -> B)(_ a: A) -> B {
|
||||
return function(a)
|
||||
}
|
||||
|
||||
internal func curry<A, B, C>(function: (A, B) -> C)(_ a: A)(_ b: B) -> C {
|
||||
return function(a, b)
|
||||
}
|
||||
|
||||
internal func curry<A, B, C, D>(function: (A, B, C) -> D)(_ a: A)(_ b: B)(_ c: C) -> D {
|
||||
return function(a, b, c)
|
||||
}
|
||||
|
||||
internal func curry<A, B, C, D, E>(function: (A, B, C, D) -> E)(_ a: A)(_ b: B)(_ c: C)(_ d: D) -> E {
|
||||
return function(a, b, c, d)
|
||||
}
|
||||
|
||||
internal func curry<A, B, C, D, E, F>(function: (A, B, C, D, E) -> F)(_ a: A)(_ b: B)(_ c: C)(_ d: D)(_ e: E) -> F {
|
||||
return function(a, b, c, d, e)
|
||||
}
|
||||
|
||||
enum TypeStripingError: ErrorType {
|
||||
case CalledWithIncorrectType
|
||||
}
|
||||
|
||||
internal func stripInputTypeInformation<IN, OUT>(function: IN -> OUT)(_ input: Any) throws -> OUT {
|
||||
return try stripInputTypeInformation(IN.self, from: function)(input)
|
||||
}
|
||||
|
||||
internal func stripInputTypeInformation<IN, OUT>(inputType: IN.Type, from function: IN -> OUT)(_ input: Any) throws -> OUT {
|
||||
guard let castInput = input as? IN else {
|
||||
throw TypeStripingError.CalledWithIncorrectType
|
||||
}
|
||||
return function(castInput)
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
//
|
||||
// Verification.swift
|
||||
// Mockery
|
||||
//
|
||||
// Created by Tadeas Kriz on 13/01/16.
|
||||
// Copyright © 2016 Brightify. All rights reserved.
|
||||
//
|
||||
|
||||
public protocol VerificationProxy {
|
||||
init(handler: VerificationHandler)
|
||||
}
|
||||
|
||||
public struct VerificationHandler {
|
||||
let matcher: AnyMatcher<Stub?>
|
||||
let verifyCall: (method: String, parameters: Any, matcher: AnyMatcher<Stub?>) -> ()
|
||||
|
||||
public func verify(method: String) {
|
||||
return verify(method, parameters: Void())
|
||||
}
|
||||
|
||||
public func verify<IN>(method: String, parameters: IN) {
|
||||
verifyCall(method: method, parameters: parameters, matcher: matcher)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
//
|
||||
// VerificationFunctions.swift
|
||||
// Mockery
|
||||
//
|
||||
// Created by Tadeas Kriz on 13/01/16.
|
||||
// Copyright © 2016 Brightify. All rights reserved.
|
||||
//
|
||||
|
||||
@warn_unused_result
|
||||
public func verify<M: Mock>(mock: M) -> M.Verification {
|
||||
return verify(mock, times(1))
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func verify<M: Mock>(mock: M, _ matcher: AnyMatcher<Stub?>) -> M.Verification {
|
||||
return mock.manager.getVerificationProxy(matcher)
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>$(PRODUCT_NAME)</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>BNDL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
</dict>
|
||||
</plist>
|
|
@ -0,0 +1,145 @@
|
|||
//
|
||||
// MockeryTests.swift
|
||||
// MockeryTests
|
||||
//
|
||||
// Created by Tadeas Kriz on 13/01/16.
|
||||
// Copyright © 2016 Brightify. All rights reserved.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
import Mockery
|
||||
|
||||
class MockeryAPITest: XCTestCase {
|
||||
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
// Put setup code here. This method is called before the invocation of each test method in the class.
|
||||
}
|
||||
|
||||
override func tearDown() {
|
||||
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
||||
super.tearDown()
|
||||
}
|
||||
|
||||
func testExample() {
|
||||
|
||||
enum TestError: ErrorType {
|
||||
case Unknown
|
||||
}
|
||||
|
||||
let mock = Mock_Something()
|
||||
|
||||
// FIXME Should be fatalError when method was not throwing
|
||||
|
||||
stub(mock) { mock in
|
||||
when(mock.noParameter()).thenReturn()
|
||||
when(mock.countCharacters("hello")).thenReturn(1000)
|
||||
when(mock.withReturn()).thenReturn("hello world!")
|
||||
// when(mock.withThrows()).thenThrow(TestError.Unknown)
|
||||
}
|
||||
|
||||
mock.noParameter()
|
||||
|
||||
XCTAssertEqual(mock.countCharacters("hello"), 1000)
|
||||
|
||||
XCTAssertEqual(mock.withReturn(), "hello world!")
|
||||
|
||||
verify(mock).noParameter()
|
||||
|
||||
verify(mock).countCharacters("hello")
|
||||
|
||||
verify(mock).withReturn()
|
||||
|
||||
verify(mock, never()).withThrows()
|
||||
|
||||
// This is an example of a functional test case.
|
||||
// Use XCTAssert and related functions to verify your tests produce the correct results.
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Source
|
||||
protocol Something {
|
||||
func noParameter()
|
||||
|
||||
func countCharacters(test: String) -> Int
|
||||
|
||||
func withReturn() -> String
|
||||
|
||||
func withThrows() throws
|
||||
}
|
||||
|
||||
// MARK: - Begin of generated
|
||||
struct Mock_Something: Something, Mock {
|
||||
let manager: MockManager<StubbingProxyImpl, VerificationProxyImpl> = .init()
|
||||
|
||||
func noParameter() {
|
||||
return manager.call("noParameter()")
|
||||
}
|
||||
|
||||
func countCharacters(test: String) -> Int {
|
||||
return manager.call("countCharacters(String)", parameters: test)
|
||||
}
|
||||
|
||||
func withReturn() -> String {
|
||||
return manager.call("withReturn()")
|
||||
}
|
||||
|
||||
func withThrows() throws {
|
||||
return try manager.callThrows("withThrows()")
|
||||
}
|
||||
|
||||
struct StubbingProxyImpl: StubbingProxy {
|
||||
let handler: StubbingHandler
|
||||
|
||||
init(handler: StubbingHandler) {
|
||||
self.handler = handler
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
func noParameter() -> ToBeStubbedFunction<Void, Void> {
|
||||
return handler.stub("noParameter()", parameters: ())
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
func countCharacters(test: String) -> ToBeStubbedFunction<String, Int> {
|
||||
return handler.stub("countCharacters(String)", parameters: test)
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
func withReturn() -> ToBeStubbedFunction<Void, String> {
|
||||
return handler.stub("withReturn()", parameters: ())
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
func withThrows() -> ToBeStubbedThrowingFunction<Void, Void> {
|
||||
return handler.stubThrowing("withThrows()", parameters: ())
|
||||
}
|
||||
}
|
||||
|
||||
struct VerificationProxyImpl: VerificationProxy {
|
||||
let handler: VerificationHandler
|
||||
|
||||
init(handler: VerificationHandler) {
|
||||
self.handler = handler
|
||||
}
|
||||
|
||||
func noParameter() {
|
||||
return handler.verify("noParameter()", parameters: ())
|
||||
}
|
||||
|
||||
func countCharacters(test: String) {
|
||||
return handler.verify("countCharacters(String)", parameters: test)
|
||||
}
|
||||
|
||||
func withReturn() {
|
||||
return handler.verify("withReturn()", parameters: ())
|
||||
}
|
||||
|
||||
func withThrows() {
|
||||
return handler.verify("withThrows()", parameters: ())
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue