GithubHelp home page GithubHelp logo

marcialwushu / yadda Goto Github PK

View Code? Open in Web Editor NEW

This project forked from acuminous/yadda

0.0 2.0 0.0 1.91 MB

A BDD javascript library

JavaScript 93.34% Batchfile 0.09% Shell 0.50% Gherkin 6.06% Ruby 0.01%

yadda's Introduction

Yadda

Gitter NPM version NPM downloads Build Status Code Climate Test Coverage Code Style Dependency Status devDependencies Status

Jasmine, Mocha and Vows can fall out of date and are a form of duplication. Yadda brings true BDD to JavaScript frameworks such as Jasmine, Mocha, QUnit, Nodeunit, WebdriverIO and CasperJS. By true BDD we mean that the ordinary language (e.g. English) steps are mapped to code, as opposed to simply decorating it. This is important because just like comments, the decorative steps such as those used by

Yadda's BDD implementation is like Cucumber's in that it maps the ordinary language steps to code. Not only are the steps less likely to go stale, but they also provide a valuable abstraction layer and encourage re-use. You could of course just use CucumberJS, but we find Yadda less invasive and prefer it's flexible syntax to Gherkin's. Yadda's conflict resolution is smarter too.

Latest Version

The current version of Yadda is 1.4.0

Documentation

Please refer to the the Yadda User Guide.

tl;dr

Step 1 - Decide upon a directory structure, e.g.

.
├── bottles-test.js
├── lib
│    └── wall.js
└── test
    ├── features
    │   └── bottles.feature
    └── steps
        └── bottles-library.js

Step 2 - Write your first scenario

./test/features/bottles.feature

Feature: 100 Green Bottles

Scenario: Should fall from the wall

   Given 100 green bottles are standing on the wall
   When 1 green bottle accidentally falls
   Then there are 99 green bottles standing on the wall

Step 3 - Implement the step library

./test/steps/bottles-library.js

var assert = require('assert');
var English = require('yadda').localisation.English;
var Wall = require('../../lib/wall'); // The library that you wish to test

module.exports = (function() {
  return English.library()
    .given("$NUM green bottles are standing on the wall", function(number, next) {
       wall = new Wall(number);
       next();
    })
    .when("$NUM green bottle accidentally falls", function(number, next) {
       wall.fall(number);
       next();
    })
    .then("there are $NUM green bottles standing on the wall", function(number, next) {
       assert.equal(number, wall.bottles);
       next();
    });
})();

(If your test runner & code are synchronous you can omit the calls to 'next')

Step 4 - Integrate Yadda with your testing framework (e.g. Mocha)

./bottles-test.js

var Yadda = require('yadda');
Yadda.plugins.mocha.StepLevelPlugin.init();

new Yadda.FeatureFileSearch('./test/features').each(function(file) {

  featureFile(file, function(feature) {

    var library = require('./test/steps/bottles-library');
    var yadda = Yadda.createInstance(library);

    scenarios(feature.scenarios, function(scenario) {
      steps(scenario.steps, function(step, done) {
        yadda.run(step, done);
      });
    });
  });
});

Step 5 - Write your code

./lib/wall.js

module.exports = function(bottles) {
  this.bottles = bottles;
  this.fall = function(n) {
    this.bottles -= n;
  }
};

Step 6 - Run your tests

  mocha --reporter spec bottles-test.js

  100 Green Bottles
    Should fall from the wall
      ✓ Given 100 green bottles are standing on the wall
      ✓ When 1 green bottle accidentally falls
      ✓ Then there are 99 green bottles standing on the wall

yadda's People

Contributors

chrisns avatar albanminassian avatar prokls avatar remkoboschker avatar christian-bromann avatar n1k0 avatar prust avatar bogus34 avatar exon avatar brianjmiller avatar marketionist avatar gblosser42 avatar hans-d avatar jcsrb avatar johntron avatar lloydwatkin avatar meisterluk avatar mgijsbertihodenpijl avatar mortonfox avatar punkchameleon avatar pmpuro avatar raulmb avatar snowyu avatar robfletcher avatar smarigowda avatar simoami avatar radioactivemouse avatar akikhtenko avatar datchung avatar feliun avatar

Watchers

James Cloos avatar Cleilson avatar

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.