Last active
December 9, 2015 21:59
-
-
Save fivetanley/4334633 to your computer and use it in GitHub Desktop.
Lol qunit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Test | |
| constructor: (@description,@body,@context) -> | |
| run: => | |
| test.call @context, @description, => @body.call @context | |
| class Suite | |
| capitalize = (string) -> | |
| string[0].toUpperCase() + string.slice(1) | |
| each = ( collection, fn ) -> | |
| for item in collection | |
| fn( item ) | |
| HOOK_TYPES = [ 'beforeEach', 'beforeAll', 'afterEach', 'afterAll' ] | |
| constructor: (@name)-> | |
| for hookType in HOOK_TYPES | |
| @[ "#{hookType}Hooks" ] = [] | |
| @tests = [] | |
| test: (description, testBody) => | |
| @tests.push new Test( description,testBody,this ) | |
| describe: (description, suiteBody) => | |
| nestedSuite = new Suite @name+description.toString() | |
| suiteBody.call nestedSuite | |
| @tests.push nestedSuite | |
| context: (description, suiteBody) => @describe( description, suiteBody ) | |
| it: ( description, testBody ) => | |
| @test description, testBody | |
| before: (allOrEach, hookBody ) => | |
| @["before#{capitalize(allOrEach)}" ] hookBody | |
| after: (allOrEach, hookBody ) => | |
| @["after#{capitalize(allOrEach)}" ] hookBody | |
| beforeAll: (fn) => | |
| @beforeAllHooks.push fn | |
| afterAll: (fn) => | |
| @afterAllHooks.push fn | |
| afterEach: (fn) => | |
| @afterEachHooks.push fn | |
| beforeEach: (fn) => | |
| @beforeEachHooks.push fn | |
| run: => | |
| each @beforeAllHooks, ( hook ) => hook.call( this ) | |
| each @tests, ( example ) => | |
| module @name.toString() | |
| each @beforeEachHooks, (hook) => hook.call( this ) | |
| example.run() | |
| each @afterEachHooks, ( hook ) => hook.call this | |
| each @afterEachHooks, ( hook ) => hook.call this | |
| @tests = [] | |
| suite = new Suite( 'FullAssignmentView' ) | |
| suite.beforeEach -> | |
| @assignment = new Assignment() | |
| suite.describe "#someMethod", -> | |
| @beforeEach -> @assignment = "hi" | |
| @it "does something", -> | |
| ok @assignment | |
| @describe "NESTING WE MUST GO DEEPER", -> | |
| ok 'deeeeeeper' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment