From 9640d7ac952af8d580a53ca2981e755a74d4caf8 Mon Sep 17 00:00:00 2001 From: Bjarne Mogstad Date: Sun, 4 Oct 2015 18:09:15 +0200 Subject: [PATCH] Setup project and import proof of concept codebase --- .gitignore | 17 +- Bankside.podspec | 18 + Bankside.xcodeproj/project.pbxproj | 571 ++++++++++++++++++ .../contents.xcworkspacedata | 7 + .../xcshareddata/xcschemes/Mac.xcscheme | 80 +++ .../xcshareddata/xcschemes/iOS.xcscheme | 99 +++ Cartfile.private | 2 + Cartfile.resolved | 2 + LICENSE | 1 - README.md | 94 ++- circle.yml | 11 + scripts/dependencies.sh | 6 + scripts/test.sh | 3 + sources/factory.swift | 129 ++++ supporting_files/Bankside.h | 4 + supporting_files/ios/info.plist | 26 + supporting_files/mac/info.plist | 28 + supporting_files/tests/info.plist | 24 + tests/factory_spec.swift | 135 +++++ 19 files changed, 1240 insertions(+), 17 deletions(-) create mode 100644 Bankside.podspec create mode 100644 Bankside.xcodeproj/project.pbxproj create mode 100644 Bankside.xcodeproj/project.xcworkspace/contents.xcworkspacedata create mode 100644 Bankside.xcodeproj/xcshareddata/xcschemes/Mac.xcscheme create mode 100644 Bankside.xcodeproj/xcshareddata/xcschemes/iOS.xcscheme create mode 100644 Cartfile.private create mode 100644 Cartfile.resolved create mode 100644 circle.yml create mode 100755 scripts/dependencies.sh create mode 100755 scripts/test.sh create mode 100644 sources/factory.swift create mode 100644 supporting_files/Bankside.h create mode 100644 supporting_files/ios/info.plist create mode 100644 supporting_files/mac/info.plist create mode 100644 supporting_files/tests/info.plist create mode 100644 tests/factory_spec.swift diff --git a/.gitignore b/.gitignore index 8615121..95be3a7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,3 @@ -# Xcode -# build/ *.pbxuser !default.pbxuser @@ -17,17 +15,6 @@ DerivedData *.ipa *.xcuserstate -# CocoaPods -# -# We recommend against adding the Pods directory to your .gitignore. However -# you should judge for yourself, the pros and cons are mentioned at: -# http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control -# -# Pods/ - -# Carthage -# -# Add this line if you want to avoid checking in source code from Carthage dependencies. -# Carthage/Checkouts - +Pods/ +Carthage/Checkouts Carthage/Build diff --git a/Bankside.podspec b/Bankside.podspec new file mode 100644 index 0000000..e0709b8 --- /dev/null +++ b/Bankside.podspec @@ -0,0 +1,18 @@ +Pod::Spec.new do |spec| + spec.name = "Bankside" + spec.version = "0.1.0" + spec.license = "MIT" + spec.summary = "Simple fixture generation tool for your tests" + spec.homepage = "https://github.com/mogstad/Bankside" + spec.authors = { "Bjarne Mogstad" => "me@mogstad.co" } + spec.source = { + :git => "https://github.com/Bankside/Bankside.git", + :tag => spec.version + } + spec.ios.deployment_target = "8.0" + spec.osx.deployment_target = "10.10" + + spec.source_files = "sources/*.swift" + + spec.requires_arc = true +end diff --git a/Bankside.xcodeproj/project.pbxproj b/Bankside.xcodeproj/project.pbxproj new file mode 100644 index 0000000..0dbcfab --- /dev/null +++ b/Bankside.xcodeproj/project.pbxproj @@ -0,0 +1,571 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 2D1161471BC18BFD009DB0E6 /* factory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2DB43A3D1BBDB97F001BCF97 /* factory.swift */; }; + 2D1161481BC18C03009DB0E6 /* Bankside.h in Headers */ = {isa = PBXBuildFile; fileRef = 2DB43A241BBDB95A001BCF97 /* Bankside.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 2DAC04CD1BBDC69F003EC55A /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2DAC04C81BBDC664003EC55A /* Nimble.framework */; }; + 2DAC04CE1BBDC69F003EC55A /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2DAC04C91BBDC664003EC55A /* Quick.framework */; }; + 2DAC04D11BBDC7B4003EC55A /* Nimble.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = 2DAC04C81BBDC664003EC55A /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 2DAC04D21BBDC7B4003EC55A /* Quick.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = 2DAC04C91BBDC664003EC55A /* Quick.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 2DAC04D41BBDCC95003EC55A /* factory_spec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2DAC04D31BBDCC95003EC55A /* factory_spec.swift */; settings = {ASSET_TAGS = (); }; }; + 2DB43A251BBDB95A001BCF97 /* Bankside.h in Headers */ = {isa = PBXBuildFile; fileRef = 2DB43A241BBDB95A001BCF97 /* Bankside.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 2DB43A2C1BBDB95A001BCF97 /* Bankside.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2DB43A211BBDB95A001BCF97 /* Bankside.framework */; settings = {ASSET_TAGS = (); }; }; + 2DB43A3E1BBDB97F001BCF97 /* factory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2DB43A3D1BBDB97F001BCF97 /* factory.swift */; settings = {ASSET_TAGS = (); }; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + 2DB43A2D1BBDB95A001BCF97 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 2DB43A181BBDB95A001BCF97 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 2DB43A201BBDB95A001BCF97; + remoteInfo = Bankside; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 2DAC04D01BBDC7AC003EC55A /* Copy Frameworks */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + 2DAC04D11BBDC7B4003EC55A /* Nimble.framework in Copy Frameworks */, + 2DAC04D21BBDC7B4003EC55A /* Quick.framework in Copy Frameworks */, + ); + name = "Copy Frameworks"; + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 2D11613F1BC18B92009DB0E6 /* Bankside.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Bankside.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 2D1161431BC18B92009DB0E6 /* info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = info.plist; sourceTree = ""; }; + 2DAC04C81BBDC664003EC55A /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Nimble.framework; path = Carthage/Build/iOS/Nimble.framework; sourceTree = ""; }; + 2DAC04C91BBDC664003EC55A /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Quick.framework; path = Carthage/Build/iOS/Quick.framework; sourceTree = ""; }; + 2DAC04D31BBDCC95003EC55A /* factory_spec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = factory_spec.swift; sourceTree = ""; }; + 2DB43A211BBDB95A001BCF97 /* Bankside.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Bankside.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 2DB43A241BBDB95A001BCF97 /* Bankside.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Bankside.h; sourceTree = ""; }; + 2DB43A261BBDB95A001BCF97 /* info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = info.plist; sourceTree = ""; }; + 2DB43A2B1BBDB95A001BCF97 /* BanksideTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = BanksideTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 2DB43A321BBDB95A001BCF97 /* info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = info.plist; sourceTree = ""; }; + 2DB43A3D1BBDB97F001BCF97 /* factory.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = factory.swift; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 2DB43A281BBDB95A001BCF97 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 2DB43A2C1BBDB95A001BCF97 /* Bankside.framework in Frameworks */, + 2DAC04CD1BBDC69F003EC55A /* Nimble.framework in Frameworks */, + 2DAC04CE1BBDC69F003EC55A /* Quick.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 2D1161331BC18912009DB0E6 /* Supporting files */ = { + isa = PBXGroup; + children = ( + 2DB43A241BBDB95A001BCF97 /* Bankside.h */, + 2D1161381BC1894F009DB0E6 /* Mac */, + 2D1161371BC1894A009DB0E6 /* iOS */, + 2D1161361BC18943009DB0E6 /* Tests */, + ); + name = "Supporting files"; + path = supporting_files; + sourceTree = ""; + }; + 2D1161341BC18920009DB0E6 /* Sources */ = { + isa = PBXGroup; + children = ( + 2DB43A3D1BBDB97F001BCF97 /* factory.swift */, + ); + name = Sources; + path = sources; + sourceTree = ""; + }; + 2D1161351BC18935009DB0E6 /* Tests */ = { + isa = PBXGroup; + children = ( + 2DAC04D31BBDCC95003EC55A /* factory_spec.swift */, + ); + name = Tests; + path = tests; + sourceTree = ""; + }; + 2D1161361BC18943009DB0E6 /* Tests */ = { + isa = PBXGroup; + children = ( + 2DB43A321BBDB95A001BCF97 /* info.plist */, + ); + name = Tests; + path = tests; + sourceTree = ""; + }; + 2D1161371BC1894A009DB0E6 /* iOS */ = { + isa = PBXGroup; + children = ( + 2DB43A261BBDB95A001BCF97 /* info.plist */, + ); + name = iOS; + path = ios; + sourceTree = ""; + }; + 2D1161381BC1894F009DB0E6 /* Mac */ = { + isa = PBXGroup; + children = ( + 2D1161431BC18B92009DB0E6 /* info.plist */, + ); + name = Mac; + path = mac; + sourceTree = ""; + }; + 2DB43A171BBDB95A001BCF97 = { + isa = PBXGroup; + children = ( + 2D1161341BC18920009DB0E6 /* Sources */, + 2D1161351BC18935009DB0E6 /* Tests */, + 2D1161331BC18912009DB0E6 /* Supporting files */, + 2DB43A3F1BBDC1EE001BCF97 /* Vendor */, + 2DB43A221BBDB95A001BCF97 /* Products */, + ); + sourceTree = ""; + }; + 2DB43A221BBDB95A001BCF97 /* Products */ = { + isa = PBXGroup; + children = ( + 2DB43A211BBDB95A001BCF97 /* Bankside.framework */, + 2DB43A2B1BBDB95A001BCF97 /* BanksideTests.xctest */, + 2D11613F1BC18B92009DB0E6 /* Bankside.framework */, + ); + name = Products; + sourceTree = ""; + }; + 2DB43A3F1BBDC1EE001BCF97 /* Vendor */ = { + isa = PBXGroup; + children = ( + 2DAC04C81BBDC664003EC55A /* Nimble.framework */, + 2DAC04C91BBDC664003EC55A /* Quick.framework */, + ); + name = Vendor; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXHeadersBuildPhase section */ + 2D11613C1BC18B92009DB0E6 /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + 2D1161481BC18C03009DB0E6 /* Bankside.h in Headers */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 2DB43A1E1BBDB95A001BCF97 /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + 2DB43A251BBDB95A001BCF97 /* Bankside.h in Headers */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXHeadersBuildPhase section */ + +/* Begin PBXNativeTarget section */ + 2D11613E1BC18B92009DB0E6 /* Bankside-Mac */ = { + isa = PBXNativeTarget; + buildConfigurationList = 2D1161441BC18B92009DB0E6 /* Build configuration list for PBXNativeTarget "Bankside-Mac" */; + buildPhases = ( + 2D11613A1BC18B92009DB0E6 /* Sources */, + 2D11613C1BC18B92009DB0E6 /* Headers */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = "Bankside-Mac"; + productName = "Bankside-Mac"; + productReference = 2D11613F1BC18B92009DB0E6 /* Bankside.framework */; + productType = "com.apple.product-type.framework"; + }; + 2DB43A201BBDB95A001BCF97 /* Bankside-iOS */ = { + isa = PBXNativeTarget; + buildConfigurationList = 2DB43A351BBDB95A001BCF97 /* Build configuration list for PBXNativeTarget "Bankside-iOS" */; + buildPhases = ( + 2DB43A1C1BBDB95A001BCF97 /* Sources */, + 2DB43A1E1BBDB95A001BCF97 /* Headers */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = "Bankside-iOS"; + productName = Bankside; + productReference = 2DB43A211BBDB95A001BCF97 /* Bankside.framework */; + productType = "com.apple.product-type.framework"; + }; + 2DB43A2A1BBDB95A001BCF97 /* BanksideTests */ = { + isa = PBXNativeTarget; + buildConfigurationList = 2DB43A381BBDB95A001BCF97 /* Build configuration list for PBXNativeTarget "BanksideTests" */; + buildPhases = ( + 2DB43A271BBDB95A001BCF97 /* Sources */, + 2DB43A281BBDB95A001BCF97 /* Frameworks */, + 2DB43A291BBDB95A001BCF97 /* Resources */, + 2DAC04D01BBDC7AC003EC55A /* Copy Frameworks */, + ); + buildRules = ( + ); + dependencies = ( + 2DB43A2E1BBDB95A001BCF97 /* PBXTargetDependency */, + ); + name = BanksideTests; + productName = BanksideTests; + productReference = 2DB43A2B1BBDB95A001BCF97 /* BanksideTests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 2DB43A181BBDB95A001BCF97 /* Project object */ = { + isa = PBXProject; + attributes = { + LastSwiftUpdateCheck = 0700; + LastUpgradeCheck = 0700; + ORGANIZATIONNAME = Flow; + TargetAttributes = { + 2D11613E1BC18B92009DB0E6 = { + CreatedOnToolsVersion = 7.0.1; + }; + 2DB43A201BBDB95A001BCF97 = { + CreatedOnToolsVersion = 7.0.1; + }; + 2DB43A2A1BBDB95A001BCF97 = { + CreatedOnToolsVersion = 7.0.1; + }; + }; + }; + buildConfigurationList = 2DB43A1B1BBDB95A001BCF97 /* Build configuration list for PBXProject "Bankside" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = 2DB43A171BBDB95A001BCF97; + productRefGroup = 2DB43A221BBDB95A001BCF97 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 2DB43A201BBDB95A001BCF97 /* Bankside-iOS */, + 2D11613E1BC18B92009DB0E6 /* Bankside-Mac */, + 2DB43A2A1BBDB95A001BCF97 /* BanksideTests */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 2DB43A291BBDB95A001BCF97 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 2D11613A1BC18B92009DB0E6 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 2D1161471BC18BFD009DB0E6 /* factory.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 2DB43A1C1BBDB95A001BCF97 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 2DB43A3E1BBDB97F001BCF97 /* factory.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 2DB43A271BBDB95A001BCF97 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 2DAC04D41BBDCC95003EC55A /* factory_spec.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + 2DB43A2E1BBDB95A001BCF97 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 2DB43A201BBDB95A001BCF97 /* Bankside-iOS */; + targetProxy = 2DB43A2D1BBDB95A001BCF97 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin XCBuildConfiguration section */ + 2D1161451BC18B92009DB0E6 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + COMBINE_HIDPI_IMAGES = YES; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + FRAMEWORK_VERSION = A; + INFOPLIST_FILE = supporting_files/mac/info.plist; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 10.10; + PRODUCT_BUNDLE_IDENTIFIER = com.getflow.bankside; + PRODUCT_NAME = Bankside; + SDKROOT = macosx; + SKIP_INSTALL = YES; + }; + name = Debug; + }; + 2D1161461BC18B92009DB0E6 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + COMBINE_HIDPI_IMAGES = YES; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + FRAMEWORK_VERSION = A; + INFOPLIST_FILE = supporting_files/mac/info.plist; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 10.10; + PRODUCT_BUNDLE_IDENTIFIER = com.getflow.bankside; + PRODUCT_NAME = Bankside; + SDKROOT = macosx; + SKIP_INSTALL = YES; + }; + name = Release; + }; + 2DB43A331BBDB95A001BCF97 /* 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 = 8.0; + MACOSX_DEPLOYMENT_TARGET = 10.10; + 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; + }; + 2DB43A341BBDB95A001BCF97 /* 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 = 8.0; + MACOSX_DEPLOYMENT_TARGET = 10.10; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + VALIDATE_PRODUCT = YES; + VERSIONING_SYSTEM = "apple-generic"; + VERSION_INFO_PREFIX = ""; + }; + name = Release; + }; + 2DB43A361BBDB95A001BCF97 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CLANG_ENABLE_MODULES = YES; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + ENABLE_BITCODE = YES; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Carthage/Build/iOS", + ); + INFOPLIST_FILE = "$(SRCROOT)/supporting_files/ios/info.plist"; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = com.getflow.bankside; + PRODUCT_NAME = Bankside; + SKIP_INSTALL = YES; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + WATCHOS_DEPLOYMENT_TARGET = 2.0; + }; + name = Debug; + }; + 2DB43A371BBDB95A001BCF97 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CLANG_ENABLE_MODULES = YES; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + ENABLE_BITCODE = YES; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Carthage/Build/iOS", + ); + INFOPLIST_FILE = "$(SRCROOT)/supporting_files/ios/info.plist"; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = com.getflow.bankside; + PRODUCT_NAME = Bankside; + SKIP_INSTALL = YES; + WATCHOS_DEPLOYMENT_TARGET = 2.0; + }; + name = Release; + }; + 2DB43A391BBDB95A001BCF97 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Carthage/Build/iOS", + ); + INFOPLIST_FILE = "$(SRCROOT)/supporting_files/tests/info.plist"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = com.getflow.BanksideTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + 2DB43A3A1BBDB95A001BCF97 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Carthage/Build/iOS", + ); + INFOPLIST_FILE = "$(SRCROOT)/supporting_files/tests/info.plist"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = com.getflow.BanksideTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 2D1161441BC18B92009DB0E6 /* Build configuration list for PBXNativeTarget "Bankside-Mac" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 2D1161451BC18B92009DB0E6 /* Debug */, + 2D1161461BC18B92009DB0E6 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 2DB43A1B1BBDB95A001BCF97 /* Build configuration list for PBXProject "Bankside" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 2DB43A331BBDB95A001BCF97 /* Debug */, + 2DB43A341BBDB95A001BCF97 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 2DB43A351BBDB95A001BCF97 /* Build configuration list for PBXNativeTarget "Bankside-iOS" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 2DB43A361BBDB95A001BCF97 /* Debug */, + 2DB43A371BBDB95A001BCF97 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 2DB43A381BBDB95A001BCF97 /* Build configuration list for PBXNativeTarget "BanksideTests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 2DB43A391BBDB95A001BCF97 /* Debug */, + 2DB43A3A1BBDB95A001BCF97 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 2DB43A181BBDB95A001BCF97 /* Project object */; +} diff --git a/Bankside.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/Bankside.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..81e5cb6 --- /dev/null +++ b/Bankside.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/Bankside.xcodeproj/xcshareddata/xcschemes/Mac.xcscheme b/Bankside.xcodeproj/xcshareddata/xcschemes/Mac.xcscheme new file mode 100644 index 0000000..0ea30ed --- /dev/null +++ b/Bankside.xcodeproj/xcshareddata/xcschemes/Mac.xcscheme @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Bankside.xcodeproj/xcshareddata/xcschemes/iOS.xcscheme b/Bankside.xcodeproj/xcshareddata/xcschemes/iOS.xcscheme new file mode 100644 index 0000000..63568c2 --- /dev/null +++ b/Bankside.xcodeproj/xcshareddata/xcschemes/iOS.xcscheme @@ -0,0 +1,99 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Cartfile.private b/Cartfile.private new file mode 100644 index 0000000..5fc4e82 --- /dev/null +++ b/Cartfile.private @@ -0,0 +1,2 @@ +github "quick/quick" +github "quick/nimble" diff --git a/Cartfile.resolved b/Cartfile.resolved new file mode 100644 index 0000000..175f3bd --- /dev/null +++ b/Cartfile.resolved @@ -0,0 +1,2 @@ +github "quick/nimble" "v2.0.0-rc.3" +github "quick/quick" "v0.6.0" diff --git a/LICENSE b/LICENSE index 4adc475..d06b270 100644 --- a/LICENSE +++ b/LICENSE @@ -19,4 +19,3 @@ 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. - diff --git a/README.md b/README.md index 92b389e..782b594 100644 --- a/README.md +++ b/README.md @@ -1 +1,93 @@ -# bankside +# Bankside + +Bankside is a fixture generation tool. It’s useful for defining fixtures for tests. Inspired by [factory_girl](https://github.com/thoughtbot/factory_girl) and [Rosie.js](https://github.com/rosiejs/rosie) + +## Usage + +Bankside provides an easy API for defining default attributes and options that allows you to change how you generate the data. + +### Defining a factory + +```swift +struct Account { + let id: Int + let name: String + init(payload: [String: Any]) { + self.id = payload["id"] as! Int + self.name = payload["name"] as! String + } +} +``` + +```swift +import Bankside + +let AccountFactory = Factory({ Account(payload: $0) }) + .sequence("id") + .attr("name", "Walter White") +``` + +### Using a factory + +```swift +let walter = AccountFactory.build() +let gustavo = AccountFactory.build(attributes: [ + "name": "Gustavo Fridge" +]) +``` + +### Extentions + +To keep your fixtures DRY it’s useful to extend the Factory class and add common or complex default attributes. Remember to return `self` to keep the API chainable. + +```swift +extension Factory { + + func timestamp() -> Self { + func date(options: [String: Any]) { + return NSDate() + } + self.attr("created_at", closure: date) + self.attr("updated_at", closure: date) + return self + } + +} +``` + +In use: + +```swift +let AccountFactory = Factory({ Account(payload: $0) }) + .sequence("id") + .attr("name", "Walter White") + .timestamps() +``` + +### Limitations + +We don’t try to detect circular dependencies, you will just get a stack overflow if it happens. + +## Install + +Requirements: +- Bankside will be compatible with the lastest public release of Swift. Older releases will be available, but bug fixes won’t be issued. +- A data structure that accepts a reflected data structure to populate its models. + +### [Carthage](https://github.com/carthage/carthage) + +1. Add `github "mogstad/bankside" ~> 0.1.0` to “Cartfile.private” +2. Run `carthage update` +3. Link Bankside with your test target +4. Create a new “Copy files” build phases, set ”Destination” to ”Frameworks”, add Bankside + +### [CocoaPods](https://cocoapods.org) + +Update your podfile: + +1. Add `use_frameworks!` to your pod file[^1] +2. Add `pod "Bankside", "~> 0.1.0"` to your testing target +3. Update your dependencies by running `pod install` + +[^1]: +Swift can’t be included as a static library, therefor it’s required to add `use_frameworks!` to your `podfile`. It will then import your dependeices as dynamic frameworks. diff --git a/circle.yml b/circle.yml new file mode 100644 index 0000000..f6bb039 --- /dev/null +++ b/circle.yml @@ -0,0 +1,11 @@ +machine: + xcode: + version: "7.0" + +dependencies: + override: + - ./scripts/dependencies.sh + +test: + override: + - ./scripts/test.sh diff --git a/scripts/dependencies.sh b/scripts/dependencies.sh new file mode 100755 index 0000000..7f143ef --- /dev/null +++ b/scripts/dependencies.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +curl -O -L https://github.com/Carthage/Carthage/releases/download/0.9.2/Carthage.pkg +sudo installer -pkg Carthage.pkg -target / + +carthage bootstrap --use-ssh --platform ios diff --git a/scripts/test.sh b/scripts/test.sh new file mode 100755 index 0000000..2a17c08 --- /dev/null +++ b/scripts/test.sh @@ -0,0 +1,3 @@ +#!/bin/sh +set -ev +xcodebuild test -project Bankside.xcodeproj -scheme iOS -sdk iphonesimulator -destination platform='iOS Simulator',OS=9.0,name='iPhone 5s' diff --git a/sources/factory.swift b/sources/factory.swift new file mode 100644 index 0000000..d15c26a --- /dev/null +++ b/sources/factory.swift @@ -0,0 +1,129 @@ +import Foundation + +public class Factory { + + public typealias CreateClosure = (attributes: [String: Any]) -> T + public typealias AttributeClosure = (options: [String: Any]) -> Any + public typealias OptionClosure = () -> Any + public typealias AfterClosure = (item: T, options: [String: Any]) -> Void + public typealias SequenceClosure = (Int) -> Any + + let create: CreateClosure + var sequence: Int = 1 + var attributes: [String: AttributeClosure] = [:] + var options: [String: OptionClosure] = [:] + var after: [AfterClosure] = [] + + public init(_ create: CreateClosure) { + self.create = create + } + + /// Defines an attribute that has a random UUID String assign to it. + /// + /// - parameter key: the key to set a UUIDv5 + /// - returns: It self + public func uuid(key: String) -> Self { + self.attr(key) { _ in + return NSUUID().UUIDString + } + return self + } + + /// Defines an attribute that will auto-increment every time it gets + /// generated, useful for identifiers you want to be unique. The sequence + /// will be unique per factory. + /// + /// Supports an optional closure, if provided, the closure’s result will be + /// used as the attribute value. The sequence value, will be passed in as the + /// first argument. Useful if you want predictable unique string values. + /// + /// - parameter key: attribute name + /// - parameter closure: optional closure, its result will be used as the + /// attribute value + /// - returns: It self + public func sequence(key: String, closure: SequenceClosure? = nil) -> Self { + self.attr(key) { _ in + let sequence = self.sequence + self.sequence += 1 + if let closure = closure { + return closure(sequence) + } + return sequence + } + return self + } + + /// Defines an attribute + /// + /// - parameter key: attribute name + /// - parameter value: attribute value + /// - returns: It self + public func attr(key: String, value: Any) -> Self { + self.attributes[key] = { _ in value } + return self + } + + /// Defines an attribute, that uses the passed in closure to generate the + /// value, it will be invoked everytime `build` is called. + /// + /// - parameter key: attribute name + /// - parameter closure: closure to generate the attribute value + /// - returns: It self + public func attr(key: String, closure: AttributeClosure) -> Self { + self.attributes[key] = closure + return self + } + + /// Defines an option that will be available when creating dynamic attributes, + /// and in `after` callbacks. + /// + /// - parameter key: attribute name + /// - parameter value: option value, if this is an `OptionClosure` it will be + /// invoked instead of returned + /// - returns: It self + public func option(key: String, @autoclosure(escaping) value: OptionClosure) -> Self { + self.options[key] = value + return self + } + + /// Adds a callback that will be invoked after the model is created, and + /// before it is return in by the `build` function. + /// + /// - parameter callback: callback to be invoked right after creating the + /// object + /// - returns: It self + public func after(callback: AfterClosure) -> Self { + self.after.append(callback) + return self + } + + /// Builds the object + /// + /// - parameter attributes: additional attributes + /// - parameter options: additional options + /// - returns: The built object + public func build(attributes: [String: Any] = [:], options: [String: Any] = [:]) -> T { + let options = self.options(options) + let attributes = self.attributes(attributes, options: options) + let item = self.create(attributes: attributes) + for callback in self.after { + callback(item: item, options: options) + } + return item + } + + func attributes(var attributes: [String: Any], options: [String: Any]) -> [String: Any] { + for (key, value) in self.attributes where attributes[key] == nil { + attributes[key] = value(options: options) + } + return attributes + } + + func options(var options: [String: Any]) -> [String: Any] { + for (key, value) in self.options where options[key] == nil { + options[key] = value() + } + return options + } + +} diff --git a/supporting_files/Bankside.h b/supporting_files/Bankside.h new file mode 100644 index 0000000..5d5d7ab --- /dev/null +++ b/supporting_files/Bankside.h @@ -0,0 +1,4 @@ +#import + +FOUNDATION_EXPORT double BanksideVersionNumber; +FOUNDATION_EXPORT const unsigned char BanksideVersionString[]; diff --git a/supporting_files/ios/info.plist b/supporting_files/ios/info.plist new file mode 100644 index 0000000..d3de8ee --- /dev/null +++ b/supporting_files/ios/info.plist @@ -0,0 +1,26 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + $(CURRENT_PROJECT_VERSION) + NSPrincipalClass + + + diff --git a/supporting_files/mac/info.plist b/supporting_files/mac/info.plist new file mode 100644 index 0000000..3be9c6c --- /dev/null +++ b/supporting_files/mac/info.plist @@ -0,0 +1,28 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + $(CURRENT_PROJECT_VERSION) + NSHumanReadableCopyright + Copyright © 2015 Flow. All rights reserved. + NSPrincipalClass + + + diff --git a/supporting_files/tests/info.plist b/supporting_files/tests/info.plist new file mode 100644 index 0000000..ba72822 --- /dev/null +++ b/supporting_files/tests/info.plist @@ -0,0 +1,24 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + + diff --git a/tests/factory_spec.swift b/tests/factory_spec.swift new file mode 100644 index 0000000..d151ca9 --- /dev/null +++ b/tests/factory_spec.swift @@ -0,0 +1,135 @@ +@testable import Bankside +import Foundation +import Quick +import Nimble + +struct FactorySpecStruct { + let attributes: [String: Any] + init(attributes: [String: Any]) { + self.attributes = attributes + } +} + +class FactorySpec: QuickSpec { + + override func spec() { + var factory: Factory! + beforeEach { + factory = Factory({ FactorySpecStruct(attributes: $0) }) + } + + describe("#uuid(key)") { + it("defines an UUID attribute") { + factory.uuid("id") + let attributes = factory.attributes([:], options: [:]) + expect(attributes["id"]).notTo(beNil()) + expect(attributes["id"] is String).to(equal(true)) + } + } + + describe("#sequence(key)") { + beforeEach { + factory.sequence("id") + } + + it("defines attribute") { + let attributes = factory.attributes([:], options: [:]) + expect(attributes["id"] as? Int).to(equal(1)) + } + + it("increments attribute value") { + let _ = factory.attributes([:], options: [:]) + let attributes = factory.attributes([:], options: [:]) + expect(attributes["id"] as? Int).to(equal(2)) + } + } + + describe("#sequence(key, closure)") { + it("defines attribute") { + factory.sequence("id") { "id: \($0)" } + let attributes = factory.attributes([:], options: [:]) + expect(attributes["id"] as? String).to(equal("id: 1")) + } + } + + describe("#attr(key, value)") { + it("defines attribute") { + factory.attr("id", value: "lol") + let attributes = factory.attributes([:], options: [:]) + let id = attributes["id"] as! String + expect(id).to(equal("lol")) + } + } + + describe("#attr(key, closure)") { + it("defines attribute") { + factory.attr("id") { _ in "lol" } + let attributes = factory.attributes([:], options: [:]) + let id = attributes["id"] as! String + expect(id).to(equal("lol")) + } + + it("passes in options") { + waitUntil(timeout: 5) { done in + factory.attr("id") { options in + expect(options["value"] as? Bool).to(equal(true)) + defer { done() } + return "hey" + } + factory.attributes([:], options: ["value": true]) + } + } + } + + describe("#option(key, value)") { + beforeEach { + factory.option("store", value: true) + } + + it("defines option") { + let options = factory.options([:]) + expect(options["store"] as? Bool).to(equal(true)) + } + + it("overwrites option") { + let options = factory.options(["store": false]) + expect(options["store"] as? Bool).to(equal(false)) + } + } + + describe("#option(key, closure)") { + beforeEach { + factory.option("store", value: NSUUID().UUIDString) + } + it("uses closure value") { + let optionsA = factory.options([:]) + let optionsB = factory.options([:]) + expect(optionsA["store"] is String).to(equal(true)) + expect(optionsA["store"] as? String).notTo(equal(optionsB["store"] as? String)) + } + } + + describe("#after(callback)") { + it("invokes callback when calling `build()`") { + waitUntil(timeout: 5) { done in + factory.after { item, options in + done() + } + factory.build() + } + } + + it("passes in options") { + waitUntil(timeout: 5) { done in + factory.after { item, options in + expect(options["works"] as? Bool).to(equal(true)) + done() + } + factory.build(options: ["works": true]) + } + } + + } + } + +}