QuickSpec.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #import <XCTest/XCTest.h>
  2. /**
  3. QuickSpec is a base class all specs written in Quick inherit from.
  4. They need to inherit from QuickSpec, a subclass of XCTestCase, in
  5. order to be discovered by the XCTest framework.
  6. XCTest automatically compiles a list of XCTestCase subclasses included
  7. in the test target. It iterates over each class in that list, and creates
  8. a new instance of that class for each test method. It then creates an
  9. "invocation" to execute that test method. The invocation is an instance of
  10. NSInvocation, which represents a single message send in Objective-C.
  11. The invocation is set on the XCTestCase instance, and the test is run.
  12. Most of the code in QuickSpec is dedicated to hooking into XCTest events.
  13. First, when the spec is first loaded and before it is sent any messages,
  14. the +[NSObject initialize] method is called. QuickSpec overrides this method
  15. to call +[QuickSpec spec]. This builds the example group stacks and
  16. registers them with Quick.World, a global register of examples.
  17. Then, XCTest queries QuickSpec for a list of test methods. Normally, XCTest
  18. automatically finds all methods whose selectors begin with the string "test".
  19. However, QuickSpec overrides this default behavior by implementing the
  20. +[XCTestCase testInvocations] method. This method iterates over each example
  21. registered in Quick.World, defines a new method for that example, and
  22. returns an invocation to call that method to XCTest. Those invocations are
  23. the tests that are run by XCTest. Their selector names are displayed in
  24. the Xcode test navigation bar.
  25. */
  26. @interface QuickSpec : XCTestCase
  27. /**
  28. Override this method in your spec to define a set of example groups
  29. and examples.
  30. @code
  31. override func spec() {
  32. describe("winter") {
  33. it("is coming") {
  34. // ...
  35. }
  36. }
  37. }
  38. @endcode
  39. See DSL.swift for more information on what syntax is available.
  40. */
  41. - (void)spec;
  42. /**
  43. Returns the currently executing spec. Use in specs that require XCTestCase
  44. methods, e.g. expectationWithDescription.
  45. */
  46. @property (class, nonatomic, readonly) QuickSpec *current;
  47. @end