evergreen 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +4 -0
- data/bin/evergreen +18 -0
- data/lib/evergreen.rb +44 -0
- data/lib/evergreen/cli.rb +23 -0
- data/lib/evergreen/evergreen.js +3 -0
- data/lib/evergreen/runner.rb +56 -0
- data/lib/evergreen/server.rb +31 -0
- data/lib/evergreen/spec.rb +60 -0
- data/lib/evergreen/version.rb +3 -0
- data/lib/evergreen/views/list.erb +6 -0
- data/lib/evergreen/views/spec.erb +37 -0
- data/lib/jasmine/MIT.LICENSE +20 -0
- data/lib/jasmine/README.markdown +489 -0
- data/lib/jasmine/Rakefile +146 -0
- data/lib/jasmine/cruise_config.rb +21 -0
- data/lib/jasmine/doc/files.html +460 -0
- data/lib/jasmine/doc/index.html +322 -0
- data/lib/jasmine/doc/symbols/_global_.html +918 -0
- data/lib/jasmine/doc/symbols/jasmine.Block.html +417 -0
- data/lib/jasmine/doc/symbols/jasmine.Clock.html +678 -0
- data/lib/jasmine/doc/symbols/jasmine.Env.html +1169 -0
- data/lib/jasmine/doc/symbols/jasmine.JsApiReporter.html +822 -0
- data/lib/jasmine/doc/symbols/jasmine.Matchers.html +1474 -0
- data/lib/jasmine/doc/symbols/jasmine.MultiReporter.html +394 -0
- data/lib/jasmine/doc/symbols/jasmine.NestedResults.html +710 -0
- data/lib/jasmine/doc/symbols/jasmine.Reporter.html +574 -0
- data/lib/jasmine/doc/symbols/jasmine.Runner.html +710 -0
- data/lib/jasmine/doc/symbols/jasmine.Spec.html +1253 -0
- data/lib/jasmine/doc/symbols/jasmine.Spy.html +855 -0
- data/lib/jasmine/doc/symbols/jasmine.Suite.html +705 -0
- data/lib/jasmine/doc/symbols/jasmine.html +1345 -0
- data/lib/jasmine/doc/symbols/jasmine.util.html +535 -0
- data/lib/jasmine/doc/symbols/src/lib_TrivialReporter.js.html +124 -0
- data/lib/jasmine/doc/symbols/src/src_Block.js.html +29 -0
- data/lib/jasmine/doc/symbols/src/src_Env.js.html +248 -0
- data/lib/jasmine/doc/symbols/src/src_JsApiReporter.js.html +111 -0
- data/lib/jasmine/doc/symbols/src/src_Matchers.js.html +344 -0
- data/lib/jasmine/doc/symbols/src/src_MultiReporter.js.html +36 -0
- data/lib/jasmine/doc/symbols/src/src_NestedResults.js.html +88 -0
- data/lib/jasmine/doc/symbols/src/src_PrettyPrinter.js.html +130 -0
- data/lib/jasmine/doc/symbols/src/src_Queue.js.html +102 -0
- data/lib/jasmine/doc/symbols/src/src_Reporter.js.html +35 -0
- data/lib/jasmine/doc/symbols/src/src_Reporters.js.html +51 -0
- data/lib/jasmine/doc/symbols/src/src_Runner.js.html +75 -0
- data/lib/jasmine/doc/symbols/src/src_Spec.js.html +214 -0
- data/lib/jasmine/doc/symbols/src/src_Suite.js.html +77 -0
- data/lib/jasmine/doc/symbols/src/src_WaitsBlock.js.html +21 -0
- data/lib/jasmine/doc/symbols/src/src_WaitsForBlock.js.html +45 -0
- data/lib/jasmine/doc/symbols/src/src_base.js.html +585 -0
- data/lib/jasmine/doc/symbols/src/src_mock-timeout.js.html +185 -0
- data/lib/jasmine/doc/symbols/src/src_util.js.html +75 -0
- data/lib/jasmine/example/example_runner.html +22 -0
- data/lib/jasmine/example/spec/example_suite.js +11 -0
- data/lib/jasmine/images/fail-16.png +0 -0
- data/lib/jasmine/images/fail.png +0 -0
- data/lib/jasmine/images/go-16.png +0 -0
- data/lib/jasmine/images/go.png +0 -0
- data/lib/jasmine/images/pending-16.png +0 -0
- data/lib/jasmine/images/pending.png +0 -0
- data/lib/jasmine/images/question-bk.png +0 -0
- data/lib/jasmine/images/questionbk-16.png +0 -0
- data/lib/jasmine/images/spinner.gif +0 -0
- data/lib/jasmine/lib/TrivialReporter.js +171 -0
- data/lib/jasmine/lib/consolex.js +28 -0
- data/lib/jasmine/lib/jasmine-0.10.4.js +2371 -0
- data/lib/jasmine/lib/jasmine.css +166 -0
- data/lib/jasmine/lib/json2.js +478 -0
- data/lib/jasmine/spec/jasmine_helper.rb +44 -0
- data/lib/jasmine/spec/jasmine_spec.rb +31 -0
- data/lib/jasmine/spec/runner.html +80 -0
- data/lib/jasmine/spec/saucelabs.yml +24 -0
- data/lib/jasmine/spec/suites/CustomMatchersSpec.js +112 -0
- data/lib/jasmine/spec/suites/EnvSpec.js +158 -0
- data/lib/jasmine/spec/suites/ExceptionsSpec.js +107 -0
- data/lib/jasmine/spec/suites/JsApiReporterSpec.js +96 -0
- data/lib/jasmine/spec/suites/MatchersSpec.js +709 -0
- data/lib/jasmine/spec/suites/MockClockSpec.js +34 -0
- data/lib/jasmine/spec/suites/MultiReporterSpec.js +30 -0
- data/lib/jasmine/spec/suites/NestedResultsSpec.js +54 -0
- data/lib/jasmine/spec/suites/PrettyPrintSpec.js +93 -0
- data/lib/jasmine/spec/suites/QueueSpec.js +23 -0
- data/lib/jasmine/spec/suites/ReporterSpec.js +60 -0
- data/lib/jasmine/spec/suites/RunnerSpec.js +267 -0
- data/lib/jasmine/spec/suites/SpecRunningSpec.js +1195 -0
- data/lib/jasmine/spec/suites/SpecSpec.js +110 -0
- data/lib/jasmine/spec/suites/SpySpec.js +201 -0
- data/lib/jasmine/spec/suites/SuiteSpec.js +120 -0
- data/lib/jasmine/spec/suites/TrivialReporterSpec.js +158 -0
- data/lib/jasmine/spec/suites/UtilSpec.js +40 -0
- data/lib/jasmine/spec/suites/WaitsForBlockSpec.js +88 -0
- data/lib/jasmine/src/Block.js +22 -0
- data/lib/jasmine/src/Env.js +263 -0
- data/lib/jasmine/src/JsApiReporter.js +104 -0
- data/lib/jasmine/src/Matchers.js +336 -0
- data/lib/jasmine/src/MultiReporter.js +28 -0
- data/lib/jasmine/src/NestedResults.js +80 -0
- data/lib/jasmine/src/PrettyPrinter.js +122 -0
- data/lib/jasmine/src/Queue.js +94 -0
- data/lib/jasmine/src/Reporter.js +27 -0
- data/lib/jasmine/src/Reporters.js +43 -0
- data/lib/jasmine/src/Runner.js +77 -0
- data/lib/jasmine/src/Spec.js +206 -0
- data/lib/jasmine/src/Suite.js +82 -0
- data/lib/jasmine/src/WaitsBlock.js +13 -0
- data/lib/jasmine/src/WaitsForBlock.js +37 -0
- data/lib/jasmine/src/base.js +586 -0
- data/lib/jasmine/src/mock-timeout.js +177 -0
- data/lib/jasmine/src/util.js +67 -0
- data/lib/jasmine/src/version.json +5 -0
- metadata +238 -0
@@ -0,0 +1,107 @@
|
|
1
|
+
describe('Exceptions:', function() {
|
2
|
+
var env;
|
3
|
+
|
4
|
+
beforeEach(function() {
|
5
|
+
env = new jasmine.Env();
|
6
|
+
env.updateInterval = 0;
|
7
|
+
});
|
8
|
+
|
9
|
+
it('jasmine.formatException formats Firefox exception messages as expected', function() {
|
10
|
+
var sampleFirefoxException = {
|
11
|
+
fileName: 'foo.js',
|
12
|
+
line: '1978',
|
13
|
+
message: 'you got your foo in my bar',
|
14
|
+
name: 'A Classic Mistake'
|
15
|
+
};
|
16
|
+
|
17
|
+
var expected = 'A Classic Mistake: you got your foo in my bar in foo.js (line 1978)';
|
18
|
+
|
19
|
+
expect(jasmine.util.formatException(sampleFirefoxException)).toEqual(expected);
|
20
|
+
});
|
21
|
+
|
22
|
+
it('jasmine.formatException formats Webkit exception messages as expected', function() {
|
23
|
+
var sampleWebkitException = {
|
24
|
+
sourceURL: 'foo.js',
|
25
|
+
lineNumber: '1978',
|
26
|
+
message: 'you got your foo in my bar',
|
27
|
+
name: 'A Classic Mistake'
|
28
|
+
};
|
29
|
+
|
30
|
+
var expected = 'A Classic Mistake: you got your foo in my bar in foo.js (line 1978)';
|
31
|
+
|
32
|
+
expect(jasmine.util.formatException(sampleWebkitException)).toEqual(expected);
|
33
|
+
});
|
34
|
+
|
35
|
+
it('should handle exceptions thrown, but continue', function() {
|
36
|
+
var fakeTimer = new jasmine.FakeTimer();
|
37
|
+
env.setTimeout = fakeTimer.setTimeout;
|
38
|
+
env.clearTimeout = fakeTimer.clearTimeout;
|
39
|
+
env.setInterval = fakeTimer.setInterval;
|
40
|
+
env.clearInterval = fakeTimer.clearInterval;
|
41
|
+
|
42
|
+
//we run two exception tests to make sure we continue after throwing an exception
|
43
|
+
var suite = env.describe('Suite for handles exceptions', function () {
|
44
|
+
env.it('should be a test that fails because it throws an exception', function() {
|
45
|
+
throw new Error('fake error 1');
|
46
|
+
});
|
47
|
+
|
48
|
+
env.it('should be another test that fails because it throws an exception', function() {
|
49
|
+
this.runs(function () {
|
50
|
+
throw new Error('fake error 2');
|
51
|
+
});
|
52
|
+
this.runs(function () {
|
53
|
+
this.expect(true).toEqual(true);
|
54
|
+
});
|
55
|
+
});
|
56
|
+
|
57
|
+
env.it('should be a passing test that runs after exceptions are thrown', function() {
|
58
|
+
this.expect(true).toEqual(true);
|
59
|
+
});
|
60
|
+
|
61
|
+
env.it('should be another test that fails because it throws an exception after a wait', function() {
|
62
|
+
this.runs(function () {
|
63
|
+
var foo = 'foo';
|
64
|
+
});
|
65
|
+
this.waits(250);
|
66
|
+
this.runs(function () {
|
67
|
+
throw new Error('fake error 3');
|
68
|
+
});
|
69
|
+
});
|
70
|
+
|
71
|
+
env.it('should be a passing test that runs after exceptions are thrown from a async test', function() {
|
72
|
+
this.expect(true).toEqual(true);
|
73
|
+
});
|
74
|
+
});
|
75
|
+
|
76
|
+
var runner = env.currentRunner();
|
77
|
+
suite.execute();
|
78
|
+
fakeTimer.tick(2500);
|
79
|
+
|
80
|
+
var suiteResults = suite.results();
|
81
|
+
var specResults = suiteResults.getItems();
|
82
|
+
|
83
|
+
expect(suiteResults.passed()).toEqual(false);
|
84
|
+
//
|
85
|
+
expect(specResults.length).toEqual(5);
|
86
|
+
expect(specResults[0].passed()).toMatch(false);
|
87
|
+
var blockResults = specResults[0].getItems();
|
88
|
+
expect(blockResults[0].passed()).toEqual(false);
|
89
|
+
expect(blockResults[0].message).toMatch(/fake error 1/);
|
90
|
+
|
91
|
+
expect(specResults[1].passed()).toEqual(false);
|
92
|
+
var blockResults = specResults[1].getItems();
|
93
|
+
expect(blockResults[0].passed()).toEqual(false);
|
94
|
+
expect(blockResults[0].message).toMatch(/fake error 2/),
|
95
|
+
expect(blockResults[1].passed()).toEqual(true);
|
96
|
+
|
97
|
+
expect(specResults[2].passed()).toEqual(true);
|
98
|
+
|
99
|
+
expect(specResults[3].passed()).toEqual(false);
|
100
|
+
blockResults = specResults[3].getItems();
|
101
|
+
expect(blockResults[0].message).toMatch(/fake error 3/);
|
102
|
+
|
103
|
+
expect(specResults[4].passed()).toEqual(true);
|
104
|
+
|
105
|
+
});
|
106
|
+
|
107
|
+
});
|
@@ -0,0 +1,96 @@
|
|
1
|
+
describe('jasmine.jsApiReporter', function() {
|
2
|
+
|
3
|
+
|
4
|
+
describe('results', function () {
|
5
|
+
var reporter, spec1, spec2, spec3, expectedSpec1Results, expectedSpec2Results;
|
6
|
+
var env;
|
7
|
+
var suite, nestedSuite, nestedSpec;
|
8
|
+
|
9
|
+
beforeEach(function() {
|
10
|
+
env = new jasmine.Env();
|
11
|
+
env.updateInterval = 0;
|
12
|
+
|
13
|
+
suite = env.describe("top-level suite", function() {
|
14
|
+
spec1 = env.it("spec 1", function() {
|
15
|
+
this.expect(true).toEqual(true);
|
16
|
+
|
17
|
+
});
|
18
|
+
|
19
|
+
spec2 = env.it("spec 2", function() {
|
20
|
+
this.expect(true).toEqual(false);
|
21
|
+
});
|
22
|
+
|
23
|
+
nestedSuite = env.describe("nested suite", function() {
|
24
|
+
nestedSpec = env.it("nested spec", function() {
|
25
|
+
expect(true).toEqual(true);
|
26
|
+
})
|
27
|
+
});
|
28
|
+
|
29
|
+
spec3 = env.it("spec 3", function() {
|
30
|
+
this.log('some debug message');
|
31
|
+
});
|
32
|
+
});
|
33
|
+
|
34
|
+
reporter = new jasmine.JsApiReporter();
|
35
|
+
env.addReporter(reporter);
|
36
|
+
|
37
|
+
env.execute();
|
38
|
+
});
|
39
|
+
|
40
|
+
xit('resultForSpec() should return the result for the given spec', function () {
|
41
|
+
expect(reporter.resultsForSpec(spec1.id)).toEqual(expectedSpec1Results);
|
42
|
+
expect(reporter.resultsForSpec(spec2.id)).toEqual(expectedSpec2Results);
|
43
|
+
|
44
|
+
});
|
45
|
+
|
46
|
+
xit('results() should return a hash of all results, indexed by spec id', function () {
|
47
|
+
expect(reporter.results()[spec1.id]).toEqual(expectedSpec1Results);
|
48
|
+
expect(reporter.results()[spec2.id]).toEqual(expectedSpec2Results);
|
49
|
+
});
|
50
|
+
|
51
|
+
it("should return nested suites as children of their parents", function() {
|
52
|
+
expect(reporter.suites()).toEqual([
|
53
|
+
{ id: 0, name: 'top-level suite', type: 'suite',
|
54
|
+
children: [
|
55
|
+
{ id: 0, name: 'spec 1', type: 'spec', children: [ ] },
|
56
|
+
{ id: 1, name: 'spec 2', type: 'spec', children: [ ] },
|
57
|
+
{ id: 1, name: 'nested suite', type: 'suite',
|
58
|
+
children: [
|
59
|
+
{ id: 2, name: 'nested spec', type: 'spec', children: [ ] }
|
60
|
+
]
|
61
|
+
},
|
62
|
+
{ id: 3, name: 'spec 3', type: 'spec', children: [ ] }
|
63
|
+
]
|
64
|
+
}
|
65
|
+
]);
|
66
|
+
});
|
67
|
+
|
68
|
+
xdescribe("#summarizeResult_", function() {
|
69
|
+
it("should summarize a passing result", function() {
|
70
|
+
var result = reporter.results()[spec1.id];
|
71
|
+
var summarizedResult = reporter.summarizeResult_(result);
|
72
|
+
expect(summarizedResult.result).toEqual('passed');
|
73
|
+
expect(summarizedResult.messages.length).toEqual(1);
|
74
|
+
expect(summarizedResult.messages[0].message).toEqual(result.messages[0].message);
|
75
|
+
expect(summarizedResult.messages[0].passed).toBeTruthy();
|
76
|
+
expect(summarizedResult.messages[0].type).toEqual('ExpectationResult');
|
77
|
+
expect(summarizedResult.messages[0].text).toEqual(jasmine.undefined);
|
78
|
+
expect(summarizedResult.messages[0].trace.stack).toEqual(jasmine.undefined);
|
79
|
+
});
|
80
|
+
|
81
|
+
it("should have a stack trace for failing specs", function() {
|
82
|
+
var result = reporter.results()[spec2.id];
|
83
|
+
var summarizedResult = reporter.summarizeResult_(result);
|
84
|
+
expect(summarizedResult.result).toEqual('failed');
|
85
|
+
expect(summarizedResult.messages[0].trace.stack).toEqual(result.messages[0].trace.stack);
|
86
|
+
});
|
87
|
+
|
88
|
+
it("should have messages for specs with messages", function() {
|
89
|
+
var result = reporter.results()[spec3.id];
|
90
|
+
var summarizedResult = reporter.summarizeResult_(result);
|
91
|
+
expect(summarizedResult.result).toEqual('passed');
|
92
|
+
expect(summarizedResult.messages[0].text).toEqual('some debug message');
|
93
|
+
});
|
94
|
+
});
|
95
|
+
});
|
96
|
+
});
|
@@ -0,0 +1,709 @@
|
|
1
|
+
describe("jasmine.Matchers", function() {
|
2
|
+
var env, spec;
|
3
|
+
|
4
|
+
beforeEach(function() {
|
5
|
+
env = new jasmine.Env();
|
6
|
+
env.updateInterval = 0;
|
7
|
+
|
8
|
+
var suite = env.describe("suite", function() {
|
9
|
+
spec = env.it("spec", function() {
|
10
|
+
});
|
11
|
+
});
|
12
|
+
spyOn(spec, 'addMatcherResult');
|
13
|
+
});
|
14
|
+
|
15
|
+
function match(value) {
|
16
|
+
return spec.expect(value);
|
17
|
+
}
|
18
|
+
|
19
|
+
function lastResult() {
|
20
|
+
return spec.addMatcherResult.mostRecentCall.args[0];
|
21
|
+
}
|
22
|
+
|
23
|
+
it("toEqual with primitives, objects, dates, html nodes, etc.", function() {
|
24
|
+
expect(match(true).toEqual(true)).toEqual(true);
|
25
|
+
|
26
|
+
expect(match({foo:'bar'}).toEqual(null)).toEqual(false);
|
27
|
+
|
28
|
+
var functionA = function() {
|
29
|
+
return 'hi';
|
30
|
+
};
|
31
|
+
var functionB = function() {
|
32
|
+
return 'hi';
|
33
|
+
};
|
34
|
+
expect(match({foo:functionA}).toEqual({foo:functionB})).toEqual(false);
|
35
|
+
expect(match({foo:functionA}).toEqual({foo:functionA})).toEqual(true);
|
36
|
+
|
37
|
+
expect((match(false).toEqual(true))).toEqual(false);
|
38
|
+
|
39
|
+
var circularGraph = {};
|
40
|
+
circularGraph.referenceToSelf = circularGraph;
|
41
|
+
expect((match(circularGraph).toEqual(circularGraph))).toEqual(true);
|
42
|
+
|
43
|
+
var nodeA = document.createElement('div');
|
44
|
+
var nodeB = document.createElement('div');
|
45
|
+
expect((match(nodeA).toEqual(nodeA))).toEqual(true);
|
46
|
+
expect((match(nodeA).toEqual(nodeB))).toEqual(false);
|
47
|
+
|
48
|
+
expect((match(new Date(2008, 1, 3, 15, 17, 19, 1234)).toEqual(new Date(2009, 1, 3, 15, 17, 19, 1234)))).toEqual(false);
|
49
|
+
expect((match(new Date(2008, 1, 3, 15, 17, 19, 1234)).toEqual(new Date(2008, 1, 3, 15, 17, 19, 1234)))).toEqual(true);
|
50
|
+
|
51
|
+
|
52
|
+
expect(match(true).toNotEqual(false)).toEqual(true);
|
53
|
+
expect((match(true).toNotEqual(true))).toEqual(false);
|
54
|
+
|
55
|
+
expect((match(['a', 'b']).toEqual(['a', jasmine.undefined]))).toEqual(false);
|
56
|
+
expect((match(['a', 'b']).toEqual(['a', 'b', jasmine.undefined]))).toEqual(false);
|
57
|
+
|
58
|
+
expect((match(new String("cat")).toEqual("cat"))).toBe(true);
|
59
|
+
expect((match(new String("cat")).toNotEqual("cat"))).toBe(false);
|
60
|
+
|
61
|
+
expect((match(new Number(5)).toEqual(5))).toBe(true);
|
62
|
+
expect((match(new Number('5')).toEqual(5))).toBe(true);
|
63
|
+
expect((match(new Number(5)).toNotEqual(5))).toBe(false);
|
64
|
+
expect((match(new Number('5')).toNotEqual(5))).toBe(false);
|
65
|
+
});
|
66
|
+
|
67
|
+
it("toEqual to build an Expectation Result", function() {
|
68
|
+
var actual = 'a';
|
69
|
+
var matcher = match(actual);
|
70
|
+
var expected = 'b';
|
71
|
+
matcher.toEqual(expected);
|
72
|
+
|
73
|
+
var result = lastResult();
|
74
|
+
|
75
|
+
expect(result.matcherName).toEqual("toEqual");
|
76
|
+
expect(result.passed()).toEqual(false);
|
77
|
+
expect(result.message).toMatch(jasmine.pp(actual));
|
78
|
+
expect(result.message).toMatch(jasmine.pp(expected));
|
79
|
+
expect(result.expected).toEqual(expected);
|
80
|
+
expect(result.actual).toEqual(actual);
|
81
|
+
});
|
82
|
+
|
83
|
+
it("toNotEqual to build an Expectation Result", function() {
|
84
|
+
var str = 'a';
|
85
|
+
var matcher = match(str);
|
86
|
+
matcher.toNotEqual(str);
|
87
|
+
|
88
|
+
var result = lastResult();
|
89
|
+
|
90
|
+
expect(result.matcherName).toEqual("toNotEqual");
|
91
|
+
expect(result.passed()).toEqual(false);
|
92
|
+
expect(result.message).toMatch(jasmine.pp(str));
|
93
|
+
expect(result.message).toMatch('not');
|
94
|
+
expect(result.expected).toEqual(str);
|
95
|
+
expect(result.actual).toEqual(str);
|
96
|
+
});
|
97
|
+
|
98
|
+
it('toBe should return true only if the expected and actual items === each other', function() {
|
99
|
+
var a = {};
|
100
|
+
var b = {};
|
101
|
+
//noinspection UnnecessaryLocalVariableJS
|
102
|
+
var c = a;
|
103
|
+
expect((match(a).toBe(b))).toEqual(false);
|
104
|
+
expect((match(a).toBe(a))).toEqual(true);
|
105
|
+
expect((match(a).toBe(c))).toEqual(true);
|
106
|
+
expect((match(a).toNotBe(b))).toEqual(true);
|
107
|
+
expect((match(a).toNotBe(a))).toEqual(false);
|
108
|
+
expect((match(a).toNotBe(c))).toEqual(false);
|
109
|
+
});
|
110
|
+
|
111
|
+
it("toBe to build an ExpectationResult", function() {
|
112
|
+
var expected = 'b';
|
113
|
+
var actual = 'a';
|
114
|
+
var matcher = match(actual);
|
115
|
+
matcher.toBe(expected);
|
116
|
+
|
117
|
+
var result = lastResult();
|
118
|
+
|
119
|
+
expect(result.matcherName).toEqual("toBe");
|
120
|
+
expect(result.passed()).toEqual(false);
|
121
|
+
expect(result.message).toMatch(jasmine.pp(actual));
|
122
|
+
expect(result.message).toMatch(jasmine.pp(expected));
|
123
|
+
expect(result.expected).toEqual(expected);
|
124
|
+
expect(result.actual).toEqual(actual);
|
125
|
+
});
|
126
|
+
|
127
|
+
it("toNotBe to build an ExpectationResult", function() {
|
128
|
+
var str = 'a';
|
129
|
+
var matcher = match(str);
|
130
|
+
matcher.toNotBe(str);
|
131
|
+
|
132
|
+
var result = lastResult();
|
133
|
+
|
134
|
+
expect(result.matcherName).toEqual("toNotBe");
|
135
|
+
expect(result.passed()).toEqual(false);
|
136
|
+
expect(result.message).toMatch(str);
|
137
|
+
expect(result.expected).toEqual(str);
|
138
|
+
expect(result.actual).toEqual(str);
|
139
|
+
});
|
140
|
+
|
141
|
+
it("toMatch and #toNotMatch should perform regular expression matching on strings", function() {
|
142
|
+
expect((match('foobarbel').toMatch(/bar/))).toEqual(true);
|
143
|
+
expect((match('foobazbel').toMatch(/bar/))).toEqual(false);
|
144
|
+
|
145
|
+
expect((match('foobarbel').toMatch("bar"))).toEqual(true);
|
146
|
+
expect((match('foobazbel').toMatch("bar"))).toEqual(false);
|
147
|
+
|
148
|
+
expect((match('foobarbel').toNotMatch(/bar/))).toEqual(false);
|
149
|
+
expect((match('foobazbel').toNotMatch(/bar/))).toEqual(true);
|
150
|
+
|
151
|
+
expect((match('foobarbel').toNotMatch("bar"))).toEqual(false);
|
152
|
+
expect((match('foobazbel').toNotMatch("bar"))).toEqual(true);
|
153
|
+
});
|
154
|
+
|
155
|
+
it("toMatch w/ RegExp to build an ExpectationResult", function() {
|
156
|
+
var actual = 'a';
|
157
|
+
var matcher = match(actual);
|
158
|
+
var expected = /b/;
|
159
|
+
matcher.toMatch(expected);
|
160
|
+
|
161
|
+
var result = lastResult();
|
162
|
+
|
163
|
+
expect(result.matcherName).toEqual("toMatch");
|
164
|
+
expect(result.passed()).toEqual(false);
|
165
|
+
expect(result.message).toMatch(jasmine.pp(actual));
|
166
|
+
expect(result.message).toMatch(expected.toString());
|
167
|
+
expect(result.expected).toEqual(expected);
|
168
|
+
expect(result.actual).toEqual(actual);
|
169
|
+
});
|
170
|
+
|
171
|
+
it("toMatch w/ String to build an ExpectationResult", function() {
|
172
|
+
var actual = 'a';
|
173
|
+
var matcher = match(actual);
|
174
|
+
var expected = 'b';
|
175
|
+
matcher.toMatch(expected);
|
176
|
+
|
177
|
+
var result = lastResult();
|
178
|
+
|
179
|
+
expect(result.matcherName).toEqual("toMatch");
|
180
|
+
expect(result.passed()).toEqual(false);
|
181
|
+
expect(result.message).toEqual("Expected 'a' to match 'b'.");
|
182
|
+
expect(result.expected).toEqual(expected);
|
183
|
+
expect(result.actual).toEqual(actual);
|
184
|
+
});
|
185
|
+
|
186
|
+
it("toNotMatch w/ RegExp to build an ExpectationResult", function() {
|
187
|
+
var actual = 'a';
|
188
|
+
var matcher = match(actual);
|
189
|
+
var expected = /a/;
|
190
|
+
matcher.toNotMatch(expected);
|
191
|
+
|
192
|
+
var result = lastResult();
|
193
|
+
|
194
|
+
expect(result.matcherName).toEqual("toNotMatch");
|
195
|
+
expect(result.passed()).toEqual(false);
|
196
|
+
expect(result.message).toEqual("Expected 'a' to not match /a/.");
|
197
|
+
expect(result.expected).toEqual(expected);
|
198
|
+
expect(result.actual).toEqual(actual);
|
199
|
+
});
|
200
|
+
|
201
|
+
it("toNotMatch w/ String to build an ExpectationResult", function() {
|
202
|
+
var str = 'a';
|
203
|
+
var matcher = match(str);
|
204
|
+
matcher.toNotMatch(str);
|
205
|
+
|
206
|
+
var result = lastResult();
|
207
|
+
|
208
|
+
expect(result.matcherName).toEqual("toNotMatch");
|
209
|
+
expect(result.passed()).toEqual(false);
|
210
|
+
expect(result.message).toEqual("Expected 'a' to not match 'a'.");
|
211
|
+
expect(result.expected).toEqual(str);
|
212
|
+
expect(result.actual).toEqual(str);
|
213
|
+
});
|
214
|
+
|
215
|
+
it("toBeDefined", function() {
|
216
|
+
expect(match('foo').toBeDefined()).toEqual(true);
|
217
|
+
expect(match(jasmine.undefined).toBeDefined()).toEqual(false);
|
218
|
+
});
|
219
|
+
|
220
|
+
it("toBeDefined to build an ExpectationResult", function() {
|
221
|
+
var matcher = match(jasmine.undefined);
|
222
|
+
matcher.toBeDefined();
|
223
|
+
|
224
|
+
var result = lastResult();
|
225
|
+
|
226
|
+
expect(result.matcherName).toEqual("toBeDefined");
|
227
|
+
expect(result.passed()).toEqual(false);
|
228
|
+
expect(result.message).toEqual('Expected undefined to be defined.');
|
229
|
+
expect(result.actual).toEqual(jasmine.undefined);
|
230
|
+
});
|
231
|
+
|
232
|
+
it("toBeUndefined", function() {
|
233
|
+
expect(match('foo').toBeUndefined()).toEqual(false);
|
234
|
+
expect(match(jasmine.undefined).toBeUndefined()).toEqual(true);
|
235
|
+
});
|
236
|
+
|
237
|
+
it("toBeNull", function() {
|
238
|
+
expect(match(null).toBeNull()).toEqual(true);
|
239
|
+
expect(match(jasmine.undefined).toBeNull()).toEqual(false);
|
240
|
+
expect(match("foo").toBeNull()).toEqual(false);
|
241
|
+
});
|
242
|
+
|
243
|
+
it("toBeNull w/ String to build an ExpectationResult", function() {
|
244
|
+
var actual = 'a';
|
245
|
+
var matcher = match(actual);
|
246
|
+
matcher.toBeNull();
|
247
|
+
|
248
|
+
var result = lastResult();
|
249
|
+
|
250
|
+
expect(result.matcherName).toEqual("toBeNull");
|
251
|
+
expect(result.passed()).toEqual(false);
|
252
|
+
expect(result.message).toMatch(jasmine.pp(actual));
|
253
|
+
expect(result.message).toMatch('null');
|
254
|
+
expect(result.actual).toEqual(actual);
|
255
|
+
});
|
256
|
+
|
257
|
+
it("toBeNull w/ Object to build an ExpectationResult", function() {
|
258
|
+
var actual = {a: 'b'};
|
259
|
+
var matcher = match(actual);
|
260
|
+
matcher.toBeNull();
|
261
|
+
|
262
|
+
var result = lastResult();
|
263
|
+
|
264
|
+
expect(result.matcherName).toEqual("toBeNull");
|
265
|
+
expect(result.passed()).toEqual(false);
|
266
|
+
expect(result.message).toMatch(jasmine.pp(actual));
|
267
|
+
expect(result.message).toMatch('null');
|
268
|
+
expect(result.actual).toEqual(actual);
|
269
|
+
});
|
270
|
+
|
271
|
+
it("toBeFalsy", function() {
|
272
|
+
expect(match(false).toBeFalsy()).toEqual(true);
|
273
|
+
expect(match(true).toBeFalsy()).toEqual(false);
|
274
|
+
expect(match(jasmine.undefined).toBeFalsy()).toEqual(true);
|
275
|
+
expect(match(0).toBeFalsy()).toEqual(true);
|
276
|
+
expect(match("").toBeFalsy()).toEqual(true);
|
277
|
+
});
|
278
|
+
|
279
|
+
it("toBeFalsy to build an ExpectationResult", function() {
|
280
|
+
var actual = 'a';
|
281
|
+
var matcher = match(actual);
|
282
|
+
matcher.toBeFalsy();
|
283
|
+
|
284
|
+
var result = lastResult();
|
285
|
+
|
286
|
+
expect(result.matcherName).toEqual("toBeFalsy");
|
287
|
+
expect(result.passed()).toEqual(false);
|
288
|
+
expect(result.message).toMatch(jasmine.pp(actual));
|
289
|
+
expect(result.message).toMatch('falsy');
|
290
|
+
expect(result.actual).toEqual(actual);
|
291
|
+
});
|
292
|
+
|
293
|
+
it("toBeTruthy", function() {
|
294
|
+
expect(match(false).toBeTruthy()).toEqual(false);
|
295
|
+
expect(match(true).toBeTruthy()).toEqual(true);
|
296
|
+
expect(match(jasmine.undefined).toBeTruthy()).toEqual(false);
|
297
|
+
expect(match(0).toBeTruthy()).toEqual(false);
|
298
|
+
expect(match("").toBeTruthy()).toEqual(false);
|
299
|
+
expect(match("hi").toBeTruthy()).toEqual(true);
|
300
|
+
expect(match(5).toBeTruthy()).toEqual(true);
|
301
|
+
expect(match({foo: 1}).toBeTruthy()).toEqual(true);
|
302
|
+
});
|
303
|
+
|
304
|
+
it("toBeTruthy to build an ExpectationResult", function() {
|
305
|
+
var matcher = match(false);
|
306
|
+
matcher.toBeTruthy();
|
307
|
+
|
308
|
+
var result = lastResult();
|
309
|
+
|
310
|
+
expect(result.matcherName).toEqual("toBeTruthy");
|
311
|
+
expect(result.passed()).toEqual(false);
|
312
|
+
expect(result.message).toEqual("Expected false to be truthy.");
|
313
|
+
expect(result.actual).toEqual(false);
|
314
|
+
});
|
315
|
+
|
316
|
+
it("toEqual", function() {
|
317
|
+
expect(match(jasmine.undefined).toEqual(jasmine.undefined)).toEqual(true);
|
318
|
+
expect(match({foo:'bar'}).toEqual({foo:'bar'})).toEqual(true);
|
319
|
+
expect(match("foo").toEqual({bar: jasmine.undefined})).toEqual(false);
|
320
|
+
expect(match({foo: jasmine.undefined}).toEqual("goo")).toEqual(false);
|
321
|
+
expect(match({foo: {bar :jasmine.undefined}}).toEqual("goo")).toEqual(false);
|
322
|
+
});
|
323
|
+
|
324
|
+
it("toEqual with jasmine.any()", function() {
|
325
|
+
expect(match("foo").toEqual(jasmine.any(String))).toEqual(true);
|
326
|
+
expect(match(3).toEqual(jasmine.any(Number))).toEqual(true);
|
327
|
+
expect(match("foo").toEqual(jasmine.any(Function))).toEqual(false);
|
328
|
+
expect(match("foo").toEqual(jasmine.any(Object))).toEqual(false);
|
329
|
+
expect(match({someObj:'foo'}).toEqual(jasmine.any(Object))).toEqual(true);
|
330
|
+
expect(match({someObj:'foo'}).toEqual(jasmine.any(Function))).toEqual(false);
|
331
|
+
expect(match(function() {
|
332
|
+
}).toEqual(jasmine.any(Object))).toEqual(false);
|
333
|
+
expect(match(["foo", "goo"]).toEqual(["foo", jasmine.any(String)])).toEqual(true);
|
334
|
+
expect(match(function() {
|
335
|
+
}).toEqual(jasmine.any(Function))).toEqual(true);
|
336
|
+
expect(match(["a", function() {
|
337
|
+
}]).toEqual(["a", jasmine.any(Function)])).toEqual(true);
|
338
|
+
});
|
339
|
+
|
340
|
+
it("toEqual handles circular objects ok", function() {
|
341
|
+
expect(match({foo: "bar", baz: jasmine.undefined}).toEqual({foo: "bar", baz: jasmine.undefined})).toEqual(true);
|
342
|
+
expect(match({foo:['bar','baz','quux']}).toEqual({foo:['bar','baz','quux']})).toEqual(true);
|
343
|
+
expect(match({foo: {bar:'baz'}, quux:'corge'}).toEqual({foo:{bar:'baz'}, quux:'corge'})).toEqual(true);
|
344
|
+
|
345
|
+
var circularObject = {};
|
346
|
+
var secondCircularObject = {};
|
347
|
+
circularObject.field = circularObject;
|
348
|
+
secondCircularObject.field = secondCircularObject;
|
349
|
+
expect(match(circularObject).toEqual(secondCircularObject)).toEqual(true);
|
350
|
+
});
|
351
|
+
|
352
|
+
it("toNotEqual as slightly surprising behavior, but is it intentional?", function() {
|
353
|
+
expect(match({x:"x", y:"y", z:"w"}).toNotEqual({x:"x", y:"y", z:"z"})).toEqual(true);
|
354
|
+
expect(match({x:"x", y:"y", w:"z"}).toNotEqual({x:"x", y:"y", z:"z"})).toEqual(true);
|
355
|
+
expect(match({x:"x", y:"y", z:"z"}).toNotEqual({w: "w", x:"x", y:"y", z:"z"})).toEqual(true);
|
356
|
+
expect(match({w: "w", x:"x", y:"y", z:"z"}).toNotEqual({x:"x", y:"y", z:"z"})).toEqual(true);
|
357
|
+
});
|
358
|
+
|
359
|
+
it("toEqual handles arrays", function() {
|
360
|
+
expect(match([1, "A"]).toEqual([1, "A"])).toEqual(true);
|
361
|
+
});
|
362
|
+
|
363
|
+
it("toContain and toNotContain", function() {
|
364
|
+
expect(match('ABC').toContain('A')).toEqual(true);
|
365
|
+
expect(match('ABC').toContain('X')).toEqual(false);
|
366
|
+
|
367
|
+
expect(match(['A', 'B', 'C']).toContain('A')).toEqual(true);
|
368
|
+
expect(match(['A', 'B', 'C']).toContain('F')).toEqual(false);
|
369
|
+
expect(match(['A', 'B', 'C']).toNotContain('F')).toEqual(true);
|
370
|
+
expect(match(['A', 'B', 'C']).toNotContain('A')).toEqual(false);
|
371
|
+
|
372
|
+
expect(match(['A', {some:'object'}, 'C']).toContain({some:'object'})).toEqual(true);
|
373
|
+
expect(match(['A', {some:'object'}, 'C']).toContain({some:'other object'})).toEqual(false);
|
374
|
+
});
|
375
|
+
|
376
|
+
it("toContain to build an ExpectationResult", function() {
|
377
|
+
var actual = ['a','b','c'];
|
378
|
+
var matcher = match(actual);
|
379
|
+
var expected = 'x';
|
380
|
+
matcher.toContain(expected);
|
381
|
+
|
382
|
+
var result = lastResult();
|
383
|
+
|
384
|
+
expect(result.matcherName).toEqual("toContain");
|
385
|
+
expect(result.passed()).toEqual(false);
|
386
|
+
expect(result.message).toMatch(jasmine.pp(actual));
|
387
|
+
expect(result.message).toMatch('contain');
|
388
|
+
expect(result.message).toMatch(jasmine.pp(expected));
|
389
|
+
expect(result.actual).toEqual(actual);
|
390
|
+
expect(result.expected).toEqual(expected);
|
391
|
+
});
|
392
|
+
|
393
|
+
it("toNotContain to build an ExpectationResult", function() {
|
394
|
+
var actual = ['a','b','c'];
|
395
|
+
var matcher = match(actual);
|
396
|
+
var expected = 'b';
|
397
|
+
matcher.toNotContain(expected);
|
398
|
+
|
399
|
+
var result = lastResult();
|
400
|
+
|
401
|
+
expect(result.matcherName).toEqual("toNotContain");
|
402
|
+
expect(result.passed()).toEqual(false);
|
403
|
+
expect(result.message).toMatch(jasmine.pp(actual));
|
404
|
+
expect(result.message).toMatch('not contain');
|
405
|
+
expect(result.message).toMatch(jasmine.pp(expected));
|
406
|
+
expect(result.actual).toEqual(actual);
|
407
|
+
expect(result.expected).toEqual(expected);
|
408
|
+
});
|
409
|
+
|
410
|
+
it("toBeLessThan should pass if actual is less than expected", function() {
|
411
|
+
expect(match(37).toBeLessThan(42)).toEqual(true);
|
412
|
+
expect(match(37).toBeLessThan(-42)).toEqual(false);
|
413
|
+
expect(match(37).toBeLessThan(37)).toEqual(false);
|
414
|
+
});
|
415
|
+
|
416
|
+
it("toBeLessThan to build an ExpectationResult", function() {
|
417
|
+
var actual = 3;
|
418
|
+
var matcher = match(actual);
|
419
|
+
var expected = 1;
|
420
|
+
matcher.toBeLessThan(expected);
|
421
|
+
|
422
|
+
var result = lastResult();
|
423
|
+
|
424
|
+
expect(result.matcherName).toEqual("toBeLessThan");
|
425
|
+
expect(result.passed()).toEqual(false);
|
426
|
+
expect(result.message).toMatch(jasmine.pp(actual) + ' to be less than');
|
427
|
+
expect(result.message).toMatch(jasmine.pp(expected));
|
428
|
+
expect(result.actual).toEqual(actual);
|
429
|
+
expect(result.expected).toEqual(expected);
|
430
|
+
});
|
431
|
+
|
432
|
+
it("toBeGreaterThan should pass if actual is greater than expected", function() {
|
433
|
+
expect(match(37).toBeGreaterThan(42)).toEqual(false);
|
434
|
+
expect(match(37).toBeGreaterThan(-42)).toEqual(true);
|
435
|
+
expect(match(37).toBeGreaterThan(37)).toEqual(false);
|
436
|
+
});
|
437
|
+
|
438
|
+
it("toBeGreaterThan to build an ExpectationResult", function() {
|
439
|
+
var actual = 1;
|
440
|
+
var matcher = match(actual);
|
441
|
+
var expected = 3;
|
442
|
+
matcher.toBeGreaterThan(expected);
|
443
|
+
|
444
|
+
var result = lastResult();
|
445
|
+
|
446
|
+
expect(result.matcherName).toEqual("toBeGreaterThan");
|
447
|
+
expect(result.passed()).toEqual(false);
|
448
|
+
expect(result.message).toMatch(jasmine.pp(actual) + ' to be greater than');
|
449
|
+
expect(result.message).toMatch(jasmine.pp(expected));
|
450
|
+
expect(result.actual).toEqual(actual);
|
451
|
+
expect(result.expected).toEqual(expected);
|
452
|
+
});
|
453
|
+
|
454
|
+
it("toThrow", function() {
|
455
|
+
var expected = match(function() {
|
456
|
+
throw new Error("Fake Error");
|
457
|
+
});
|
458
|
+
expect(expected.toThrow()).toEqual(true);
|
459
|
+
expect(expected.toThrow("Fake Error")).toEqual(true);
|
460
|
+
expect(expected.toThrow(new Error("Fake Error"))).toEqual(true);
|
461
|
+
|
462
|
+
expect(expected.toThrow("Other Error")).toEqual(false);
|
463
|
+
var result = lastResult();
|
464
|
+
expect(result.message).toMatch("Other Error");
|
465
|
+
|
466
|
+
expect(expected.toThrow(new Error("Other Error"))).toEqual(false);
|
467
|
+
result = lastResult();
|
468
|
+
expect(result.message).toMatch("Other Error");
|
469
|
+
|
470
|
+
var exception;
|
471
|
+
try {
|
472
|
+
(function () {
|
473
|
+
new jasmine.Matchers(env, 'not-a-function', spec).toThrow();
|
474
|
+
})();
|
475
|
+
} catch (e) {
|
476
|
+
exception = e;
|
477
|
+
}
|
478
|
+
|
479
|
+
expect(exception).toBeDefined();
|
480
|
+
expect(exception.message).toEqual('Actual is not a function');
|
481
|
+
|
482
|
+
|
483
|
+
expect(match(function() {
|
484
|
+
}).toThrow()).toEqual(false);
|
485
|
+
result = lastResult();
|
486
|
+
expect(result.message).toEqual('Expected function to throw an exception.');
|
487
|
+
});
|
488
|
+
|
489
|
+
describe(".not.matcher", function() {
|
490
|
+
it("should invert the sense of any matcher", function() {
|
491
|
+
expect(match(37).not.toBeGreaterThan(42)).toEqual(true);
|
492
|
+
expect(match(42).not.toBeGreaterThan(37)).toEqual(false);
|
493
|
+
expect(match("abc").not.toEqual("def")).toEqual(true);
|
494
|
+
expect(match("abc").not.toEqual("abc")).toEqual(false);
|
495
|
+
});
|
496
|
+
|
497
|
+
it("should provide an inverted default message", function() {
|
498
|
+
match(37).not.toBeGreaterThan(42);
|
499
|
+
expect(lastResult().message).toEqual("Passed.");
|
500
|
+
|
501
|
+
match(42).not.toBeGreaterThan(37);
|
502
|
+
expect(lastResult().message).toEqual("Expected 42 not to be greater than 37.");
|
503
|
+
});
|
504
|
+
|
505
|
+
it("should use the second message when the matcher sets an array of custom messages", function() {
|
506
|
+
spec.addMatchers({
|
507
|
+
custom: function() {
|
508
|
+
this.message = function() {
|
509
|
+
return ['Expected it was called.', 'Expected it wasn\'t called.'];
|
510
|
+
};
|
511
|
+
return this.actual;
|
512
|
+
}
|
513
|
+
});
|
514
|
+
|
515
|
+
match(true).custom();
|
516
|
+
expect(lastResult().message).toEqual("Passed.");
|
517
|
+
match(false).custom();
|
518
|
+
expect(lastResult().message).toEqual("Expected it was called.");
|
519
|
+
match(true).not.custom();
|
520
|
+
expect(lastResult().message).toEqual("Expected it wasn't called.");
|
521
|
+
match(false).not.custom();
|
522
|
+
expect(lastResult().message).toEqual("Passed.");
|
523
|
+
});
|
524
|
+
|
525
|
+
it("should make old-style custom matchers blow up, but only when negated", function() {
|
526
|
+
spec.addMatchers({
|
527
|
+
custom: function() {
|
528
|
+
this.report();
|
529
|
+
}
|
530
|
+
});
|
531
|
+
|
532
|
+
expect(function() {
|
533
|
+
match(true).custom();
|
534
|
+
}).not.toThrow();
|
535
|
+
|
536
|
+
expect(function() {
|
537
|
+
match(true).not.custom();
|
538
|
+
}).toThrow();
|
539
|
+
});
|
540
|
+
});
|
541
|
+
|
542
|
+
describe("spy matchers >>", function() {
|
543
|
+
var TestClass;
|
544
|
+
beforeEach(function() {
|
545
|
+
TestClass = {
|
546
|
+
normalFunction: function() {
|
547
|
+
},
|
548
|
+
spyFunction: jasmine.createSpy("My spy")
|
549
|
+
};
|
550
|
+
});
|
551
|
+
|
552
|
+
function shouldThrowAnExceptionWhenInvokedOnANonSpy(methodName) {
|
553
|
+
return function() {
|
554
|
+
expect(function() {
|
555
|
+
match(TestClass.normalFunction)[methodName]();
|
556
|
+
}).toThrow('Expected a spy, but got Function.');
|
557
|
+
|
558
|
+
expect(function() {
|
559
|
+
match(jasmine.undefined)[methodName]();
|
560
|
+
}).toThrow('Expected a spy, but got undefined.');
|
561
|
+
|
562
|
+
expect(function() {
|
563
|
+
match({some:'object'})[methodName]();
|
564
|
+
}).toThrow('Expected a spy, but got { some : \'object\' }.');
|
565
|
+
|
566
|
+
expect(function() {
|
567
|
+
match("<b>")[methodName]();
|
568
|
+
}).toThrow('Expected a spy, but got \'<b>\'.');
|
569
|
+
};
|
570
|
+
}
|
571
|
+
|
572
|
+
describe("wasCalled", function() {
|
573
|
+
it("should pass iff the spy was called", function() {
|
574
|
+
expect(match(TestClass.spyFunction).wasCalled()).toEqual(false);
|
575
|
+
|
576
|
+
TestClass.spyFunction();
|
577
|
+
expect(match(TestClass.spyFunction).wasCalled()).toEqual(true);
|
578
|
+
});
|
579
|
+
|
580
|
+
it("should throw an exception when invoked with any arguments", function() {
|
581
|
+
expect(function() {
|
582
|
+
match(TestClass.normalFunction).wasCalled("unwanted argument");
|
583
|
+
}).toThrow('wasCalled does not take arguments, use wasCalledWith');
|
584
|
+
});
|
585
|
+
|
586
|
+
it('should throw an exception when invoked on a non-spy', shouldThrowAnExceptionWhenInvokedOnANonSpy('wasCalled'));
|
587
|
+
});
|
588
|
+
|
589
|
+
describe("wasNotCalled", function() {
|
590
|
+
it("should pass iff the spy was not called", function() {
|
591
|
+
expect(match(TestClass.spyFunction).wasNotCalled()).toEqual(true);
|
592
|
+
|
593
|
+
TestClass.spyFunction();
|
594
|
+
expect(match(TestClass.spyFunction).wasNotCalled()).toEqual(false);
|
595
|
+
});
|
596
|
+
|
597
|
+
it("should throw an exception when invoked with any arguments", function() {
|
598
|
+
expect(function() {
|
599
|
+
match(TestClass.normalFunction).wasNotCalled("unwanted argument");
|
600
|
+
}).toThrow('wasNotCalled does not take arguments');
|
601
|
+
});
|
602
|
+
|
603
|
+
it('should throw an exception when invoked on a non-spy', shouldThrowAnExceptionWhenInvokedOnANonSpy('wasNotCalled'));
|
604
|
+
});
|
605
|
+
|
606
|
+
describe("wasCalledWith", function() {
|
607
|
+
it('wasCalledWith should return true if it was called with the expected args', function() {
|
608
|
+
TestClass.spyFunction('a', 'b', 'c');
|
609
|
+
expect(match(TestClass.spyFunction).wasCalledWith('a', 'b', 'c')).toEqual(true);
|
610
|
+
});
|
611
|
+
|
612
|
+
it('should return false if it was not called with the expected args', function() {
|
613
|
+
TestClass.spyFunction('a', 'b', 'c');
|
614
|
+
var expected = match(TestClass.spyFunction);
|
615
|
+
expect(expected.wasCalledWith('c', 'b', 'a')).toEqual(false);
|
616
|
+
var result = lastResult();
|
617
|
+
expect(result.passed()).toEqual(false);
|
618
|
+
expect(result.expected).toEqual(['c', 'b', 'a']);
|
619
|
+
expect(result.actual.mostRecentCall.args).toEqual(['a', 'b', 'c']);
|
620
|
+
expect(result.message).toContain(jasmine.pp(result.expected));
|
621
|
+
expect(result.message).toContain(jasmine.pp(result.actual.mostRecentCall.args));
|
622
|
+
});
|
623
|
+
|
624
|
+
it('should return false if it was not called', function() {
|
625
|
+
var expected = match(TestClass.spyFunction);
|
626
|
+
expect(expected.wasCalledWith('c', 'b', 'a')).toEqual(false);
|
627
|
+
var result = lastResult();
|
628
|
+
expect(result.passed()).toEqual(false);
|
629
|
+
expect(result.expected).toEqual(['c', 'b', 'a']);
|
630
|
+
expect(result.actual.argsForCall).toEqual([]);
|
631
|
+
expect(result.message).toContain(jasmine.pp(result.expected));
|
632
|
+
});
|
633
|
+
|
634
|
+
it('should allow matches across multiple calls', function() {
|
635
|
+
var expected = match(TestClass.spyFunction);
|
636
|
+
TestClass.spyFunction('a', 'b', 'c');
|
637
|
+
TestClass.spyFunction('d', 'e', 'f');
|
638
|
+
expect(expected.wasCalledWith('a', 'b', 'c')).toEqual(true);
|
639
|
+
expect(expected.wasCalledWith('d', 'e', 'f')).toEqual(true);
|
640
|
+
expect(expected.wasCalledWith('x', 'y', 'z')).toEqual(false);
|
641
|
+
});
|
642
|
+
|
643
|
+
it('should throw an exception when invoked on a non-spy', shouldThrowAnExceptionWhenInvokedOnANonSpy('wasCalledWith'));
|
644
|
+
|
645
|
+
describe("to build an ExpectationResult", function () {
|
646
|
+
beforeEach(function() {
|
647
|
+
var currentSuite;
|
648
|
+
var spec;
|
649
|
+
currentSuite = env.describe('default current suite', function() {
|
650
|
+
spec = env.it();
|
651
|
+
}, spec);
|
652
|
+
TestClass = { someFunction: function(a, b) {
|
653
|
+
} };
|
654
|
+
spec.spyOn(TestClass, 'someFunction');
|
655
|
+
});
|
656
|
+
|
657
|
+
it("should should handle the case of a spy", function() {
|
658
|
+
TestClass.someFunction('a', 'c');
|
659
|
+
var matcher = match(TestClass.someFunction);
|
660
|
+
matcher.wasCalledWith('a', 'b');
|
661
|
+
|
662
|
+
var result = lastResult();
|
663
|
+
expect(result.matcherName).toEqual("wasCalledWith");
|
664
|
+
expect(result.passed()).toEqual(false);
|
665
|
+
expect(result.message).toContain(jasmine.pp(['a', 'b']));
|
666
|
+
expect(result.message).toContain(jasmine.pp(['a', 'c']));
|
667
|
+
expect(result.actual).toEqual(TestClass.someFunction);
|
668
|
+
expect(result.expected).toEqual(['a','b']);
|
669
|
+
});
|
670
|
+
});
|
671
|
+
});
|
672
|
+
|
673
|
+
describe("wasNotCalledWith", function() {
|
674
|
+
it('should return true if the spy was NOT called with the expected args', function() {
|
675
|
+
TestClass.spyFunction('a', 'b', 'c');
|
676
|
+
expect(match(TestClass.spyFunction).wasNotCalledWith('c', 'b', 'a')).toEqual(true);
|
677
|
+
});
|
678
|
+
|
679
|
+
it('should return false if it WAS called with the expected args', function() {
|
680
|
+
TestClass.spyFunction('a', 'b', 'c');
|
681
|
+
var expected = match(TestClass.spyFunction);
|
682
|
+
expect(expected.wasNotCalledWith('a', 'b', 'c')).toEqual(false);
|
683
|
+
var result = lastResult();
|
684
|
+
expect(result.passed()).toEqual(false);
|
685
|
+
expect(result.expected).toEqual(['a', 'b', 'c']);
|
686
|
+
expect(result.actual.mostRecentCall.args).toEqual(['a', 'b', 'c']);
|
687
|
+
expect(result.message).toContain(jasmine.pp(result.expected));
|
688
|
+
});
|
689
|
+
|
690
|
+
it('should return true if it was not called', function() {
|
691
|
+
var expected = match(TestClass.spyFunction);
|
692
|
+
expect(expected.wasNotCalledWith('c', 'b', 'a')).toEqual(true);
|
693
|
+
});
|
694
|
+
|
695
|
+
it('should allow matches across multiple calls', function() {
|
696
|
+
var expected = match(TestClass.spyFunction);
|
697
|
+
TestClass.spyFunction('a', 'b', 'c');
|
698
|
+
TestClass.spyFunction('d', 'e', 'f');
|
699
|
+
expect(expected.wasNotCalledWith('a', 'b', 'c')).toEqual(false);
|
700
|
+
expect(expected.wasNotCalledWith('d', 'e', 'f')).toEqual(false);
|
701
|
+
expect(expected.wasNotCalledWith('x', 'y', 'z')).toEqual(true);
|
702
|
+
});
|
703
|
+
|
704
|
+
it('should throw an exception when invoked on a non-spy', shouldThrowAnExceptionWhenInvokedOnANonSpy('wasNotCalledWith'));
|
705
|
+
|
706
|
+
});
|
707
|
+
|
708
|
+
});
|
709
|
+
});
|