|
| 1 | +import XCTest |
1 | 2 | import Spectre |
2 | 3 | @testable import Stencil |
3 | 4 |
|
4 | 5 |
|
5 | | -func testContext() { |
6 | | - describe("Context") { |
7 | | - var context: Context! |
| 6 | +class ContextTests: XCTestCase { |
| 7 | + |
| 8 | + func testContext() { |
| 9 | + describe("Context") { |
| 10 | + var context: Context! |
8 | 11 |
|
9 | | - $0.before { |
10 | | - context = Context(dictionary: ["name": "Kyle"]) |
11 | | - } |
| 12 | + $0.before { |
| 13 | + context = Context(dictionary: ["name": "Kyle"]) |
| 14 | + } |
12 | 15 |
|
13 | | - $0.it("allows you to get a value via subscripting") { |
14 | | - try expect(context["name"] as? String) == "Kyle" |
15 | | - } |
| 16 | + $0.it("allows you to get a value via subscripting") { |
| 17 | + try expect(context["name"] as? String) == "Kyle" |
| 18 | + } |
16 | 19 |
|
17 | | - $0.it("allows you to set a value via subscripting") { |
18 | | - context["name"] = "Katie" |
| 20 | + $0.it("allows you to set a value via subscripting") { |
| 21 | + context["name"] = "Katie" |
19 | 22 |
|
20 | | - try expect(context["name"] as? String) == "Katie" |
21 | | - } |
| 23 | + try expect(context["name"] as? String) == "Katie" |
| 24 | + } |
22 | 25 |
|
23 | | - $0.it("allows you to remove a value via subscripting") { |
24 | | - context["name"] = nil |
| 26 | + $0.it("allows you to remove a value via subscripting") { |
| 27 | + context["name"] = nil |
25 | 28 |
|
26 | | - try expect(context["name"]).to.beNil() |
27 | | - } |
| 29 | + try expect(context["name"]).to.beNil() |
| 30 | + } |
28 | 31 |
|
29 | | - $0.it("allows you to retrieve a value from a parent") { |
30 | | - try context.push { |
31 | | - try expect(context["name"] as? String) == "Kyle" |
| 32 | + $0.it("allows you to retrieve a value from a parent") { |
| 33 | + try context.push { |
| 34 | + try expect(context["name"] as? String) == "Kyle" |
| 35 | + } |
32 | 36 | } |
33 | | - } |
34 | 37 |
|
35 | | - $0.it("allows you to override a parent's value") { |
36 | | - try context.push { |
37 | | - context["name"] = "Katie" |
38 | | - try expect(context["name"] as? String) == "Katie" |
| 38 | + $0.it("allows you to override a parent's value") { |
| 39 | + try context.push { |
| 40 | + context["name"] = "Katie" |
| 41 | + try expect(context["name"] as? String) == "Katie" |
| 42 | + } |
39 | 43 | } |
40 | | - } |
41 | 44 |
|
42 | | - $0.it("allows you to pop to restore previous state") { |
43 | | - context.push { |
44 | | - context["name"] = "Katie" |
| 45 | + $0.it("allows you to pop to restore previous state") { |
| 46 | + context.push { |
| 47 | + context["name"] = "Katie" |
| 48 | + } |
| 49 | + |
| 50 | + try expect(context["name"] as? String) == "Kyle" |
45 | 51 | } |
46 | 52 |
|
47 | | - try expect(context["name"] as? String) == "Kyle" |
48 | | - } |
| 53 | + $0.it("allows you to remove a parent's value in a level") { |
| 54 | + try context.push { |
| 55 | + context["name"] = nil |
| 56 | + try expect(context["name"]).to.beNil() |
| 57 | + } |
49 | 58 |
|
50 | | - $0.it("allows you to remove a parent's value in a level") { |
51 | | - try context.push { |
52 | | - context["name"] = nil |
53 | | - try expect(context["name"]).to.beNil() |
| 59 | + try expect(context["name"] as? String) == "Kyle" |
54 | 60 | } |
55 | 61 |
|
56 | | - try expect(context["name"] as? String) == "Kyle" |
57 | | - } |
| 62 | + $0.it("allows you to push a dictionary and run a closure then restoring previous state") { |
| 63 | + var didRun = false |
58 | 64 |
|
59 | | - $0.it("allows you to push a dictionary and run a closure then restoring previous state") { |
60 | | - var didRun = false |
| 65 | + try context.push(dictionary: ["name": "Katie"]) { |
| 66 | + didRun = true |
| 67 | + try expect(context["name"] as? String) == "Katie" |
| 68 | + } |
61 | 69 |
|
62 | | - try context.push(dictionary: ["name": "Katie"]) { |
63 | | - didRun = true |
64 | | - try expect(context["name"] as? String) == "Katie" |
| 70 | + try expect(didRun).to.beTrue() |
| 71 | + try expect(context["name"] as? String) == "Kyle" |
65 | 72 | } |
66 | 73 |
|
67 | | - try expect(didRun).to.beTrue() |
68 | | - try expect(context["name"] as? String) == "Kyle" |
69 | | - } |
70 | | - |
71 | | - $0.it("allows you to flatten the context contents") { |
72 | | - try context.push(dictionary: ["test": "abc"]) { |
73 | | - let flattened = context.flatten() |
| 74 | + $0.it("allows you to flatten the context contents") { |
| 75 | + try context.push(dictionary: ["test": "abc"]) { |
| 76 | + let flattened = context.flatten() |
74 | 77 |
|
75 | | - try expect(flattened.count) == 2 |
76 | | - try expect(flattened["name"] as? String) == "Kyle" |
77 | | - try expect(flattened["test"] as? String) == "abc" |
| 78 | + try expect(flattened.count) == 2 |
| 79 | + try expect(flattened["name"] as? String) == "Kyle" |
| 80 | + try expect(flattened["test"] as? String) == "abc" |
| 81 | + } |
78 | 82 | } |
79 | 83 | } |
80 | 84 | } |
|
0 commit comments