-
-
Notifications
You must be signed in to change notification settings - Fork 660
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
83bb20e
commit fc0e44e
Showing
3 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package books_test | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/ginkgo/example/books" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("Book", func() { | ||
var ( | ||
longBook Book | ||
shortBook Book | ||
) | ||
|
||
BeforeEach(func() { | ||
longBook = Book{ | ||
Title: "Les Miserables", | ||
Author: "Victor Hugo", | ||
Pages: 1488, | ||
} | ||
|
||
shortBook = Book{ | ||
Title: "Fox In Socks", | ||
Author: "Dr. Seuss", | ||
Pages: 24, | ||
} | ||
}) | ||
|
||
Describe("Categorizing book length", func() { | ||
Context("With more than 300 pages", func() { | ||
It("should be a novel", func() { | ||
Expect(longBook.CategoryByLength()).To(Equal("NOVEL")) | ||
}) | ||
}) | ||
|
||
Context("With fewer than 300 pages", func() { | ||
It("should be a short story", func() { | ||
Expect(shortBook.CategoryByLength()).To(Equal("SHORT STORY")) | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package books | ||
|
||
type Book struct { | ||
Title string | ||
Author string | ||
Pages int | ||
} | ||
|
||
func (b *Book) CategoryByLength() string { | ||
|
||
if b.Pages >= 300 { | ||
return "NOVEL" | ||
} | ||
|
||
return "SHORT STORY" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package books_test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestBooks(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Books Suite") | ||
} |