• Stars
    star
    126
  • Rank 284,543 (Top 6 %)
  • Language
    CoffeeScript
  • License
    MIT License
  • Created almost 13 years ago
  • Updated about 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

(inactive) BDD mocha test framework add-on, stories with Cucumber style Given/When/Then syntax for Node.js

Project is In-Active

Checkout mocha-cakes-2

What is it?

Gherkin-Cucumber syntax add-on for mocha javascript/node test framework for customer acceptance testing.

Provides high-level/functional/acceptance test organization lingo, using 'Feature', Stories, 'Scenarios', 'Given/Then/When'.

Mocha-Cakes Pretty Output

Mocha-Cakes Commands

Mocha-Cakes adds the following commands:

Feature Scenario

Given When Then

And But I

System Describe

You can use these commands to describe your tests & specs, as well as mocha's BDD commands describe, it, before, beforeEach, after, afterEach OR mocha's TDD commands suite, test, setup, teardown, suiteSetup, suiteTeardown

Mocha-Cakes Commands Breakdown

Mocha-Cakes extends Mocha, by adding on helpful commands and print-outs for Acceptance Tests. (Given, When, Then, etc.)

##Acceptance Tests

Feature, Scenario (maps to describe)

Given, When, Then (maps to it, but if first message argument is ommited, it'll be a describe)

And, But, I (maps to it but if first message argument is ommited, it'll be a describe)

GWTab

GWTab commands can map to a describe if the message argument is ommited.

  Given 'I am at home', ->  # it's an it
    home.should.eql 'home'

  Given ->  # it's a describe
    it 'is dark', ->
      outside.should.eql 'dark'

Grey-Box, System Tests

System (if it has a message it'll be an it, if not it'll be a describe with System label, useful for testing (grey box) system resources, database, not directly observable by Customer etc.)

Given ->
  System 'Logged Out', ->

Then ->
  System ->
    it 'should log in', ->

Pretty Commands for Specs/Unit Tests

Describe (maps to describe used for things like filenames)

Describe 'lib/file.coffee'  # filename
  describe '+copy()', ->
    it 'should copy files...', ->

Custom

Mocha-Cakes 0.7 added the I command, to do things like:

Given ->
  I 'have a test', ->
  And 'I have another', ->
Then ->
  I 'should be good', ->
  But 'make sure I am also', ->

Example

Coffee-Script: test.coffee

require 'mocha-cakes'

Feature "New Feature",
  "In order to use cool feature",
  "as a new user",
  "I want do include this", ->

    Scenario "Singing", ->

      voice = null

      Given "I am a good singing", ->
      When "I sing", ->
        voice = 'good'
      Then "it should sound good", ->
        voice.should.eql 'good'

Run this test using mocha command:

mocha test.coffee -R spec -r should --compilers coffee:coffee-script

What's going on?

Mocha-cakes gives you access to function names

"Feature", "Scenario" that wraps around mocha's describe().

"Given", "When", "Then", "And", "But" wraps around mocha's it(). (If first argument is omitted Given -> it'll be a describe())

Also bonus, "Describe" wraps around mocha's describe() also, that could be used at the start of spec files. It prints out in bolded blue header with -R Spec. And System() is a describe or it depending on if first argument is a string or callback.

So the above would output something like:

  Feature: New Feature 

  In order to use cool feature
  as a new user
  I want do include this
    
    Scenario: Singing
      ✓ Given: I am a good singing
      ✓ When: I sing
      ✓ Then: it should sound good
        ✓ sound good  


  ✔ 1 tests complete (3ms)

How to Use

Mocha-Cakes provides GWT commands to mocha, and pretty prints it.

To use just:

  1. require 'mocha-cakes'

Then you will have access to the mocha-cakes commands Feature, Scenario, Given, When, Then, etc.

Also to see the pretty output, use the spec reporter

mocha acceptance_tests.coffee -R spec -r mocha-cakes --compilers coffee:coffee-script

Note: You can use mocha-cakes with plain javascript.

Features

require 'mocha-cakes'

Feature "Big Buttons",
  "As a user",
  "I want big buttons",
  "So it'll be easier to use", ->

    Scenario "On Homepage", ->

      Given "I am a new user", ->
      When "I go to homepage", ->

      And "I scroll down", ->
      Then "I see big buttons", ->
      But "no small text", ->

      Given ->  # Describe
      When "I scroll down more", ->
      And "I reach end of page", ->
      Then "all I see is big buttons", ->

      Describe 'test.spec.coffee', ->

    Scenario false, 'Skip Me', ->

* Remember, they're all either describe()'s or it()

Mix & Match

Also you could still mix-in regular mocha syntax

Feature "Mix & Match" ->
  Scenario 'Mix-in Mocha', ->
    Given "I'm using Mocha-Cakes", ->
    Then ->
      describe 'Also using regular mocha', ->
        I 'should be able to do this', ->
          true.should.be true
        it 'should work too', ->
          true.should.be true

Note you can also test asynchronous code with Mocha-Cakes passing a callback argument to any GWTabi command. (done for example)

Feature "Async tests with Mocha-Cakes", ->
  Given "I want to test async code", ->
  When "I pass 'done' to GWT commands", ->
  Then "It should wait for 'done' to be done.", (done)->
    done()

Reference

The WHY behind TDD/BDD and the HOW with RSpec

Use it

Install:

cd my_project
npm install --save-dev mocha-cakes

Mocha Reporter Support

Mocha-Cakes was developed with the -R spec in mind.

You can use Mocha-Cakes also with the -R doc reporter.

All other reporters should function, but have not been tested.

If you have any questions, issues or comments, please leave them on mocha-cakes' github.

Thanks!


*Special Thanks* to TJ Holowaychuk for Mocha, awesome test framework.

More Repositories

1

awesome-couchdb

CouchDB - curated meta resources & best practices list
175
star
2

hulk-hogan

Hogan.js for Express with support for Template Partials.
CoffeeScript
38
star
3

awesome-angular-learning

🕶️ Awesome Angular Learning Resources, Courses & Examples
30
star
4

shadow-re-frame-simple-example

Clojure
23
star
5

shirt-sizes

React+Redux, shirt size app (Bing API dead)
JavaScript
19
star
6

re-frame-html5-routing

Re-Frame +routes using Bidi & pushy for no-hashes html5 routing
Clojure
15
star
7

create-react-coffee-app

Create-react-app + Coffee-script, starter template
JavaScript
8
star
8

awesome-codepen

Wicked awesome UI/UX examples.
4
star
9

vue-vuex-charts

Demo project, vue.js + vuex + charts.js
JavaScript
4
star
10

awesome-zeitgeist

🔮 Surveys and trends relevant to design & development.
4
star
11

meteor-init

Start of a Meteor Project
CoffeeScript
2
star
12

twin.macro-snowpack-react-emotion-typescript

Example template starter using twin.macro snowpack react emotion typescript
TypeScript
2
star
13

gitpod-dotfiles

Shell
1
star
14

aws-appsync-tutorial-building-reactjs-client-app

JavaScript
1
star
15

shadow-cljs-re-frame

Clojure
1
star
16

bootstrap-sales-page

Demo of Twitter Bootstrap SaaS Sales Page
HTML
1
star
17

storybook_bug-null-callback

TypeScript
1
star
18

connect-mongolian

MongoStore for sessions in connect, using mongolian instead of mongodb-native
JavaScript
1
star
19

wait

Simple utility functions to simplify setTimeout and setInterval
JavaScript
1
star
20

alif

Alphabetical App Code Naming System
Ruby
1
star
21

.qv.space

Spacemacs Colemak Configurations
Emacs Lisp
1
star
22

aria-theory

wai-aria apg testing for popular react ui libraries
MDX
1
star