From f597800d7663c786211631bc94a632f0b9f63673 Mon Sep 17 00:00:00 2001 From: Jian Zhang Date: Tue, 2 Apr 2019 16:50:15 +0800 Subject: [PATCH] add books package --- example/books/book_test.go | 42 +++++++++++++++++++++++++++++++ example/books/books.go | 16 ++++++++++++ example/books/books_suite_test.go | 13 ++++++++++ 3 files changed, 71 insertions(+) create mode 100644 example/books/book_test.go create mode 100644 example/books/books.go create mode 100644 example/books/books_suite_test.go diff --git a/example/books/book_test.go b/example/books/book_test.go new file mode 100644 index 000000000..5ec5f2ade --- /dev/null +++ b/example/books/book_test.go @@ -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")) + }) + }) + }) +}) diff --git a/example/books/books.go b/example/books/books.go new file mode 100644 index 000000000..ea7bb43f3 --- /dev/null +++ b/example/books/books.go @@ -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" +} diff --git a/example/books/books_suite_test.go b/example/books/books_suite_test.go new file mode 100644 index 000000000..269b77872 --- /dev/null +++ b/example/books/books_suite_test.go @@ -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") +}