Factories for your Go structs. Think factory_girl.
Switch branches/tags
Nothing to show
Clone or download
modocache Add LICENSE
Closes #1.
Latest commit 1a22577 Feb 26, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore Initial commit May 10, 2014
LICENSE Add LICENSE Feb 26, 2018
README.md README: Add BuildWithParams() example May 11, 2014
definitions.go gory.go: Add BuildWithParams() May 11, 2014
factory.go gory.go: Add BuildWithParams() May 11, 2014
gory.go gory.go: Add BuildWithParams() May 11, 2014
gory_suite_test.go Add lazy fields May 11, 2014
gory_test.go gory.go: Add BuildWithParams() May 11, 2014
lazy.go Add lazy fields May 11, 2014
sequence.go Add lazy fields May 11, 2014

README.md

gory

Build Status Coverage Status GoDoc

Factories for your Go structs. Think factory_girl.

Usage

To install, just go get it:

go get github.com/modocache/gory

gory is fully documented, but below are some examples to get you started.

Defining Factories

Define factories that may be used during any test. Works great in a global setup hook.

gory.Define("user", User{}, func(factory gory.Factory) {
    factory["FirstName"] = "John"
    factory["LastName"] = "Doe"
    factory["Admin"] = false

    // 'n' in email is incremented each time the factory is built
    factory["Email"] = gory.Sequence(func(n int) interface{} {
        return fmt.Sprintf("john-doe-%d@example.com", n)
    })

    // time.Now() is evaluated when the factory is built
    factory["Created"] = gory.Lazy(func() interface{} {
        return time.Now()
    })
})

See gory_suite_test.go for more examples of defining factories.

Using Factories

john := gory.Build("user").(*User)
fmt.Println(john.FirstName) // "John"

jane := gory.BuildWithParams("user", gory.Factory{
    "FirstName": "Jane"
}).(*User)
fmt.Println(jane.FirstName) // "Jane"

See gory_test.go for more examples of using factories.

Coming Soon