Last active
May 20, 2016 17:21
-
-
Save aliaspooryorik/749470cdb3eee19f6671 to your computer and use it in GitHub Desktop.
TestBox BDD template
This file contains 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
component extends="testbox.system.BaseSpec" { | |
function beforeAll() { | |
variables.foo = true; | |
variables.moo = 1; | |
} | |
function run() { | |
describe("test callback", function() { | |
var isEven = function(i) { | |
return i % 2 == 0 ? 'Even' : 'Odd'; | |
}; | |
var cut = createStub(); | |
it("should work with $callback", function() { | |
cut.$("isEven").$callback(isEven); | |
expect(cut.isEven(1)).toBe('Odd'); | |
expect(cut.isEven(2)).toBe('Even'); | |
}); | |
it("should accept callback argument", function() { | |
cut.$(method="isEven", callback=isEven); | |
expect(cut.isEven(3)).toBe('Odd'); | |
expect(cut.isEven(4)).toBe('Even'); | |
}); | |
it("callback should accept closure", function() { | |
cut.$("fullName").$callback(function(forename, lastname) { | |
return forename & " " & lastname; | |
}); | |
expect(cut.fullName("John", "Whish")).toBe('John Whish'); | |
}); | |
}); | |
describe("test scope", function() { | |
var bar = true; | |
var baz = true; | |
beforeEach(function() { | |
baz = false; | |
cut = duplicate(variables.moo); | |
cut++; | |
}); | |
it("foo should be true as set in beforeAll", function() { | |
expect(variables.foo).toBe(true); | |
}); | |
it("bar should be true as set in describe scope", function() { | |
expect(bar).toBe(true); | |
}); | |
it("baz should be set to false in the beforeEach", function() { | |
expect(baz).toBe(false); | |
}); | |
it("cut to be one greater than moo", function() { | |
expect(cut).toBe(2); | |
}); | |
it("cut to be one greater than moo", function() { | |
expect(cut).toBe(2); | |
}); | |
it("moo to be one", function() { | |
expect(moo).toBe(1); | |
}); | |
describe("nested test scope", function() { | |
var zoo = 1; | |
beforeEach(function() { | |
cut++; | |
}); | |
it("foo should be true as set in beforeAll", function() { | |
expect(variables.foo).toBe(true); | |
}); | |
it("bar should be true as set in describe scope", function() { | |
expect(bar).toBe(true); | |
}); | |
it("baz should be set to false in the beforeEach", function() { | |
expect(baz).toBe(false); | |
}); | |
it("zoo should be set to 1 in the nested describe", function() { | |
expect(zoo).toBe(1); | |
}); | |
it("cut to be one greater than moo", function() { | |
expect(cut).toBe(3); | |
}); | |
it("cut to be one greater than moo", function() { | |
expect(cut).toBe(3); | |
}); | |
it("moo to be one", function() { | |
expect(moo).toBe(1); | |
}); | |
}); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment