bdd stories add-on for mocha test framework with cucumber given/then/when syntax.
Provides high-level/functional/acceptance test organization lingo, using 'Feature', Stories, 'Scenarios', 'Given/Then/When'.
Mocha-Cakes extends Mocha, by adding on helpful commands and print-outs for Acceptance Tests. (Given, When, Then, etc.)
Scenario (maps to describe)
Then (maps to it, but if first message argument is ommited, it'll be a describe)
I (maps to it but if first message argument is ommited, it'll be a describe)
GWTab commands can map to a describe if the message argument is ommited.
Given 'I am at home'-> # it's an ithomeshouldeql 'home'Given -> # it's a describeit 'is dark'->outsideshouldeql 'dark'
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'->
Describe (maps to describe used for things like filenames)
Describe 'lib/file.coffee' # filenamedescribe '+copy()'->it 'should copy files...'->
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', ->
require 'mocha-cakes'Feature "New Feature""In order to use cool feature""as a new user""I want do include this"->Scenario "Singing"->voice = nullGiven "I am a good singing"->When "I sing"->voice = 'good'Then "it should sound good"->it 'sound good'->voiceshouldeql 'good'
Run this test using mocha command:
mocha test.coffee -R spec -r should
Mocha-cakes gives you access to function names
"Feature", "Scenario" that wraps around mocha's
"Given", "When", "Then", "And", "But" wraps around mocha's
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
So the above would output something like:
Feature: New FeatureIn order to use cool featureas a new userI want do include thisScenario: Singing✓ Given: I am a good singing✓ When: I sing✓ Then: it should sound good✓ sound good✔ 1 tests complete (3ms)
Mocha-Cakes provides GWT commands to mocha, and pretty prints it.
To use just:
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 -R spec -r mocha-cakes acceptance_tests.coffee
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 -> # PreviousWhen "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
Also you could still mix-in regular mocha syntax
Feature "Mix & Match" ->Scenario 'Mix-in Mocha', ->Given "I'm using Cakes", ->Then ->describe 'Also using regular mocha', ->I 'should be able to do this', ->true.should.be trueit 'should work too', ->true.should.be true
cd my_project npm -d install mocha-cakes
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.
*Special Thanks* to TJ Holowaychuk for Mocha, awesome test framework.