Skip to content

Commit 97415d0

Browse files
committed
Simplify GitHubEventSpec but use more nested Scalatest matchers
1 parent 568efb4 commit 97415d0

File tree

1 file changed

+65
-84
lines changed

1 file changed

+65
-84
lines changed

src/test/scala/events/GitHubEventSpec.scala

Lines changed: 65 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -15,42 +15,34 @@ class GitHubEventSpec extends FunSpec with Matchers with Inside
1515
it("should yield IssueEvent") {
1616
event shouldBe a [IssueEvent]
1717
}
18-
it("should have a name") {
18+
describe("IssueEvent") {
1919
inside(event) {
2020
case e @ IssueEvent(name, _) =>
21-
assert(name === "issue")
22-
}
23-
}
24-
it("should have an action") {
25-
inside(event) {
26-
case e @ IssueEvent(_, _) =>
27-
assert(e.action === models.IssueAction.opened)
28-
}
29-
}
30-
it("should have an issue") {
31-
inside(event) {
32-
case e @ IssueEvent(_, _) =>
33-
e.issue shouldBe a [models.Issue]
34-
}
35-
}
36-
describe("Issue") {
37-
inside(event) {
38-
case e @ IssueEvent(_, _) => {
39-
val issue = e.issue
40-
it("should have a number") {
41-
assert(issue.number === 2l)
21+
it("should have a name") {
22+
assert(name === "issue")
4223
}
43-
it("should have a title") {
44-
assert(issue.title === "Spelling error in the README file")
24+
it("should have an action") {
25+
assert(e.action === models.IssueAction.opened)
4526
}
46-
it("should have a state") {
47-
assert(issue.state === "open")
27+
it("should have an issue") {
28+
e.issue shouldBe a [models.Issue]
4829
}
49-
it("should have a body") {
50-
val exp = "It looks like you accidently spelled 'commit' with two 't's."
51-
assert(issue.body === Some(exp))
30+
describe("Issue") {
31+
val issue = e.issue
32+
it("should have a number") {
33+
assert(issue.number === 2l)
34+
}
35+
it("should have a title") {
36+
assert(issue.title === "Spelling error in the README file")
37+
}
38+
it("should have a state") {
39+
assert(issue.state === "open")
40+
}
41+
it("should have a body") {
42+
val exp = "It looks like you accidently spelled 'commit' with two 't's."
43+
assert(issue.body === Some(exp))
44+
}
5245
}
53-
}
5446
}
5547
}
5648
}
@@ -61,72 +53,61 @@ class GitHubEventSpec extends FunSpec with Matchers with Inside
6153
it("should yield PullRequestEvent") {
6254
event shouldBe a [PullRequestEvent]
6355
}
64-
it("should have a name") {
65-
inside(event) {
66-
case e @ PullRequestEvent(name, _) =>
67-
assert(name === "pull_request")
68-
}
69-
}
70-
it("should have a number") {
71-
inside(event) {
72-
case e @ PullRequestEvent(_, _) =>
73-
assert(e.number === 1l)
74-
}
75-
}
76-
it("should have an action") {
77-
inside(event) {
78-
case e @ PullRequestEvent(_, _) =>
79-
assert(e.action === models.PullRequestAction.opened)
80-
}
81-
}
82-
it("should have a pull request") {
83-
inside(event) {
84-
case e @ PullRequestEvent(_, _) =>
85-
e.pull_request shouldBe a [models.PullRequest]
86-
}
87-
}
8856
describe("PullRequest") {
8957
inside(event) {
90-
case e @ PullRequestEvent(_, _) => {
91-
val pr = e.pull_request
92-
it("should have a number") {
93-
assert(pr.number === 1l)
94-
}
95-
it("should have a title") {
96-
assert(pr.title === "Update the README with new information")
58+
case e @ PullRequestEvent(name, _) =>
59+
it("should have a name") {
60+
assert(name === "pull_request")
9761
}
98-
it("should have a state") {
99-
assert(pr.state === "open")
62+
it("should have a number") {
63+
assert(e.number === 1l)
10064
}
101-
it("should have a body") {
102-
val exp = "This is a pretty simple change that we need to pull into master."
103-
assert(pr.body === exp)
65+
it("should have an action") {
66+
assert(e.action === models.PullRequestAction.opened)
10467
}
105-
it("should have a head") {
106-
pr.head shouldBe a [models.PullRequestRef]
68+
it("should have a pull request") {
69+
e.pull_request shouldBe a [models.PullRequest]
10770
}
108-
describe("PullRequestRef") {
109-
val head = pr.head
110-
it("should have a label") {
111-
assert(head.label === "baxterthehacker:changes")
71+
describe("PullRequest") {
72+
val pr = e.pull_request
73+
it("should have a number") {
74+
assert(pr.number === 1l)
11275
}
113-
it("should have a ref") {
114-
assert(head.ref === "changes")
76+
it("should have a title") {
77+
assert(pr.title === "Update the README with new information")
11578
}
116-
it("should have a sha") {
117-
assert(head.sha === "0d1a26e67d8f5eaf1f6ba5c57fc3c7d91ac0fd1c")
79+
it("should have a state") {
80+
assert(pr.state === "open")
11881
}
119-
it("should have a user") {
120-
head.user shouldBe a [models.User]
82+
it("should have a body") {
83+
val exp = "This is a pretty simple change that we need to pull into master."
84+
assert(pr.body === exp)
12185
}
122-
it("should have a repo") {
123-
head.repo shouldBe a [models.Repository]
86+
it("should have a head") {
87+
pr.head shouldBe a [models.PullRequestRef]
88+
}
89+
describe("PullRequestRef") {
90+
val head = pr.head
91+
it("should have a label") {
92+
assert(head.label === "baxterthehacker:changes")
93+
}
94+
it("should have a ref") {
95+
assert(head.ref === "changes")
96+
}
97+
it("should have a sha") {
98+
assert(head.sha === "0d1a26e67d8f5eaf1f6ba5c57fc3c7d91ac0fd1c")
99+
}
100+
it("should have a user") {
101+
head.user shouldBe a [models.User]
102+
}
103+
it("should have a repo") {
104+
head.repo shouldBe a [models.Repository]
105+
}
106+
}
107+
it("should have a base") {
108+
pr.base shouldBe a [models.PullRequestRef]
124109
}
125110
}
126-
it("should have a base") {
127-
pr.base shouldBe a [models.PullRequestRef]
128-
}
129-
}
130111
}
131112
}
132113
}

0 commit comments

Comments
 (0)