forked from keronsen/jack
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Started to implement jack.matchers. So far: is(), isNot(), matches(),…
… hasProperty(), hasProperties() git-svn-id: http://boss.bekk.no/repos/projects/jack/trunk@4987 43881228-ca37-0410-962c-81b306aa3a78
- Loading branch information
Showing
7 changed files
with
459 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,11 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<projectDescription> | |||
<name>Jack</name> | |||
<comment></comment> | |||
<projects> | |||
</projects> | |||
<buildSpec> | |||
</buildSpec> | |||
<natures> | |||
</natures> | |||
</projectDescription> |
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
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
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,54 @@ | |||
|
|||
/* | |||
describe('FunctionInvocation class', { | |||
'Class should exist': function() { | |||
var inv = new jack.FunctionInvocation(); | |||
value_of(inv).should_not_be_undefined(); | |||
} | |||
, | |||
'Should have test() method': function() { | |||
var inv = new jack.FunctionInvocation(); | |||
var result = inv.test(); | |||
value_of(result).should_be_true(); | |||
} | |||
, | |||
'Should specify that no arguments are expected': function() { | |||
var inv = new jack.FunctionInvocation(); | |||
inv.withNoArguments(); | |||
value_of(inv.test()).should_be_true(); | |||
value_of(inv.test("foo")).should_be_false(); | |||
} | |||
, | |||
'Should check for equal strings': function() { | |||
var inv = new jack.FunctionInvocation(); | |||
inv.withArguments("argValue1","argValue2"); | |||
value_of(inv.test("foo","bar")).should_be_false(); | |||
value_of(inv.test("argValue1","argValue2")).should_be_true(); | |||
} | |||
, | |||
'whereArgument(n) should return all available matchers from jack.matchers': function() { | |||
var inv = new jack.FunctionInvocation(); | |||
var matchers = inv.whereArgument(0); | |||
value_of(matchers).should_not_be_undefined(); | |||
for(var m in jack.matchers) { | |||
value_of(typeof matchers[m]).should_be("function"); | |||
} | |||
} | |||
/* | |||
, | |||
'Should check for equal numbers': function() { | |||
jack(function(){ | |||
jack.expect("globalFunctionOne").exactly("1 time").withArguments(1234,5678); | |||
jack.expect("globalFunctionTwo").exactly("1 time").withArguments(1234,5678); | |||
window.globalFunctionOne(1111, 5555); | |||
window.globalFunctionTwo(1234, 5678); | |||
}); | |||
value_of(jack.report("globalFunctionOne").actual).should_be(0); | |||
value_of(jack.report("globalFunctionTwo").actual).should_be(1); | |||
} | |||
*/ | |||
}); | |||
|
|||
*/ |
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,172 @@ | |||
|
|||
|
|||
describe('Matching objects', { | |||
'Namespace should exist': function() { | |||
value_of(jack.matchers).should_not_be_undefined(); | |||
} | |||
, | |||
'is() should match on equal strings': function() { | |||
value_of(jack.matchers.is("foo", "foo").result).should_be_true(); | |||
} | |||
, | |||
'is() should not match on unequal strings': function() { | |||
value_of(jack.matchers.is("foo", "bar").result).should_be_false(); | |||
} | |||
, | |||
'is() should match on equal numbers': function() { | |||
value_of(jack.matchers.is(1, 1).result).should_be_true(); | |||
} | |||
, | |||
'is() should not match on unequal numbers': function() { | |||
value_of(jack.matchers.is(1, 2).result).should_be_false(); | |||
} | |||
, | |||
'is() should match on equal booleans': function() { | |||
value_of(jack.matchers.is(true, true).result).should_be_true(); | |||
} | |||
, | |||
'is() should not match on unequal booleans': function() { | |||
value_of(jack.matchers.is(true, false).result).should_be_false(); | |||
} | |||
, | |||
'is() should match on equal object references': function() { | |||
var obj1 = {}; | |||
value_of(jack.matchers.is(obj1, obj1).result).should_be_true(); | |||
} | |||
, | |||
'is() should not match on unequal object references': function() { | |||
var obj1 = {}; | |||
var obj2 = {}; | |||
value_of(jack.matchers.is(obj1, obj2).result).should_be_false(); | |||
} | |||
, | |||
'isNot() should not match on equal strings': function() { | |||
value_of(jack.matchers.isNot("foo", "foo").result).should_be_false(); | |||
} | |||
, | |||
'isNot() should match on unequal strings': function() { | |||
value_of(jack.matchers.isNot("foo", "bar").result).should_be_true(); | |||
} | |||
, | |||
'isNot() should not match on equal numbers': function() { | |||
value_of(jack.matchers.isNot(1, 1).result).should_be_false(); | |||
} | |||
, | |||
'isNot() should match on unequal numbers': function() { | |||
value_of(jack.matchers.isNot(1, 2).result).should_be_true(); | |||
} | |||
, | |||
'isNot() should not match on equal booleans': function() { | |||
value_of(jack.matchers.isNot(true, true).result).should_be_false(); | |||
} | |||
, | |||
'isNot() should match on unequal booleans': function() { | |||
value_of(jack.matchers.isNot(true, false).result).should_be_true(); | |||
} | |||
, | |||
'isNot() should not match on equal object references': function() { | |||
var obj1 = {}; | |||
value_of(jack.matchers.isNot(obj1, obj1).result).should_be_false(); | |||
} | |||
, | |||
'isNot() should match on unequal object references': function() { | |||
var obj1 = {}; | |||
var obj2 = {}; | |||
value_of(jack.matchers.isNot(obj1, obj2).result).should_be_true(); | |||
} | |||
, | |||
'matches() should match with regular expressions': function() { | |||
var testString = "Homer Simpson is 40 years old..."; | |||
value_of(jack.matchers.matches(testString, /Homer/).result).should_be_true(); | |||
value_of(jack.matchers.matches(testString, /Flanders/).result).should_be_false(); | |||
value_of(jack.matchers.matches(testString, /^Homer/).result).should_be_true(); | |||
value_of(jack.matchers.matches(testString, /Simpson$/).result).should_be_false(); | |||
value_of(jack.matchers.matches(testString, /\d{2}/).result).should_be_true(); | |||
value_of(jack.matchers.matches(testString, /\d{3}/).result).should_be_false(); | |||
} | |||
, | |||
'hasProperty(a, b) should match if b is a property of a': function() { | |||
value_of(jack.matchers.hasProperty({property1:'value1'}, "property1").result).should_be_true(); | |||
} | |||
, | |||
'hasProperty(a, b) should not match if b is not a property of a': function() { | |||
value_of(jack.matchers.hasProperty({property1:'value1'}, "property2").result).should_be_false(); | |||
} | |||
, | |||
'hasProperty(a, b, c) should match if b is a property of a with value c': function() { | |||
value_of(jack.matchers.hasProperty({property1:'value1'}, "property1", "value1").result).should_be_true(); | |||
} | |||
, | |||
'hasProperty(a, b, c) should not match if b is a property of a with a value other than c': function() { | |||
value_of(jack.matchers.hasProperty({property1:'value1'}, "property1", "value2").result).should_be_false(); | |||
} | |||
, | |||
'hasProperty(a, b, c) should not match if b is not a property of a': function() { | |||
value_of(jack.matchers.hasProperty({property1:'value1'}, "property2", "value2").result).should_be_false(); | |||
} | |||
, | |||
'hasProperties() should match if all properties have the expected values': function() { | |||
var objectUnderTest = { | |||
property1: 'value1', | |||
property2: 'value2' | |||
} | |||
var propertyCheck = { | |||
property1: 'value1', | |||
property2: 'value2' | |||
} | |||
value_of(jack.matchers.hasProperties(objectUnderTest, propertyCheck).result).should_be_true(); | |||
} | |||
, | |||
'hasProperties() should not match if one of the properties have the wrong value': function() { | |||
var objectUnderTest = { | |||
property1: 'value1', | |||
property2: 'value2' | |||
} | |||
var propertyCheck = { | |||
property1: 'value1', | |||
property2: 'somethingElse' | |||
} | |||
value_of(jack.matchers.hasProperties(objectUnderTest, propertyCheck).result).should_be_false(); | |||
} | |||
, | |||
'hasProperties() should not match if one of the properties is missing': function() { | |||
var objectUnderTest = { | |||
property1: 'value1' | |||
} | |||
var propertyCheck = { | |||
property1: 'value1', | |||
property2: 'value2' | |||
} | |||
value_of(jack.matchers.hasProperties(objectUnderTest, propertyCheck).result).should_be_false(); | |||
} | |||
, | |||
'hasProperties() should match if the object has extra properties': function() { | |||
var objectUnderTest = { | |||
property1: 'value1', | |||
property2: 'value2', | |||
property3: 'value3' | |||
} | |||
var propertyCheck = { | |||
property1: 'value1', | |||
property2: 'value2' | |||
} | |||
value_of(jack.matchers.hasProperties(objectUnderTest, propertyCheck).result).should_be_true(); | |||
} | |||
}); | |||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
Oops, something went wrong.