{"id":18931042,"url":"https://github.com/rendro/mocha-given","last_synced_at":"2025-04-15T16:32:18.807Z","repository":{"id":12261507,"uuid":"14879479","full_name":"rendro/mocha-given","owner":"rendro","description":"Adds a Given/When/Then DSL to mocha as an alternative style for specs","archived":false,"fork":false,"pushed_at":"2017-02-22T18:42:51.000Z","size":50,"stargazers_count":22,"open_issues_count":12,"forks_count":5,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-10-07T07:59:03.457Z","etag":null,"topics":["bdd","given","mocha","testing"],"latest_commit_sha":null,"homepage":"","language":"CoffeeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rendro.png","metadata":{"files":{"readme":"readme.md","changelog":"changelog.md","contributing":null,"funding":null,"license":"license.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-12-03T00:48:30.000Z","updated_at":"2024-09-25T22:09:09.000Z","dependencies_parsed_at":"2022-09-09T12:02:39.859Z","dependency_job_id":null,"html_url":"https://github.com/rendro/mocha-given","commit_stats":null,"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rendro%2Fmocha-given","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rendro%2Fmocha-given/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rendro%2Fmocha-given/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rendro%2Fmocha-given/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rendro","download_url":"https://codeload.github.com/rendro/mocha-given/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223644791,"owners_count":17178765,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bdd","given","mocha","testing"],"created_at":"2024-11-08T11:40:15.714Z","updated_at":"2024-11-08T11:40:16.236Z","avatar_url":"https://github.com/rendro.png","language":"CoffeeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mocha-given\n\n[![Build Status](https://travis-ci.org/rendro/mocha-given.png?branch=development)](https://travis-ci.org/rendro/mocha-given)\n[![NPM version](https://badge.fury.io/js/mocha-given.png)](http://badge.fury.io/js/mocha-given)\n\nMocha-given is a mocha interface that helps you write cleaner specs using `Given`, `When`, `Then` and `And`.\nIt is a shameless port of Justin Searls' [jasmine-given](https://github.com/searls/jasmine-given) which is a tribute to Jim Weirich's terrific [rspec-given](https://github.com/jimweirich/rspec-given) gem.\n\n## Example Specs\n\n``` coffeescript\ndescribe 'assigning stuff to this', -\u003e\n\tGiven -\u003e @number = 24\n\tWhen  -\u003e @number++\n\tAnd   -\u003e @number *= 2\n\tThen  -\u003e @number == 50\n\ndescribe 'assigning stuff to variables', -\u003e\n\tsubject = null\n\tGiven -\u003e subject = []\n\tWhen  -\u003e subject.push('foo')\n\tThen  -\u003e subject.length == 1\n\ndescribe 'Testing deferred', -\u003e\n\tGiven -\u003e @t = Date.now()\n\tThen.after 1500, 'so much time has passed', -\u003e Date.now() - @t \u003e= 1500\n\ndescribe 'Testing async', -\u003e\n\tGiven -\u003e @subject = new User()\n\tThen 'save user', (done) -\u003e @subject.save(done);\n```\n\n## Run tests\n\n### Global installation of mocha\n\nIf you have mocha installed globally you need to install mocha-given globally as well.\n```\n$ npm install -g mocha mocha-given\n```\nThen you can run your tests by setting the interface of mocha to mocha-given\n```\n$ mocha -u mocha-given --compilers coffee:coffee-script -R spec\n```\n### Local installation of mocha\n\nIf you have installed mocha and mocha-given locally\n```\n$ npm install mocha-given coffee-script\n```\nyou have to call the mocha binary directly:\n```\n$ ./node_modules/.bin/mocha -u mocha-given --compilers coffee:coffee-script -R spec\n```\n\n## Run mocha-given tests \u0026 start contributing\n\nTo run the `mocha-given` tests for developing, it has to be symlinked into the `node_modules` folder to enable `mocha` to resolve `mocha-given`.\n\nTherefore run the script:\n\n```\n$ npm run link\n```\n\nAfterwards `mocha` has to be installed with ` $ npm install mocha`.\n\nNow you can run the tests using `$ npm tests` and start contributing.\n\n## Run tests programmatically\n\n``` javascript\nvar Mocha = require('mocha');\nvar fs    = require('fs');\nvar path  = require('path');\n\n// require mocha-given after Mocha is set\nrequire('mocha-given');\n\n// the directory with your tests/specs\nvar testDir = 'tests';\n\n// First, you need to instantiate a Mocha instance.\nvar mocha = new Mocha({\n\tui: 'mocha-given',\n\treporter: 'spec'\n});\n\n// Get test files\nfs.readdirSync(testDir).filter(function(file){\n\t// allow javascript and coffescript files\n\treturn file.match(/\\.(coffee|js)$/);\n}).forEach(function(file){\n\tmocha.addFile(\n\t\tpath.join(testDir, file)\n\t);\n});\n\n// Now, you can run the tests.\nmocha.run(function(failures){\n  process.on('exit', function () {\n\tprocess.exit(failures);\n  });\n});\n```\n\nRun from command line (with mocha and mocha-given installed):\n\n```\n$ node runtests.js\n```\n\nCredits\n-------\n\nThanks to [SinnerSchrader](http://www.sinnerschrader.com/) for their support and the time to work on this project.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frendro%2Fmocha-given","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frendro%2Fmocha-given","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frendro%2Fmocha-given/lists"}