Skip to content

Commit

Permalink
Add support for activities in test inspector
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Kim Dung-Pham committed Apr 17, 2020
1 parent e1a6d7d commit 30cd15c
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 8 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ func test_iCanSeeTheStars() {
}
}
```

---

<img width=600 src="Resources/test-output.png" alt="Example Output in the Report navigator">
Binary file added Resources/test-output.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions Sources/Rorschach/Assertion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@ open class Assertion<C> {

public init() {}

open var title: String {
"\(type(of: self))"
}

open func assert(in context: C) {}
}
7 changes: 6 additions & 1 deletion Sources/Rorschach/Given.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import Foundation
import XCTest

public class Given<C> {

Expand All @@ -24,6 +25,10 @@ public class Given<C> {
}

func execute(in context: inout C) {
steps.forEach { $0.execute(in: &context) }
steps.forEach { step in
XCTContext.runActivity(named: step.title ) { _ in
step.execute(in: &context)
}
}
}
}
4 changes: 4 additions & 0 deletions Sources/Rorschach/Step.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@ open class Step<C> {

public init() {}

open var title: String {
"\(type(of: self))"
}

open func execute(in context: inout C) {}
}
21 changes: 16 additions & 5 deletions Sources/Rorschach/Test.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,30 @@
//

import Foundation
import XCTest

public func expect<C>(in context: inout C, @TestBuilder<C> _ content: () -> (given: Given<C>, when: When<C>, then: Then<C>)) {

content().given.execute(in: &context)
XCTContext.runActivity(named: "Given" ) { _ in
content().given.execute(in: &context)
}

content().when.execute(in: &context)
XCTContext.runActivity(named: "When" ) { _ in
content().when.execute(in: &context)
}

content().then.assert(in: context)
XCTContext.runActivity(named: "Then" ) { _ in
content().then.assert(in: context)
}
}

public func expect<C>(in context: inout C, @TestBuilder<C> _ content: () -> (when: When<C>, then: Then<C>)) {

content().when.execute(in: &context)
XCTContext.runActivity(named: "When" ) { _ in
content().when.execute(in: &context)
}

content().then.assert(in: context)
XCTContext.runActivity(named: "Then" ) { _ in
content().then.assert(in: context)
}
}
5 changes: 4 additions & 1 deletion Sources/Rorschach/Then.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import Foundation
import XCTest

public struct Then<C> {

Expand All @@ -16,6 +17,8 @@ public struct Then<C> {
}

func assert(in context: C) {
assertion.assert(in: context)
XCTContext.runActivity(named: assertion.title) { _ in
assertion.assert(in: context)
}
}
}
5 changes: 4 additions & 1 deletion Sources/Rorschach/When.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import Foundation
import XCTest

public struct When<C> {

Expand All @@ -16,7 +17,9 @@ public struct When<C> {
}

func execute(in context: inout C) {
step.execute(in: &context)
XCTContext.runActivity(named: step.title) { activity in
step.execute(in: &context)
}
}
}

0 comments on commit 30cd15c

Please sign in to comment.