2

I try to create a cocoapod to extend Primitives in Swift. I have troubles to get tests passing or have an misconfiguration:

Here is my Nimble/Quick Test:

// 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)) // ***
            }

        }
    }
}

*** I get an unresolved identifier "validString"error

What I really wanna Test is an extension. But the variables are not attached to my strings too:

public extension String {

    public var isAlpha: Bool {

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

}
Jan
  • 12,992
  • 9
  • 53
  • 89
  • Just a note your test isn't really doing anything. It is comparing `validString` to `validString` and you aren't actually testing `isAlpha`. – sbarow May 30 '17 at 10:49
  • this is only for sanityChecking :-) "in real" life it's testing isAlpha – Jan May 30 '17 at 10:50

1 Answers1

3

Have your variables outside of the beforeEach and then set them in the beforeEach

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

    beforeEach {
        validString = "abc"
        invalidString = "abc12"
    }
    ...
}
sbarow
  • 2,759
  • 1
  • 22
  • 37