OfferingTests

public protocol OfferingTests

The protocol, all TestPoints will be defined on.

  • end() Extension method

    Marks a test as finished. No TestPoint may follow.

    Declaration

    Swift

    public func end()
  • Emits a passing TestPoint if no error will be thrown.

    tape.test("test does not throw on return", plan: 1) { t in
      t.doesThrow("does throw is ok when throwing") {
        return 1
      }
    }
    

    Parameter

    Parameter message: The message for the test.

    Declaration

    Swift

    public func doesNotThrow<T>(
        _ message: String? = nil,
        file: String = #file,
        line: Int = #line,
        column: Int = #column,
        function: String = #function,
        test: () throws -> T
      )

    Parameters

    message

    The message for the test.

  • Emits a passing TestPoint if an error will of another type will be thrown.

    struct MyError: Error { }
    struct AnotherError: Error { }
    tape.test("test does not throw on correct error type", plan: 1) { t in
      t.doesNotThrow(MyError.self, "does not throw is ok when other type") {
        throw AnotherError()
      }
    }
    

    Parameter

    Parameter kind: The kind of errors that are allowed for the test.

    Parameter

    Parameter message: The message for the test.

    Declaration

    Swift

    public func doesNotThrow<T, E: Error>(
        _ kind: E.Type,
        _ message: String? = nil,
        file: String = #file,
        line: Int = #line,
        column: Int = #column,
        function: String = #function,
        test: () throws -> T
      )

    Parameters

    kind

    The kind of errors that are allowed for the test.

    message

    The message for the test.

  • Emits a passing TestPoint if an error will of another type will be thrown.

    struct MyError: Error { }
    struct WrongError: Error { }
    tape.test("error doesn't emit other error'", plan: 1) { t in
      Observable.error(WrongError())
        .test(
          onNext: t.fail(".error won't emit"),
          onError: t.doesNotThrow(of: WrongError.self, with: "does not throw wrong type")
        )
    }
    

    Parameter

    Parameter kind: The kind of errors that are allowed for the test.

    Parameter

    Parameter message: The message for the test.

    Declaration

    Swift

    public func doesNotThrow<E: Error>(
        of kind: E.Type,
        _ message: String? = nil,
        file: String = #file,
        line: Int = #line,
        column: Int = #column,
        function: String = #function
      ) -> (Error) -> Void

    Parameters

    kind

    The kind of errors that are allowed for the test.

    message

    The message for the test.

  • Emits a passing TestPoint if an error will be thrown.

    struct MyError: Error { }
    tape.test("test does throw on throw", plan: 1) { t in
      t.doesThrow("does throw is ok when throwing") {
        throw MyError()
      }
    }
    

    Parameter

    Parameter message: The message for the test.

    Declaration

    Swift

    public func doesThrow<T>(
        _ message: String? = nil,
        file: String = #file,
        line: Int = #line,
        column: Int = #column,
        function: String = #function,
        test: () throws -> T
      )

    Parameters

    message

    The message for the test.

  • Emits a passing TestPoint if an error will of the correct type will be thrown.

    struct MyError: Error { }
    tape.test("test does throw on correct error type", plan: 1) { t in
      t.doesThrow(MyError.self, "does throw is ok when correct type") {
        throw MyError()
      }
    }
    

    Parameter

    Parameter kind: The kind of errors that are allowed for the test.

    Parameter

    Parameter message: The message for the test.

    Declaration

    Swift

    public func doesThrow<T, E: Error>(
        _ kind: E.Type,
        _ message: String? = nil,
        file: String = #file,
        line: Int = #line,
        column: Int = #column,
        function: String = #function,
        test: () throws -> T
      )

    Parameters

    kind

    The kind of errors that are allowed for the test.

    message

    The message for the test.

  • A curried version of doesThrow. Just emits a passing TestPoint. Useful for Observables.

    struct MyError: Error { }
    tape.test("observable error emits same error", plan: 1) { t in
      Observable.error(MyError())
        .test(
          onNext: t.fail(".error won't emit"),
          onError: t.doesThrow(of: MyError.self, with: "does throw correct type")
        )
    }
    

    Parameter

    Parameter kind: The kind of errors that are allowed for the test.

    Parameter

    Parameter message: The message for the test.

    Declaration

    Swift

    public func doesThrow<E: Error>(
        of kind: E.Type,
        with message: String? = nil,
        file: String = #file,
        line: Int = #line,
        column: Int = #column,
        function: String = #function
      ) -> (Error) -> Void

    Parameters

    kind

    The kind of errors that are allowed for the test.

    message

    The message for the test.

  • Emits a TestPoint, that passes if both values are equal.

    tape.test("test equality reflexiveness", plan: 1) { t in
      t.equal(2, 2, "must be reflexive")
    }
    

    Parameter

    Parameter given: The value to be tested.

    Parameter

    Parameter expected: The value to be compared against.

    Parameter

    Parameter message: The message for the test.

    Declaration

    Swift

    public func equal<T: Equatable>(
        _ given: T,
        _ expected: T,
        _ message: String? = nil,
        file: String = #file,
        line: Int = #line,
        column: Int = #column,
        function: String = #function
      )

    Parameters

    given

    The value to be tested.

    expected

    The value to be compared against.

    message

    The message for the test.

  • A curried version of Test.equal. Useful for Observables.

    tape.test("just emits", timeout: 0.01) { t in
      Observable.just(3).test(
        onNext: t.equal(to: 3, "just emits 3"),
        onError: t.fail(with: "just won't throw'")
      )
    }
    

    Parameter

    Parameter expected: The expected value.

    Parameter

    Parameter message: The message for the test.

    Declaration

    Swift

    public func equal<T: Equatable>(
        to expected: T,
        _ message: String? = nil,
        file: String = #file,
        line: Int = #line,
        column: Int = #column,
        function: String = #function
      ) -> (T) -> Void

    Parameters

    expected

    The expected value.

    message

    The message for the test.

  • Just emits a failing TestPoint.

    tape.test(plan: 1, directive: Directive.todo) { t in
      t.fail("not implemented")
    }
    

    Parameter

    Parameter message: The message for the test.

    Declaration

    Swift

    public func fail(
        _ message: String? = nil,
        file: String = #file,
        line: Int = #line,
        column: Int = #column,
        function: String = #function
      )

    Parameters

    message

    The message for the test.

  • A curried version of fail. Just emits a failing TestPoint. Useful for Observables.

    tape.test("empty", timeout: 0.01) { t in
      Observable.empty().test(
        onNext: t.fail(with: "empty doesn't emit"),
        onError: t.fail(with: "empty won't throw")
      )
    }
    

    Parameter

    Parameter message: The message for the test.

    Declaration

    Swift

    public func fail<T>(
        with message: String? = nil,
        file: String = #file,
        line: Int = #line,
        column: Int = #column,
        function: String = #function
      ) -> (T) -> Void

    Parameters

    message

    The message for the test.

  • Emits a TestPoint, that passes if both values are not equal.

    tape.test("test equality", plan: 1) { t in
      t.notEqual(1, 2, "no false positives")
    }
    

    Parameter

    Parameter message: The message for the test.

    Declaration

    Swift

    public func notEqual<T: Equatable>(
        _ given: T,
        _ expected: T,
        message: String? = nil,
        file: String = #file,
        line: Int = #line,
        column: Int = #column,
        function: String = #function
      )

    Parameters

    message

    The message for the test.

  • A curried version of Test.notEqual. Useful for Observables.

    tape.test("just emits", timeout: 0.01) { t in
      Observable.just(3)
        .map { $0 + 1 }
        .test(
          onNext: t.notEqual(to: 3, "just emits 3"),
          onError: t.fail(with: "just won't throw'")
      )
    }
    

    Parameter

    Parameter expected: The expected value.

    Parameter

    Parameter message: The message for the test.

    Declaration

    Swift

    public func notEqual<T: Equatable>(
        to expected: T,
        message: String? = nil,
        file: String = #file,
        line: Int = #line,
        column: Int = #column,
        function: String = #function
      ) -> (T) -> Void

    Parameters

    expected

    The expected value.

    message

    The message for the test.

  • Emits a passing TestPoint if test is false.

    tape.test("test array is not empty", plan: 1) { t in
      t.notOk([1].isEmpty, "[1] is not empty")
    }
    

    Parameter

    Parameter test: The value to be tested.

    Parameter

    Parameter message: The message for the test.

    Declaration

    Swift

    public func notOk(
        _ test: Bool,
        _ message: String? = nil,
        file: String = #file,
        line: Int = #line,
        column: Int = #column,
        function: String = #function
      )

    Parameters

    test

    The value to be tested.

    message

    The message for the test.

  • Emits a passing TestPoint if test is nil.

    tape.test("test empty array first", plan: 1) { t in
      t.notOk([].first, "[] has no first")
    }
    

    Parameter

    Parameter test: The value to be tested.

    Parameter

    Parameter message: The message for the test.

    Declaration

    Swift

    public func notOk<T>(
        _ test: T?,
        _ message: String? = nil,
        file: String = #file,
        line: Int = #line,
        column: Int = #column,
        function: String = #function
      )

    Parameters

    test

    The value to be tested.

    message

    The message for the test.

  • A curried version of Test.notOk. Useful for Observables.

    tape.test("first emits once", timeout: 0.01) { t in
      Observable.of(0, 1).first.test(
        onNext: t.notOk(matches: { $0 >= 0 }),
        onError: t.fail(with: "of().first won't throw'")
      )
    }
    

    Parameter

    Parameter message: The message for the test.

    Parameter

    Parameter predicate: The predicate for the value.

    Declaration

    Swift

    public func notOk<T>(
        with message: String? = nil,
        file: String = #file,
        line: Int = #line,
        column: Int = #column,
        function: String = #function,
        matches predicate: @escaping (T) -> Bool
      ) -> (T) -> Void

    Parameters

    message

    The message for the test.

    predicate

    The predicate for the value.

  • A curried version of Test.ok. Useful for Observables.

    tape.test("first emits once", timeout: 0.01) { t in
      Observable.of(false, true).first.test(
        onNext: t.notOk(with: "only emits false"),
        onError: t.fail(with: "of().first won't throw'")
      )
    }
    

    Parameter

    Parameter message: The message for the test.

    Parameter

    Parameter predicate: The predicate for the value.

    Declaration

    Swift

    public func notOk(
        with message: String? = nil,
        file: String = #file,
        line: Int = #line,
        column: Int = #column,
        function: String = #function
      ) -> (Bool) -> Void

    Parameters

    message

    The message for the test.

    predicate

    The predicate for the value.

  • A curried version of Test.notOk. Useful for Observables.

    tape.test("first emits once", timeout: 0.01) { t in
      Observable.of(nil, 1).first.test(
        onNext: t.notOk(with: "won't emit nil"),
        onError: t.fail(with: "of().first won't throw'")
      )
    }
    

    Parameter

    Parameter message: The message for the test.

    Parameter

    Parameter predicate: The predicate for the value.

    Declaration

    Swift

    public func notOk<T>(
        with message: String? = nil,
        file: String = #file,
        line: Int = #line,
        column: Int = #column,
        function: String = #function
      ) -> (T?) -> Void

    Parameters

    message

    The message for the test.

    predicate

    The predicate for the value.

  • Emits a passing TestPoint if test is true.

    tape.test("test array is empty", plan: 1) { t in
      t.ok([].isEmpty, "[] is empty")
    }
    

    Parameter

    Parameter test: The value to be tested.

    Parameter

    Parameter message: The message for the test.

    Declaration

    Swift

    public func ok(
        _ test: Bool,
        _ message: String? = nil,
        file: String = #file,
        line: Int = #line,
        column: Int = #column,
        function: String = #function
      )

    Parameters

    test

    The value to be tested.

    message

    The message for the test.

  • Emits a passing TestPoint if test is not nil.

    tape.test("test array first", plan: 1) { t in
      t.ok([1].first, "[1] has first")
    }
    

    Parameter

    Parameter test: The value to be tested.

    Parameter

    Parameter message: The message for the test.

    Declaration

    Swift

    public func ok<T>(
        _ test: T?,
        _ message: String? = nil,
        file: String = #file,
        line: Int = #line,
        column: Int = #column,
        function: String = #function
      )

    Parameters

    test

    The value to be tested.

    message

    The message for the test.

  • A curried version of Test.ok. Useful for Observables.

    tape.test("first emits once", timeout: 0.01) { t in
      Observable.of(1, 0).first.test(
        onNext: t.ok(matches: { $0 >= 0 }),
        onError: t.fail(with: "of().first won't throw'")
      )
    }
    

    Parameter

    Parameter message: The message for the test.

    Parameter

    Parameter predicate: The predicate for the value.

    Declaration

    Swift

    public func ok<T>(
        with message: String? = nil,
        file: String = #file,
        line: Int = #line,
        column: Int = #column,
        function: String = #function,
        matches predicate: @escaping (T) -> Bool
      ) -> (T) -> Void

    Parameters

    message

    The message for the test.

    predicate

    The predicate for the value.

  • A curried version of Test.ok. Useful for Observables.

    tape.test("first emits once", timeout: 0.01) { t in
      Observable.of(true, false).first.test(
        onNext: t.ok(with: "only emits true"),
        onError: t.fail(with: "of().first won't throw'")
      )
    }
    

    Parameter

    Parameter message: The message for the test.

    Parameter

    Parameter predicate: The predicate for the value.

    Declaration

    Swift

    public func ok(
        with message: String? = nil,
        file: String = #file,
        line: Int = #line,
        column: Int = #column,
        function: String = #function
      ) -> (Bool) -> Void

    Parameters

    message

    The message for the test.

    predicate

    The predicate for the value.

  • A curried version of Test.ok. Useful for Observables.

    tape.test("first emits once", timeout: 0.01) { t in
      Observable.of(1, nil).first.test(
        onNext: t.ok(with: "won't emit nil"),
        onError: t.fail(with: "of().first won't throw'")
      )
    }
    

    Parameter

    Parameter message: The message for the test.

    Parameter

    Parameter predicate: The predicate for the value.

    Declaration

    Swift

    public func ok<T>(
        with message: String? = nil,
        file: String = #file,
        line: Int = #line,
        column: Int = #column,
        function: String = #function
      ) -> (T?) -> Void

    Parameters

    message

    The message for the test.

    predicate

    The predicate for the value.

  • Just emits a passing TestPoint.

    tape.test(plan: 1) { t in
      t.pass()
    }
    

    Parameter

    Parameter message: The message for the test.

    Declaration

    Swift

    public func pass(
        _ message: String? = nil,
        file: String = #file,
        line: Int = #line,
        column: Int = #column,
        function: String = #function
      )

    Parameters

    message

    The message for the test.

  • A curried version of pass. Just emits a passing TestPoint. Useful for Observables.

    tape.test("just emits", timeout: 0.01) { t in
      Observable.just(3).test(
        onNext: t.pass(with: "just emits"),
        onError: t.fail(with: "just won't throw'")
      )
    }
    

    Parameter

    Parameter message: The message for the test.

    Declaration

    Swift

    public func pass<T>(
        with message: String? = nil,
        file: String = #file,
        line: Int = #line,
        column: Int = #column,
        function: String = #function
      ) -> (T) -> Void

    Parameters

    message

    The message for the test.