Skip to content

Commit

Permalink
add books package (#568)
Browse files Browse the repository at this point in the history
  • Loading branch information
jianzhangbjz authored Jun 10, 2020
1 parent 83bb20e commit fc0e44e
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
42 changes: 42 additions & 0 deletions example/books/book_test.go
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"))
})
})
})
})
16 changes: 16 additions & 0 deletions example/books/books.go
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"
}
13 changes: 13 additions & 0 deletions example/books/books_suite_test.go
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")
}

0 comments on commit fc0e44e

Please sign in to comment.