GithubHelp home page GithubHelp logo

zen's People

Contributors

eduncan911 avatar nerdyworm avatar pranavraja avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

zen's Issues

Enabled BDD Scenarios

I submitted a tiny pull request lately to enable a test. The code below is completely different than that.

My main purpose of forking was to change the code to be more like Dan North's original BDD definitions in his original 2008 introduction of BDD. Aka, the "purist" vision of BDD with Given/When/Then that follows the overall scenario:

Given some initial context (the givens),
When an event occurs,
then ensure some outcomes.

I also come from a .NET background where I was an avid user of Machine.Specifications (aka MSpec) BDD framework and his patterns. More specifically, his very nicely formatted TEXT and HTML outputs that was completely human readable.

Therefore, I present the following updates to Go's Zen BDD Framework: Full Contextual Scenarios

// bdd_test.go
//
func TestBddSceneriosUsingContextAndSpecifications(t *testing.T) {

    Given(t, "a BDD scenario", func(when When) {

        when("an event occurs", func(it It) {
            it("should evaluate to 1", func(expect Expect) {
                expect(1).ToEqual(1)
            })

            it("should also evaluate to 3", func(expect Expect) {
                expect(3).ToEqual(3)
            })

            it("should perform another evaluation", func(expect Expect) {
                expect(4).ToNotEqual(5)
            })

            it("should also perform another evaluation", func(expect Expect) {
                expect("hellow").ToNotEqual("world")
            })
        })

        // common context
        count := 0

        before := func() {
            count++
        }

        after := func() {
            count--
        }

        setup := Setup(before, after)

        when("using Setup() in extended-style", func(it It) {
            it("should increment count to 1", setup(func(expect Expect) {
                expect(count).ToEqual(1)
            }))

            if count != 0 {
                t.Error("In BDD-specs, count should have been reset to zero by the teardown func")
            }
        })
    })
}

Which outputs the following:

 Given a BDD scenario 
   When an event occurs 
     It should evaluate to 1 
     It should also evaluate to 3 
     It should perform another evaluation 
     It should also perform another evaluation 
   When using Setup() in extended-style 
     It should increment count to 1 
PASS
ok      github.com/eduncan911/zen   0.008s

Note my new tests that start at the "Given a BDD scenario". You will also notice that I inserted "Given / When / It" in the output.

If you are interested in a Pull request for these changes, let me know. You can have a look at the changes here:

eduncan911@91df917

In short:

  • extended existing code and keeping it backwards compatible with all existing Zen projects,
  • the only breaking change is any custom formatter(s) will need to implement two new methods,
  • broke apart but also grouped Desc from Titles for all existing,
  • enabled grouping of output indentions

It remains completely compatible with all existing Zen users. Just the output is formatted differently. If you run all tests, you will the output has been tweaked to group multiple existing it() funcs:

eduncanmac1:~/go/src/github.com/eduncan911/zen [master +0 ~5 -0]$ go test
   When Equality Specs 
     It should have an integer equal to itself 
     It should not have any integer equal to nil 
   When Setup Specs 
     It should execute before by incrementing count 
 Given a BDD scenario 
   When an event occurs 
     It should evaluate to 1 
     It should also evaluate to 3 
     It should perform another evaluation 
     It should also perform another evaluation 
   When using Setup() in extended-style 
     It should increment count to 1 
PASS
ok      github.com/eduncan911/zen   0.008s

That runs all existing tests before my changes indicating it remains backwards compatible; then, my new scenario specs are run along side them seamlessly.

Well, there is a breaking change: it is for anyone using custom formatters - I extended the interface to have two additional methods:

type formatter interface {
    PrintContext()
    PrintWhen()
    PrintTitle()
    PrintError(string)
}

You'll need to implement a PrintContext() and PrintWhen(). If anyone really has overwritten the default formatter, I'm sure this will be a welcome upgrade/tweak.

It's also missing documentation which I am happy to add later in another pull request.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.