cedarbdd / cedar

BDD-style testing using Objective-C
http://groups.google.com/group/cedar-discuss
1.19k stars 140 forks source link

Swift support for the Cedar test runner #367

Closed briancroom closed 8 years ago

briancroom commented 8 years ago

As more and more projects are expressing interest in using Cedar in pure-Swift and (especially) mixed Objective-C and Swift contexts, I've taken some steps towards a maintainable approach to making the Cedar test runner, including the describe, it, etc. DSL available from Swift. To be clear, Cedar matchers and doubles remain inaccessible from Swift due to their reliance on C++. (See discussion at #259)

I consider this to be an evolution of great proof-of-concept work done by @tjarratt and @Jdavid1001 on the swift-spec-runner branch a while back. The key difference is that this branch makes the existing Cedar framework targets importable from Swift, instead of introducing additional targets dedicated to the runner.

Have a look at the individual commit messages to see the whole story, but the highlights here are:

With this PR, it is possible to add a Swift file like the following to an existing Cedar test suite or bundle:

import Cedar
import Nimble

class SwiftSpec: CDRSpec {
    override func declareBehaviors() {
        describe("running tests in Swift") {
            it("can use XCTest assertions") {
                XCTAssertEqual(1, 1)
            }

            it("can use Nimble matchers") {
                expect(1).to(equal(1));
            }
        }
    }
}
briancroom commented 8 years ago

There may be some dependency here on sorting out our Travis situation (#345), as Swift 2 is a requirement for some of this stuff to work properly.

briancroom commented 8 years ago

Here's a full example of using this in a test target mixing Objective-C and Swift specs with Nimble matchers: https://github.com/briancroom/TastesOfCocoa/tree/master/CedarWithNimble

tjarratt commented 8 years ago

This is truly awesome! I had wondered if it would be possible to conditionally compile in the C++ features of Cedar, but couldn't find a way to make it work because of the strict rule of the umbrella header importing each public header.

Conditionally bringing in the contents of the header though is quite clever. :trophy:

briancroom commented 8 years ago

To make progress on getting CI fixed up for this I'm intending to introduce an opt-out compile-time flag that can be included in rake's xcodebuild invocation to exclude the swift spec for older Xcode versions.

tjarratt commented 8 years ago

If there's anything we can do to help out, please let us know. There's a bit of a beach in SF and NY right now, and I'm really eager to help out myself as well.

briancroom commented 8 years ago

Travis is now passing and I have resolved the shared examples context issue as well. I'm looking forward to more feedback on this, but I believe it's about ready to merge!

briancroom commented 8 years ago

I have updated this to include Xcode snippets for the standard Cedar BDD constructs in Swift, as well as added the option to the file template to generate a Swift spec. Thanks to @modocache for the Quick spec template which I used as a reference for how to add a language picker!

With this, I feel that this is ready to be merged into master to receive broader feedback. /cc @tjarratt

briancroom commented 8 years ago

(I'll defer to someone else for adding Swift snippets for AppCode when the need is felt for them!)

tjarratt commented 8 years ago

I don't have nearly enough emoji to express my excitement right now.

This will have to suffice. :evergreen_tree: + :bird: = :balloon: :balloon: :balloon: