2

我尝试创建一个 cocoapod 来扩展 Swift 中的 Primitives。我无法通过测试或配置错误:

这是我的敏捷/快速测试:

// https://github.com/Quick/Quick

import Quick
import Nimble
import SwiftRubySyntax


class TableOfContentsSpec: QuickSpec {
    override func spec() {
        describe("alphanumeric") {

            beforeEach {
                var validString = "abc"
                var invalidString = "abc12"
            }

            it("validates alphas to be true") {
                expect(validString).to(equal(validString)) // ***
            }

        }
    }
}

*** 我收到一个unresolved identifier "validString"错误

我真正想要测试的是扩展。但是这些变量也没有附加到我的字符串上:

public extension String {

    public var isAlpha: Bool {

        let alphaSet = CharacterSet.uppercaseLetters.union(.lowercaseLetters).union(.whitespacesAndNewlines)
        return self.rangeOfCharacter(from: alphaSet.inverted) == nil
    }

}
4

1 回答 1

3

将变量放在之外,beforeEach然后将它们设置在beforeEach

describe("alphanumeric") {
    var validString: String!
    var invalidString: String!

    beforeEach {
        validString = "abc"
        invalidString = "abc12"
    }
    ...
}
于 2017-05-30T09:22:27.220 回答