Skip to content
This repository was archived by the owner on Jan 10, 2023. It is now read-only.

Commit bcac135

Browse files
author
Eric Crosson
committed
Use gomega idiomatically
1 parent 7526bfa commit bcac135

File tree

1 file changed

+22
-26
lines changed

1 file changed

+22
-26
lines changed

git_ledger_test.go

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,8 @@ func popGitLedger() {
2727
func createDummyLedger() {
2828
r = Record{Path: "/tmp", Slug: "pony/fill"}
2929
r.AddToLedger()
30-
records, _ := GetRecords()
31-
Expect(len(records) == 1)
32-
3330
s = Record{Path: "/home", Slug: "badger/bear"}
3431
s.AddToLedger()
35-
records, _ = GetRecords()
36-
Expect(len(records) == 2)
3732
}
3833

3934
var (
@@ -53,25 +48,25 @@ var _ = Describe("GitLedger", func() {
5348

5449
Describe("CLI", func() {
5550
Context("add", func() {
51+
// TODO: test about duplicates
5652
Specify("should accept fully-initialized records", func() {
57-
Record{Path: "/tmp", Slug: "pony/fill"}.AddToLedger()
53+
Record{Path: "/proc", Slug: "tron/man"}.AddToLedger()
5854
records, _ := GetRecords()
59-
Expect(len(records) == 1)
60-
61-
Record{Path: "/home", Slug: "badger/bear"}.AddToLedger()
55+
Expect(len(records)).To(Equal(3))
56+
Record{Path: "/dev", Slug: "cron/man"}.AddToLedger()
6257
records, _ = GetRecords()
63-
Expect(len(records) == 2)
58+
Expect(len(records)).To(Equal(4))
6459
})
6560
})
6661

6762
Context("remove", func() {
6863
Specify("should accept fully-initialized records", func() {
6964
s.RemoveFromLedger()
7065
records, _ := GetRecords()
71-
Expect(len(records) == 1)
66+
Expect(len(records)).To(Equal(1))
7267
r.RemoveFromLedger()
7368
records, _ = GetRecords()
74-
Expect(len(records) == 0)
69+
Expect(len(records)).To(Equal(0))
7570
})
7671
})
7772

@@ -87,16 +82,17 @@ var _ = Describe("GitLedger", func() {
8782

8883
Context("The ledger", func() {
8984
Specify("should reside in the user's home directory", func() {
90-
Expect(path.Join(os.Getenv("HOME"), ".git-ledger") == Path())
85+
Expect(path.Join(os.Getenv("HOME"), ".git-ledger")).To(Equal(Path()))
9186
})
9287
})
9388

9489
Describe("Records", func() {
9590

9691
Context("When the ledger is empty", func() {
9792
It("should return 0 records", func() {
93+
os.Remove(Path())
9894
records, _ := GetRecords()
99-
Expect(len(records) == 0)
95+
Expect(len(records)).To(Equal(0))
10096
})
10197
})
10298

@@ -106,25 +102,25 @@ var _ = Describe("GitLedger", func() {
106102
slug := "sclopio/peepio"
107103
record := Record{Path: path, Slug: slug}
108104
expected := fmt.Sprintf("[[Record]]\npath = \"%s\"\nslug = \"%s\"\n\n", record.Path, record.Slug)
109-
Expect(record.String() == expected)
105+
Expect(record.String()).To(Equal(expected))
110106
})
111107

112108
Specify("should be index-able by slug", func() {
113109
rec, _ := GetBySlug("fill")
114-
Expect(rec == r)
110+
Expect(rec).To(Equal(r))
115111
rec, _ = GetBySlug("pony/fill")
116-
Expect(rec == r)
112+
Expect(rec).To(Equal(r))
117113
rec, _ = GetBySlug("badger")
118-
Expect(rec == s)
114+
Expect(rec).To(Equal(s))
119115
})
120116

121117
Specify("should be index-able by path", func() {
122-
rec, _ := GetBySlug("/tmp")
123-
Expect(rec == r)
124-
rec, _ = GetBySlug("/home")
125-
Expect(rec == s)
126-
_, err := GetBySlug("DNE")
127-
Expect(err != nil)
118+
rec, _ := GetByPath("/tmp")
119+
Expect(rec).To(Equal(r))
120+
rec, _ = GetByPath("/home")
121+
Expect(rec).To(Equal(s))
122+
_, err := GetByPath("DNE")
123+
Expect(err).ToNot(BeNil())
128124
})
129125
})
130126

@@ -146,11 +142,11 @@ var _ = Describe("GitLedger", func() {
146142

147143
Specify("should identify as such", func() {
148144
os.MkdirAll(gitdir, os.ModePerm)
149-
Expect(IsGitProject(dir))
145+
Ω(IsGitProject(dir)).Should(BeTrue())
150146
})
151147

152148
Specify("should be differentiable from non-git repositories", func() {
153-
Expect(!IsGitProject(dir))
149+
Ω(IsGitProject(dir)).Should(BeFalse())
154150
})
155151
})
156152
})

0 commit comments

Comments
 (0)