-
Notifications
You must be signed in to change notification settings - Fork 512
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Support XCTest, Expecta and Nimble assertions in Kiwi specs #636
Conversation
XCTest assertions in Objective-C require self to point to an instance of XCTestCase. Unfortunately Kiwi currently builds examples from within a class method `+buildExampleGroups`, so self points to the class XCTestCase, rather than the running test case instance.
Allows the use of XCTest assertions in specs. This should include other matcher libraries implemented in terms of XCTest assertions. - Within `+buildExampleGroups`, defines a shadow `self` pointer that is of the type of the test case instance. - Unrecognized selectors sent to the test case class are forwarded to the current example, and then to the current test case instance. - Adds a test for the use of XCTest assertions within specs.
|
||
describe(@"XCTest assertions in Objective C", ^{ | ||
it(@"supports XCTAssert", ^{ | ||
XCTAssert(1 + 1 == 2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test passes. In fact, it probably would have passed without any of the other changes in this PR. 0_o
The important thing is actually not that this test passes, but that when it fails it fails in the right way. I don't actually know how to verify that. ¯_(ツ)_/¯
👍 for the code. |
- Builds Expecta.framework via Carthage. - Overrides `+respondsToSelector:` in `KWSpec` to delegate to the current example, allowing failures to be recorded via the current test case instance.
- Builds Nimble.framework via Carthage. - Adds Swift and Objective-C specs for Nimble support.
I've just pushed a couple more commits adding explicit support for both Expecta and Nimble matchers! |
Been thinking on testing that assertions behave correctly, and I could potentially follow a similar approach to this: https://github.com/kiwi-bdd/Kiwi/blob/master/test_suite_configuration.rb. Basically:
However, it would be a lot nicer to have it properly integrated into the existing test suite. |
Introduces `KWFailureInterceptingSpec` which can intercept failures recorded by XCTest. This enables a custom `haveFailed` matcher to be defined in order to assert that a given block records a test failure. Swift specs will need to be handled differently, mainly because Kiwi matchers aren't available in Swift yet.
Yo @supermarin, came up with something for testing that assertions occur: a77c3e7. |
I looked into trying to do write the same kind of test in the Swift specs, but we don't even support full Kiwi matchers in Swift yet. And it's working really well in Objective-C, so I don't think it's necessary to duplicate the effort in this PR. ⛵ |
Support XCTest, Expecta and Nimble assertions in Kiwi specs
It's not working for me #import <Kiwi/Kiwi.h>
#import <Expecta/Expecta.h>
SPEC_BEGIN(TestSpec)
describe(@"Just a test", ^{
it(@"Works",^{
expect(1).to.equal(1);
});
});
SPEC_END It errors on |
This change allows the use of XCTest assertions in specs. This should hopefully include other matcher libraries implemented in terms of XCTest assertions!
To be clear, I'm thinking of adding some more functional specs in this PR to test out whether this will enable support for Expecta or Nimble matchers.
This now works:
+buildExampleGroups
, defines a shadowself
pointer that is of the type of the test case instance.the current example, and then to the current test case instance.
This should possibly be considered a breaking change, because any users depending on the type of
self
being their test case class (and for example invoking class methods onKWSpec
different in a category) will now get compiler warnings (that would be compiler errors in the case of-Werror
).However:
self
is still actually the class object at runtime!To make this not a breaking change (at compile time), a workaround could be for this PR to change the type of
self
toid
. This is probably even more accurate! However the convenience of the static type declaration is useful. I just don't know if this will be an issue in practice for Kiwi users.