Compare commits

...

184 Commits

Author SHA1 Message Date
Greg Cobb and Gregg Van Hove
4acb7448d8 Update release notes and bump version for 2.2.0 2015-02-02 11:27:14 -08:00
slackersoft
a26e85ff3a update 2.2.0 release notes now that I've pulled 2015-01-30 13:03:08 -08:00
slackersoft
39e175c05f Initial cut of release notes for 2.2.0 2015-01-30 13:02:01 -08:00
Christopher Amavisca
d129a6c0ee Restructure node examples folder structure to look more realistic.
- Updates PlayerSpec's require statement to match folder structure change
2015-01-27 14:39:59 -08:00
slackersoft
837101c025 Add a basic bower config
- Also ignore sauce_connect.log

Fix #719
2015-01-26 17:53:41 -08:00
slackersoft
8e3066db42 Allow pending to take a reason and show it in the HtmlReporter
[#78954014] Fix #671
2015-01-26 15:55:31 -08:00
slackersoft
a857f4c042 Merge branch 'ptomato-gjs-global-object' 2015-01-26 12:22:05 -08:00
slackersoft
dca543accb Merge branch 'gjs-global-object' of https://github.com/ptomato/jasmine into ptomato-gjs-global-object 2015-01-26 12:21:56 -08:00
slackersoft
5dbcf27f72 Merge branch 'ptomato-spidermonkey-compat' 2015-01-26 11:47:35 -08:00
slackersoft
b54de4a180 Merge branch 'spidermonkey-compat' of https://github.com/ptomato/jasmine into ptomato-spidermonkey-compat 2015-01-26 11:47:09 -08:00
slackersoft
46509f05a9 Add jshint to node run on travis
- To ensure that pull requests pass

[Finish #59588854]
2015-01-26 10:59:44 -08:00
Philip Chimento
ebaa2e7f24 Set jasmineGlobal correctly in GJS
In GJS, jasmineGlobal was not getting set to the global object; when
importing jasmine.js in GJS, "this" resolves to the jasmine.js module
object, not the global object. Solve this specifically for GJS by
assuming that `window.toString === '[object GjsGlobal]'` only in GJS; if
this is the case, assign "window" to "jasmineGlobal".

Adding a "var" to the declaration of "getJasmineRequireObj" is also
necessary, or else "getJasmineRequireObj" won't be exported in the
Jasmine module.

See #751
2015-01-24 23:50:40 -08:00
Philip Chimento
5eaf7152bf Fix some SpiderMonkey lint
SpiderMonkey complains about functions not always returning a value. In
most cases that is a conscious code style choice, so it is not fixed
here.

In one case (MockDate) the interpreter thought you could have fallen off
the end of a "switch" statement, although the number of arguments
prevented that. This was fixed by changing the last case to "default".

In another case (QueueRunner) the function really did return a value
sometimes and nothing other times, although as far as I could see, it
could only ever return "undefined". The function now explicitly only
returns no value.

See #751
2015-01-24 23:43:38 -08:00
Greg Cobb
ebbaab4cf9 Prevents *Alls from running when runnables are explicitly set
- This requires passing if runnables are set to the Suite. Hopefully in
  the future we will change how focused runnables and *Alls interact so
  this is no longer necessary.

[#732]
2015-01-23 17:27:13 -08:00
Greg Cobb
1936a36c79 Fix jslint issues 2015-01-23 17:23:07 -08:00
slackersoft
1dd4af3835 anything and stringMatching have custom pretty-print now. 2015-01-21 12:59:01 -08:00
slackersoft
6ae054c3e2 Update contribution guide to mention possible ffi dependencies for Ubuntu
Fixes #755
2015-01-21 12:55:07 -08:00
Gregg Van Hove
e5feba994f Merge pull request #746 from swirlycheetah/patch-1
Fix spelling mistake
2015-01-14 17:00:19 -08:00
Chris Wheatley
20faa883fb fix spelling mistake 2015-01-14 22:15:49 +00:00
Gregg Van Hove
3bba1eabd4 Merge pull request #745 from rohit/fix-repo-url
Use new jasmine github repo url
2015-01-14 10:26:39 -08:00
Rohit Arondekar
9ad3eac469 Use new jasmine github repo url 2015-01-14 20:47:09 +05:30
Gregg Van Hove
3140d5fb95 Allow createSpyObj to be called with just an array of method names
[Finish #50757607] #321
2015-01-12 15:16:50 -08:00
Gregg Van Hove
69a61547e7 Don't forget to buildDistribution
- Also fix jshint errors

[#59947350] #440
2015-01-12 14:10:50 -08:00
Gregg Van Hove
a999490de9 Merge branch 'arrayContaining' of https://github.com/slackersoft/jasmine into slackersoft-arrayContaining
Merge #440 [Finish #59947350]
2015-01-12 14:01:02 -08:00
Gregg Van Hove
c1479acd17 Fix fail specs for all browsers #734 2015-01-12 13:37:10 -08:00
Gregg Van Hove
3a93f845d6 Use the stack trace from the Error object if supplied
Fixes #734
2015-01-12 11:51:45 -08:00
Gregg Van Hove
6c58024321 Update readme with link to upgrading doc and mention browser support.
Fix #739
2015-01-12 11:06:59 -08:00
Gregg Van Hove
aeae141fd4 Merge branch 'moonmaster9000-patch-2' 2015-01-12 10:08:15 -08:00
Matt Parker
a951bbbb47 Link to the Jasmine NPM module
Also, put the jasmine-<language> links above the confusing "install jasmine on your local box" stuff (why would I want to do that?)
2015-01-12 10:08:04 -08:00
slackersoft
895c17e5c1 Merge branch 'rohit-equals-null-protoObjects' 2014-12-20 16:48:26 -08:00
Rohit Arondekar
a84eaf2cbe Allow null prototype obj to be compared for equals
Fixes #729
2014-12-20 08:35:27 +05:30
slackersoft
9f240c5b9e Build distribution to properly expose stringMatching
[#58120558]
2014-12-19 12:45:58 -08:00
slackersoft
dfa8a77dc3 Add asymmetric equality tester to match a string against a regexp
- Also move the asymmetric testers into their own dir for easier
  locating.

[#58120558] Fix #243
2014-12-19 12:39:24 -08:00
Gregg Van Hove
2472982fe9 Merge pull request #730 from rohit/patch-1
Fix URL's of Jasmine repositories on Github
2014-12-19 09:21:02 -08:00
Rohit Arondekar
c85500a924 Fix URL's of Jasmine repositories on Github 2014-12-19 07:36:03 +05:30
slackersoft
482f4d62fc Add anything matcher to match any value that is neither null or undefined
[finish #58117878] Fix #186
2014-12-17 12:58:47 -08:00
slackersoft
bfcd8b046d Allow asymmetric equality testers to preempt their symmetric brethren
- Also allow them to be compared to each other properly.

Fixes #540
2014-12-16 17:45:58 -08:00
slackersoft
2ab22951a1 Just check if either side implements asymmetricMatch
- Don't explicitly look for `Any` or `ObjectContaining`

[#82295210]
2014-12-16 17:29:18 -08:00
slackersoft
6c131beda7 Don't double escape focus spec links.
- QueryString already escapes parameter values, no need to escape when
  passing them in from HtmlReporter.

[finish #29578495]
2014-12-16 17:21:22 -08:00
slackersoft
ea88023553 Check for ObjectContaining on either side of equality.
- Also clean up `undefined` check.

Fixes #682
2014-12-16 17:07:35 -08:00
slackersoft
6bd98cb2ab Rename jasmineMatches to asymmetricMatch
- This should be more clear what it is for

[finish #82295210]
2014-12-16 16:47:31 -08:00
slackersoft
b4b3ac25a1 spyOn explicitly checks to see that a method name to spy on was passed.
[finish #27689237]
2014-12-16 13:21:48 -08:00
slackersoft
7570bc422b Display the name of the constructor when pretty printing objects
Fixes #598 [finishes #81228592]
2014-12-16 12:56:04 -08:00
slackersoft
eca8d8f009 Also test in IE 11 on travis 2014-12-16 11:57:48 -08:00
slackersoft
305252f5a8 toMatch requires the expected to be a String or RegExp
- Otherwise it was using the `toString` as the RegExp, which is almost
  definitely _not_ what you want.

Fixes #723
2014-12-16 11:50:45 -08:00
slackersoft
0fdb28c6ff Merge branch 'toEqualDomNodes' of https://github.com/alexeibs/jasmine into alexeibs-toEqualDomNodes 2014-12-16 11:25:14 -08:00
slackersoft
a84202a6f9 Also check custom properties on Arrays when computing equality
[Finishes #50616649]
2014-12-16 10:22:23 -08:00
slackersoft
503f4b7f49 Keep extra query params when focusing on a spec or suite
[finish #29578495]
2014-12-15 18:30:32 -08:00
slackersoft
fbe38018c9 Hide more things from the npm package
Fixes #726
2014-12-11 12:48:50 -08:00
slackersoft
8bb2f67fb3 Properly record finishing an xdescribe so further cleanup works
Fix #724
2014-12-09 12:40:00 -08:00
slackersoft
ba9c863de9 Add spec to verify custom query params are left alone
[#29578495]
2014-12-05 08:12:42 -08:00
slackersoft
02161b7d48 ObjectContaining no longer tries to track exact mismatches
- equals wasn't looking at it anyways, so just bail as soon as something
  is different.
2014-12-05 08:06:20 -08:00
slackersoft
4d5f27d359 Reschedule all functions for a tick before executing any
- This allows any function run during a tick to cancel any other in the
  same tick.

Fixes #708
2014-12-05 08:01:34 -08:00
slackersoft
a4faa80be4 pass through all args from external interface for befores, afters, its
Fix #483
2014-12-02 13:29:43 -08:00
slackersoft
b68ba90ad7 Just return the result directly from any and objectContaining
- They return false when they fail which means not equal.
2014-12-02 07:56:40 -08:00
slackersoft
dc7be9c55e change 2.1.3 release notes filename to match others 2014-12-01 12:49:40 -08:00
slackersoft
b56c2a69ac add standalone dist for 2.1.3 2014-12-01 12:46:52 -08:00
slackersoft
4b6789ccd9 version bump for 2.1.3 2014-12-01 12:43:52 -08:00
slackersoft
9f94e8e226 Top level suite no longer reports suiteStart and suiteDone
- jasmineStart and jasmineDone are reported separately

Fixes #716
2014-11-28 21:25:45 -08:00
slackersoft
55f32e2dc6 Don't keep the expected and actual for a passed expectation
- It causes memory problems in phantom and you probably don't need it
  anyways.

Fixes #640 Fixes #690
2014-11-22 15:03:27 -08:00
Gregg Van Hove
b30a85c8f1 Merge pull request #712 from joshk/patch-1
Use the new build env on Travis
2014-11-22 14:58:34 -08:00
Josh Kalderimis
20ce62d5f5 Use the new build env on Travis
better faster stronger

more ram, cpu, faster boot times, better network

docs coming soon
2014-11-22 14:21:03 -05:00
Christopher Amavisca
c3de57aaac Update travis badge 2014-11-22 11:16:07 -08:00
slackersoft
2517ddfe17 bump verion to 2.1.2 2014-11-16 14:56:27 -08:00
slackersoft
23a492cb65 Suites still run their children even if none are executable
- Continue skipping beforeAll and afterAll

Fixes #707
2014-11-16 14:43:44 -08:00
slackersoft
25c546a904 add release notes and standalone dist for 2.1.1 2014-11-14 18:44:28 -08:00
slackersoft
97ab0cb403 bump version to 2.1.1 2014-11-14 18:43:00 -08:00
slackersoft
42b1bda919 Top-level suite triggers suiteStarted and suiteEnd to be consistent
Fixes #706
2014-11-14 18:37:00 -08:00
slackersoft
216b40439f Attempt to use selenium runner from source, to fix dependency loop 2014-11-14 12:41:50 -08:00
slackersoft
590a9d9d41 bump version to 2.1.0 2014-11-14 07:54:19 -08:00
Davis W. Frank
66c8624022 Updating links in release notes 2014-11-11 09:46:38 -08:00
Davis W. Frank
75e5a5c308 Fix for wayward underscore and Anchorman bug 2014-11-10 17:24:06 -08:00
Davis W. Frank
9b5c20cc19 Adding first crack at 2.1 release notes 2014-11-10 17:15:57 -08:00
slackersoft
cc720e7f56 Add release notes for previous releases, so they can be removed from the wiki
[#54582902]
2014-11-06 08:21:31 -08:00
Gregg Van Hove
1426416666 Merge pull request #700 from tkrotoff/patch-1
Simplifies SpecRunner.html
2014-11-04 13:20:55 -08:00
Tanguy Krotoff
197cb13817 Simplifies SpecRunner.html
No need to specify type="text/javascript" for script tag
No need to specify type="text/css" for link tag with rel="stylesheet"
2014-11-04 10:30:11 +01:00
slackersoft
816b7d701f Merge branch 'charleshansen-to_contain_array_like_objects' 2014-11-03 13:10:13 -08:00
Charles Hansen
da6813ef0d toContain works with array-like objects (Arguments, HTMLCollections, etc)
Fixes #699

Don't rely on Array.prototype.indexOf for testing containment (not in IE8)
2014-11-03 13:09:57 -08:00
slackersoft
a4d134521a Revert "toContain works with array-like objects (Arguments, HTMLCollections, etc)"
IE 8 doesn't have Array.prototype.indexOf so this breaks there.
Reverting until we can figure out a better way to solve across all
supported browsers.

This reverts commit 663fbd0cdb.
2014-11-01 14:28:32 -07:00
slackersoft
d4fc787ea7 Merge branch 'charleshansen-to_contain_array_like_objects' 2014-10-30 13:08:45 -07:00
Charles Hansen
663fbd0cdb toContain works with array-like objects (Arguments, HTMLCollections, etc)
Fix #699
2014-10-30 13:08:16 -07:00
Matt Parker
cf83ae474c Added Sheel to the Maintainers Emeritus list 2014-10-25 08:07:15 -07:00
Matt Parker
325c5a2288 Name / Email / Org updates in README 2014-10-25 07:51:18 -07:00
Gregg Van Hove
3ca687a9ad Merge pull request #691 from ertrzyiks/fix-spec-title
Fixed isPendingSpecException test title
2014-10-22 09:52:10 -07:00
Mateusz Derks
3b557f85c7 Fixed isPendingSpecException test title 2014-10-17 15:36:24 +02:00
slackersoft
b67a19507f Add notes for releasing new versions of the docs 2014-10-11 22:13:26 -07:00
slackersoft
ecae3d47a7 Use the jasmine-npm tarball, since that works on travis
[#80505862]
2014-10-11 15:04:04 -07:00
slackersoft
a76d6d1cd4 Pass in the current distribution when running node specs
- npm package spec can use beforeAll/afterAll now
- also depend on github repo directly instead of the tarball

[finish #80505862]
2014-10-11 14:54:08 -07:00
slackersoft
916dc03d9c build distribution with deprecated console
[#80410002]
2014-10-11 14:28:51 -07:00
slackersoft
2151a13705 Let's just use the print function that's passed in for deprecation messaging
[#80410002]
2014-10-11 14:20:19 -07:00
slackersoft
6cc09e00d3 Oh right, IE doesn't have console by default
[#80410002]
2014-10-11 13:54:41 -07:00
slackersoft
6d6c31328b Deprecate console reporter
- jasmine-npm has its own version so it's no longer dependent on this
  one.

[finish #80410002]
2014-10-11 13:34:45 -07:00
Gerg
c8cd2eabe5 Fixes console check for IE8
- Was causing IE8 to hang for some reason
- Also reverts previous commit, not that issue was resolved

[#79533268][fixes #80356450]
2014-10-09 00:41:17 -07:00
Gerg
f77071254a Fixes additional odd IE8 failure
[#79533268]
2014-10-08 23:14:40 -07:00
Gerg
8880729250 JsApiReporter suiteResults only includes suite results
- It was including suite starts also

[#79533268]
2014-10-08 22:33:36 -07:00
slackersoft
9ad15eeaba Merge branch 'akoptsov-patch-1' 2014-10-08 12:52:40 -07:00
Alexander Koptsov
10ca5f0246 Fixed path to src files in node_example
There's no such folder as 'jasmine_examples'
2014-10-07 16:35:38 +04:00
Gerg
a5cd2731b4 Fixes CI for IE8
For some reason, when you put this spec in a describe block, it causes
specs to hang on IE8. I tried to debug this for a while, and I have no
idea what is happening.

[#79533268]
2014-10-05 14:33:40 -07:00
Gerg
b12974db2e Adds suiteResults method to JsApiReporter
- Behaves similarly to to specResults
- Since suites were stored in an object instead of an array and the
  current interface exposes this object, we now must keep track of suites
  twice in the reporter. We cannot just construct the object lazily,
  because then the object will not update with new suite results
  like it does currently (see JsApiReporterSpec:148).

[#79533268]
2014-10-04 18:36:38 -07:00
slackersoft
f4e5573ee3 Add explicit fail and move on for async functions
- `done` now has a `fail` property which will call the global `fail`
  then continue to the next function in the queue

[finish #73744618] Fix #567 Fix #568
2014-10-02 08:10:29 -07:00
slackersoft
0c77c6cfb5 Use the Gemfile from the docs repo 2014-10-01 13:10:11 -07:00
slackersoft
cfc64a6f5c bundle exec the docs rake tasks 2014-10-01 09:59:39 -07:00
slackersoft
6ab70923b3 Use rake tasks in the docs repo to test it 2014-10-01 08:15:35 -07:00
slackersoft
d9c0b10be4 Remove type from queueableFns since we're not using it to determine afterAll anymore. 2014-09-30 18:28:41 -07:00
slackersoft
a58fd20d82 Build distribution for suite failed status changes 2014-09-26 18:35:06 -07:00
slackersoft
eefa716530 set suite status to failed when afterAll has failures 2014-09-26 09:12:48 -07:00
slackersoft
66c364564e Fix custom timeout specs for firefox 2014-09-26 08:21:54 -07:00
slackersoft
68ba5b6d48 Allow custom timeout for beforeEach, afterEach, beforeAll, afterAll and it
Fix #483
2014-09-25 22:31:00 -07:00
slackersoft
15ae0379ec Add fit and fdescribe to the public interface
They got lost in the merge
2014-09-25 13:19:13 -07:00
slackersoft
1fb0d2eefa Merge branch 'master' of https://github.com/chernetsov/jasmine into chernetsov-master
Fix #678 Close #679
2014-09-25 12:59:10 -07:00
slackersoft
ba0982d89f Merge branch 'beforeAll' into master
Conflicts:
	lib/jasmine-core/boot.js
	lib/jasmine-core/boot/boot.js
	lib/jasmine-core/jasmine.css
	lib/jasmine-core/jasmine.js
	spec/core/SpecSpec.js
	spec/core/SuiteSpec.js
	spec/core/integration/EnvSpec.js
	spec/node_suite.js
	src/core/Env.js
	src/core/requireCore.js
	src/core/util.js
2014-09-24 20:20:39 -07:00
slackersoft
f703539942 build distribution for toThrowError refactor 2014-09-24 18:27:40 -07:00
Misha Chernetsov
62840f72a6 when jasmine clock is installed and date is mocked new Date() instanceof Date should equal true 2014-09-24 15:07:22 -07:00
slackersoft
6d10f97151 Merge branch 'toThrowError_refactor' 2014-09-24 13:23:50 -07:00
slackersoft
15f3d0e9d7 update doc comment for boot.js to match current documentation 2014-09-23 08:22:05 -07:00
slackersoft
b1344d5c73 Add explicit fail function.
- Adds an expectation failure to the current spec

[finishes #70975468] Fix #563
2014-09-23 08:00:46 -07:00
slackersoft
59aaac026c Merge branch 'paladox2015-patch-1' 2014-09-22 13:10:12 -07:00
slackersoft
21f62c697a Merge branch 'patch-1' of https://github.com/paladox2015/jasmine into paladox2015-patch-1 2014-09-22 13:09:07 -07:00
slackersoft
dc93c33af6 Merge branch 'pimterry-trackReturnValues' 2014-09-22 13:04:18 -07:00
slackersoft
4889583d5c Merge branch 'trackReturnValues' of https://github.com/pimterry/jasmine into pimterry-trackReturnValues 2014-09-22 13:04:01 -07:00
slackersoft
41df058171 update contributing doc to indicate use of jasmine-npm 2014-09-20 20:54:45 -07:00
slackersoft
fa837ae90a Don't depend on debugger gem, we don't really have any ruby code here. 2014-09-20 20:17:55 -07:00
slackersoft
c82c958e0d Build distribution for earlier fixes 2014-09-16 13:05:11 -07:00
slackersoft
752e831b30 Merge branch 'mkhanal-chain_spy_andReturn'
Fix #669 #660
2014-09-15 13:10:40 -07:00
slackersoft
bd30065d66 Merge branch 'chain_spy_andReturn' of https://github.com/mkhanal/jasmine into mkhanal-chain_spy_andReturn 2014-09-15 13:10:24 -07:00
slackersoft
84dff421ea Use === when checking for circular dependencies for pretty printing. 2014-09-13 18:58:02 -07:00
Mridul
709e032d1c Added returnValues functionality to spy strategy 2014-09-13 12:41:20 +10:00
Greg Cobb
1290d93b6a Suite result status added when suite is complete
- This makes it easier to detect afterAll failures, because we can
  rely only complete runnables having statuses

[#78306786 & #73741654]
2014-09-09 11:26:32 -07:00
slackersoft
345903220c Refactor toThrowError to be less one huge if/else if/else if block
- This should also improve it's code climate score as well.
- It's also about 20 lines shorter now too :)

[#59524164]
2014-09-07 16:02:42 -07:00
Greg Cobb
3332f93a24 Only run focused runnables inside focused suites
- Focused runnables now walk up the tree to unfocus the first focused
  ancestor. Because of the way the tree is constructed, this makes sure
  that each focused runnable has no focused ancestors.

[#78289686]
2014-09-05 12:25:28 -07:00
slackersoft
3b19d66268 Check for afterAll failures in a more browser independent way.
- Only look at the message, so browsers that don't provide a stack don't
  blow up.
2014-09-04 18:49:14 -07:00
slackersoft
137c1a39f6 Check afterAll failure messages with regexp, since some browsers add more info 2014-09-04 08:15:23 -07:00
slackersoft
9402d59859 Suites report errors in afterAlls in the suiteDone event
- remove `afterAllEvent` from reporters
2014-09-03 22:18:20 -07:00
slackersoft
e8178d061b Merge branch 'tgirardi-issue655'
Fix #655 #658
2014-09-02 13:20:18 -07:00
slackersoft
dd75394ea8 Merge branch 'issue655' of https://github.com/tgirardi/jasmine into tgirardi-issue655 2014-09-02 13:19:31 -07:00
Greg Cobb and Tim Jarratt
6b857d11ce Factor out some common logic between fdesc and desc 2014-08-29 09:25:41 -07:00
Tomás Girardi
eb48c83649 Add specs for intervals that "clear themselves"
Add specs to test if issue #655 is present: the handler of an interval
cannot successfully clear the same interval that generated it's
invocation.

The most direct test consist in setting an interval with a handler that
calls clearInterval over that same interval and make the clock tick for
double of it's period. If the issue is present the interval's handler
will be called twice. If the issue is not present, the first invocation
of the handler will avoid a second one (because of the clearInterval).

Another test is included in order to check if recurring scheduled
functions are rescheduled before being called. Doing this in the reverse
order is the exact cause of the issue.
2014-08-28 20:58:30 -04:00
Greg Cobb and Tim Jarratt
08a35d134d Ensure focused tests are only run once
Required duplicating some of the logic for constructing a suite from
describe so that we could mark a suite as focused in fdescribe, but
otherwise this prevents focused tests from being run more than once.

[#73742944]
2014-08-28 17:54:42 -07:00
Greg Cobb and Tim Jarratt
14824b5f9e Expose fit and fdescribe in boot.js
* adds done() callbacks to existing specs (because we forgot, whoops!)

[Finishes #73742944]
2014-08-28 16:37:37 -07:00
Greg Cobb and Tim Jarratt
9afae3d978 Add a test documenting fits in fdescribes
Yo, this probably isn't the best behavior. Rspec and Ginkgo definitely
do not exhibit this behavior when you nest focused runnables inside
other focused runnables. We thought fixing it, but it seems like a
nontrivial refactoring would be necessary to clean this up.

[#73742944]
2014-08-28 16:19:31 -07:00
Greg Cobb and Tim Jarratt
64a67ed320 Trim extraneous whitespace 2014-08-28 15:55:39 -07:00
Greg Cobb and Tim Jarratt
dee1066652 Focused runnables play nicely with beforeAll/afterAll
[#73742944]
2014-08-28 15:54:27 -07:00
Greg Cobb and Tim Jarratt
d7ab9083be Add focused describe
[#73742944]
2014-08-28 15:43:59 -07:00
Greg Cobb and Tim Jarratt
caee1508d1 Adds a fit function to Env
[#73742944]
2014-08-28 15:37:18 -07:00
slackersoft
3b8326f1e6 Detect global object properly when getting the jasmine require obj
- Pull global detection into requireCore and pass the global to base

Fix #569
[fix #73684570]
2014-08-28 13:31:04 -07:00
Greg Cobb and Tim Jarratt
980509cd7b Preserve relative order of "alls" w.r.t. "eachs"
[Finishes #73742528]
2014-08-28 11:54:58 -07:00
Greg Cobb and Tim Jarratt
b984ff2fa6 Run before,afterAlls as 'eachs' when specifying runnablesToRun
- Fix bug where beforeAlls were being mutated in Suite#execute
- When Env.execute() receives a list of runnables, beforeAlls and
  afterAlls are collected as beforeEachs and afterEachs. This allows
  runnables to be specified in any order, regardless of if any of them
  have before/afterAlls.
- Spec constructor takes a single function that returns both before and
  afters, instead of two functions. This breaks the current interface
  for constructing a Spec.

[#73742528]
2014-08-28 11:54:54 -07:00
Greg Cobb and Tim Jarratt
61bf9ac7d7 Improve quality of async timeout for afterAll spec
We found that this test was always passing and had strange interactions
with the ordering of other specs. Rewriting it to explicitly finish the
afterAll after a specified interval makes it fail correctly.

[#73742528]
2014-08-28 11:54:46 -07:00
Greg Cobb and Tim Jarratt
5b397ff33e Revert "Deprecate suite/spec ordering hook ."
This reverts commit 76fafa0388.

[#73742528]
2014-08-28 11:54:27 -07:00
Greg Cobb and Tim Jarratt
cd4d5c2445 ConsoleReporter exits 1 when afterAll events occur
[Finishes #67068790]
2014-08-27 14:45:59 -07:00
Greg Cobb and Tim Jarratt
5b6edff3fd Report AfterAll failures as they occur
There didn't seem to be a valid reason to wait until the very end to
report these.
2014-08-27 14:01:28 -07:00
Greg Cobb and Tim Jarratt
cc3678f033 Refactor suite to share reportExpectationFailure func
This was shared between our suite factory and the suite factory.
Sweet.
2014-08-27 13:50:56 -07:00
Greg Cobb and Tim Jarratt
35f52bcb24 Rewrite an incorrect suite spec 2014-08-27 12:27:11 -07:00
slackersoft
f8bccabf03 Move afterAll reporting into Suite since that's where they're being tracked 2014-08-27 08:13:17 -07:00
Greg Cobb and Tim Jarratt
97867b2bf5 Reports expectation failures in afterAlls
This makes the specs green and appears to work for most cases. I have a
number of concerns about the implementation and would appreciate
ideas/feedback.

- Suite#addExpecationResult infers if it is coming from an afterAll fn
  based on if the first child of the suite is finished. This assumes
  that the first child of the suite is a spec (this appears to be true
  as long as there is at least one spec in the suite)
  - Suites behave like unfinished specs. Because suites will propagate
    expectation failures to their children suites, the afterAll
    expectation reporting appears to work for suites without specs
    unless you have:
    1) An otherwise empty suite with an afterAll
    2) An afterAll'd suite whose first suite is empty (or whose first
    suite's first suite is empty (and so on))
- Changed afterAllError to afterAllEvent, so it can accommodate both
  errors and expectation failures. The reporter now receives a string
  instead of the actual error object. The loss of the object doesn't
  affect our reporters, but may be a nice-to-have for other reporters/
  the future.
- The gap between the expectations caught in Suite and QueueRunner (who
  triggers reporting via an injected callback) is an array injected into
  QR by the Suite. The array is then flushed at some point (currently
  after the attempt… functions). This works, but is a bit goofy.

[#73741654]
2014-08-26 18:04:12 -07:00
slackersoft
18eb6e2f36 Don't run npm package specs in browsers 2014-08-26 13:18:16 -07:00
Tomás Girardi
51462f369b Allow clearInterval to clear it's own interval
As described in issue #655, the handler of an interval cannot
successfully clear the same interval that generated it's invocation.

Solve this issue by changing the order in which interval's handlers are
called and then rescheduled to: first reschedule it and then call it.

The actual order (call first then reschedule) produces that, during the
execution of the interval's handler, the handler is not registered as
a function to run after a timeout or interval ("scheduledFunctions"),
because it was previously unregistered. Consequently, if the handler
calls clearInterval, that function wont be able to find the handler and
remove it completely.
2014-08-26 12:01:49 -04:00
slackersoft
ea57ad97cf Add some tests to make sure we're packaging up the npm properly 2014-08-26 08:08:04 -07:00
slackersoft
3132d98f23 Bump version to 2.0.4 now that I think npm files are sorted 2014-08-24 21:14:11 -07:00
slackersoft
b799f54bc9 Remove runtime dependency on 'glob' so we have no runtime deps
- Clean up .npmignore a bit more
2014-08-24 21:11:50 -07:00
Alexei Bykov
ac8ef2988d add better support of DOM nodes into equality matcher 2014-08-24 17:07:18 +04:00
slackersoft
3c051fc291 bump to 2.0.3 to fix npm dependencies 2014-08-22 22:50:46 -07:00
slackersoft
6b937da863 Fix npm dependencies 2014-08-22 22:47:43 -07:00
paladox2015
ae94dd1bfa Update json2.js 2014-06-27 10:51:02 +01:00
slackersoft
1bad048c15 Extract afterAll checking from queueRunner 2014-06-20 08:16:42 -07:00
slackersoft
f0892a55aa report when an async afterAll doesn't call in time 2014-06-06 18:41:06 -07:00
Gregg Van Hove
6066c71966 Add failing specs for expectation failures in afterAll 2014-04-18 16:37:27 -07:00
Gregg Van Hove
0d4b04d37c rename afterAllException to afterAllError
It should also handle expectation failures
2014-04-18 16:00:02 -07:00
Christopher Amavisca and Greg Cobb
668846147c Fix issues with displaying error messages for afterAll (browser compatibility)
- Switch from showing error stack to showing message/description since only chrome/ff support stack
- Fallback to error.description if error.message is undefined
- Made exceptionList variable name consistent between both reporters
2014-03-06 18:25:49 -08:00
Christopher Amavisca and Greg Cobb
76fafa0388 Deprecate suite/spec ordering hook .
- Remove parameter from env.execute()
- Remove deprecated test
- Set runnablesToRun to always start with the topSuite

[#66789174]
2014-03-06 16:54:53 -08:00
Christopher Amavisca and Greg Cobb
bed1c15ea4 HtmlReporter shows error alerts for afterAllExceptions
-Add list of exceptions in HtmlReporter to push to on error
-Create alerts for each exception in the list (with stack trace)

[#67055688]
2014-03-06 15:39:04 -08:00
Christopher Amavisca and Greg Cobb
6caf4c5de2 Print afterAllExceptions to the console.
- Add afterAllException function to ConsoleReporter
- Print the stack traces of the errors at the end of the console output

[#67055730]
2014-03-06 15:02:55 -08:00
Christopher Amavisca and Greg Cobb
97ae9a2d88 After all exceptions dispatch to reporter hook
- Add 'afterAllException' hook to reporter dispatch, we might want to make this more generic in the future
- Add afterAllException function to HtmlReporter

[#66789174]
2014-03-06 12:01:37 -08:00
Christopher Amavisca and Greg Cobb
a3c3505086 beforeAll can have expectations and passes expectation failures to its children
[#66789174]
2014-03-05 16:27:58 -08:00
Christopher Amavisca and Greg Cobb
a9e0112a9b Throw error if you add a custom matcher or equality outside of a runnable
[#66789174]
2014-03-05 14:37:17 -08:00
Christopher Amavisca and Greg Cobb
a2ac5ef3b6 Throw error if you define a spy outside of a runnable
[#66789174]
2014-03-05 14:27:19 -08:00
Christopher Amavisca and Greg Cobb
b200952195 Only clear resources if suite is not disabled
[#66789174]
2014-03-05 14:00:57 -08:00
Christopher Amavisca, Greg Cobb and Sheel Choksi
752a36d3ff Manage spys/matchers/custom equalities for beforeAll
- Refactor expectations to take list of matchers
- Add spyRegistry to manage runnables' spies
- Add clone util

[#66789174]
2014-03-05 10:28:37 -08:00
Gregg Van Hove and Sheel Choksi
52026fb0f7 beforeAll/afterAll can be timed out and errors are applied to all children specs 2014-03-03 16:13:59 -08:00
Gregg Van Hove and Sheel Choksi
e17a2cb1e0 share usercontext for full suite 2014-03-03 11:57:32 -08:00
Gregg Van Hove and Sheel Choksi
ec5695acc1 first (naive) pass at beforeAll/afterAll 2014-03-03 09:26:39 -08:00
pimterry
b1d4ab09af Add tests for call return value tracking 2013-12-08 13:40:25 +00:00
pimterry
3b52d015ea Track return values of spy functions 2013-12-08 13:40:24 +00:00
slackersoft
b5b77b318a Argument matcher for an array containing at least the specified entries 2013-10-03 18:21:47 -07:00
104 changed files with 5413 additions and 1705 deletions

View File

@@ -1,7 +1,7 @@
dist/
grunt/
images/
node_modules
pkg/
release_notes/
spec/
src/
@@ -9,12 +9,20 @@ Gemfile
Gemfile.lock
Rakefile
jasmine-core.gemspec
.rspec
.travis.yml
.jshintrc
.bundle/
.gitignore
.gitmodules
.idea
.jshintrc
.rspec
.sass-cache/
.travis.yml
*.sh
*.py
Gruntfile.js
lib/jasmine-core.rb
lib/jasmine-core/boot/
lib/jasmine-core/spec
lib/jasmine-core/version.rb
lib/jasmine-core/*.py
sauce_connect.log

View File

@@ -1,51 +1,59 @@
---
script: $TEST_COMMAND
language: ruby
cache: bundler
sudo: false
rvm: 1.9.3
script: $TEST_COMMAND
env:
global:
- USE_SAUCE=true
- NOKOGIRI_USE_SYSTEM_LIBRARIES=true
- TEST_COMMAND="bash travis-core-script.sh"
- JASMINE_BROWSER="firefox"
- SAUCE_OS="Linux"
- SAUCE_BROWSER_VERSION=''
- secure: WSPWhlnC4mWSnSPquX+m1/BCu5ch5NygkaHuM2Nea7lD8oS3XLX8QncZZAsQ4lnNfqoDDuBOizG0AESiqNvE4y6x5qvLLTS6q+ce255ZEMZ71TBdZgDEEvGMEjOPPsVXiXyTQOP1lwOPlrbZvaPgWV7e11KIBab6DfFcQpnvDgo=
- secure: SW7CJhZnwaNT749Gdnhvqb5rbXlAOsygUAzh9qhtyvbqXKkmJdBIEsO01YF6pbju1X2twE9JvWCOxeZju43NgQChJlPsGbjY2j3k/TdQeTAJesQe2K7ytwghunI30gjEovtRH0T3w1EmcKPH8yj5eBIcB2OYoJHx8KEC7e68q1g=
matrix:
include:
- env:
- USE_SAUCE=false
- TEST_COMMAND="bash travis-node-script.sh"
- env:
- JASMINE_BROWSER="safari"
- SAUCE_OS="OS X 10.8"
- SAUCE_BROWSER_VERSION=6
- env:
- JASMINE_BROWSER="safari"
- SAUCE_OS="OS X 10.6"
- SAUCE_BROWSER_VERSION=5
- env:
- JASMINE_BROWSER="internet explorer"
- SAUCE_OS="Windows 8"
- SAUCE_BROWSER_VERSION=10
- env:
- JASMINE_BROWSER="internet explorer"
- SAUCE_OS="Windows 7"
- SAUCE_BROWSER_VERSION=9
- env:
- JASMINE_BROWSER="internet explorer"
- SAUCE_OS="Windows 7"
- SAUCE_BROWSER_VERSION=8
- env:
- JASMINE_BROWSER="chrome"
- USE_SAUCE=true
- NOKOGIRI_USE_SYSTEM_LIBRARIES=true
- TEST_COMMAND="bash travis-core-script.sh"
- JASMINE_BROWSER="firefox"
- SAUCE_OS="Linux"
- SAUCE_BROWSER_VERSION=''
- env:
- JASMINE_BROWSER="phantomjs"
- USE_SAUCE=false
- env:
- USE_SAUCE=false
- JASMINE_BROWSER="phantomjs"
- TEST_COMMAND="bash travis-docs-script.sh"
- secure: WSPWhlnC4mWSnSPquX+m1/BCu5ch5NygkaHuM2Nea7lD8oS3XLX8QncZZAsQ4lnNfqoDDuBOizG0AESiqNvE4y6x5qvLLTS6q+ce255ZEMZ71TBdZgDEEvGMEjOPPsVXiXyTQOP1lwOPlrbZvaPgWV7e11KIBab6DfFcQpnvDgo=
- secure: SW7CJhZnwaNT749Gdnhvqb5rbXlAOsygUAzh9qhtyvbqXKkmJdBIEsO01YF6pbju1X2twE9JvWCOxeZju43NgQChJlPsGbjY2j3k/TdQeTAJesQe2K7ytwghunI30gjEovtRH0T3w1EmcKPH8yj5eBIcB2OYoJHx8KEC7e68q1g=
matrix:
include:
- env:
- USE_SAUCE=false
- TEST_COMMAND="bash travis-node-script.sh"
- env:
- JASMINE_BROWSER="safari"
- SAUCE_OS="OS X 10.8"
- SAUCE_BROWSER_VERSION=6
- env:
- JASMINE_BROWSER="safari"
- SAUCE_OS="OS X 10.6"
- SAUCE_BROWSER_VERSION=5
- env:
- JASMINE_BROWSER="internet explorer"
- SAUCE_OS="Windows 8.1"
- SAUCE_BROWSER_VERSION=11
- env:
- JASMINE_BROWSER="internet explorer"
- SAUCE_OS="Windows 8"
- SAUCE_BROWSER_VERSION=10
- env:
- JASMINE_BROWSER="internet explorer"
- SAUCE_OS="Windows 7"
- SAUCE_BROWSER_VERSION=9
- env:
- JASMINE_BROWSER="internet explorer"
- SAUCE_OS="Windows 7"
- SAUCE_BROWSER_VERSION=8
- env:
- JASMINE_BROWSER="chrome"
- SAUCE_OS="Linux"
- SAUCE_BROWSER_VERSION=''
- env:
- JASMINE_BROWSER="phantomjs"
- USE_SAUCE=false
- env:
- USE_SAUCE=false
- JASMINE_BROWSER="phantomjs"
- TEST_COMMAND="bash travis-docs-script.sh"

View File

@@ -9,8 +9,8 @@ Please submit pull requests via feature branches using the semi-standard workflo
1. Fork it
1. Clone your fork: (`git clone git@github.com:yourUserName/jasmine.git`)
1. Change directory: (`cd jasmine`)
1. Asign original repository to a remote named 'upstream': (`git remote add
upstream https://github.com/pivotal/jasmine.git`)
1. Assign original repository to a remote named 'upstream': (`git remote add
upstream https://github.com/jasmine/jasmine.git`)
1. Pull in changes not present in your local repository: (`git fetch upstream`)
1. Create your feature branch (`git checkout -b my-new-feature`)
1. Commit your changes (`git commit -am 'Add some feature'`)
@@ -67,7 +67,11 @@ To install the Ruby dependencies, you will need Ruby, Rubygems, and Bundler avai
$ bundle
...will install all of the Ruby dependencies.
...will install all of the Ruby dependencies. If the ffi gem fails to build its native extensions, you may need to manually install some system dependencies. On Ubuntu:
$ apt-get install gcc ruby ruby-dev libxml2 libxml2-dev libxslt1-dev
...should get you to the point that `bundle` can install everything.
To install the Node dependencies, you will need Node.js, Npm, and [Grunt](http://gruntjs.com/), the [grunt-cli](https://github.com/gruntjs/grunt-cli) and ensure that `grunt` is on your path.
@@ -94,13 +98,13 @@ Follow these tips and your pull request, patch, or suggestion is much more likel
### Running Specs
Jasmine uses the [Jasmine Ruby gem](http://github.com/pivotal/jasmine-gem) to test itself in browser.
Jasmine uses the [Jasmine Ruby gem](http://github.com/jasmine/jasmine-gem) to test itself in browser.
$ rake jasmine
...and then visit `http://localhost:8888` to run specs.
Jasmine uses Node.js with a custom runner to test outside of a browser.
Jasmine uses the [Jasmine NPM package](http://github.com/jasmine/jasmine-npm) to test itself in a Node.js/npm environment.
$ grunt execSpecsInNode

11
Gemfile
View File

@@ -1,12 +1,9 @@
source 'https://rubygems.org'
gem "jasmine", :git => 'https://github.com/pivotal/jasmine-gem.git'
# gem "jasmine", path: "/Users/pivotal/workspace/jasmine-gem"
unless ENV["TRAVIS"]
group :debug do
gem 'debugger'
end
end
gem "jasmine", :git => 'https://github.com/jasmine/jasmine-gem.git'
# gem "jasmine", path: "../jasmine-gem"
gemspec
gem "jasmine_selenium_runner", :github => 'jasmine/jasmine_selenium_runner'
gem "anchorman"

View File

@@ -37,10 +37,19 @@ module.exports = function(grunt) {
grunt.registerTask("execSpecsInNode",
"Run Jasmine core specs in Node.js",
function() {
var exitInfo = require("shelljs").exec("node_modules/.bin/jasmine");
if (exitInfo.code !== 0) {
grunt.fail.fatal("Specs Failed", exitInfo.code);
}
var done = this.async(),
Jasmine = require('jasmine'),
jasmineCore = require('./lib/jasmine-core.js'),
jasmine = new Jasmine({jasmineCore: jasmineCore});
jasmine.loadConfigFile('./spec/support/jasmine.json');
jasmine.configureDefaultReporter({
onComplete: function(passed) {
done(passed);
}
});
jasmine.execute();
}
);

View File

@@ -1,6 +1,6 @@
<a name="README">[<img src="https://rawgithub.com/pivotal/jasmine/master/images/jasmine-horizontal.svg" width="400px" />](http://jasmine.github.io)</a>
<a name="README">[<img src="https://rawgithub.com/jasmine/jasmine/master/images/jasmine-horizontal.svg" width="400px" />](http://jasmine.github.io)</a>
[![Build Status](https://travis-ci.org/pivotal/jasmine.png?branch=master)](https://travis-ci.org/pivotal/jasmine) [![Code Climate](https://codeclimate.com/github/pivotal/jasmine.png)](https://codeclimate.com/github/pivotal/jasmine)
[![Build Status](https://travis-ci.org/jasmine/jasmine.png?branch=master)](https://travis-ci.org/jasmine/jasmine) [![Code Climate](https://codeclimate.com/github/pivotal/jasmine.png)](https://codeclimate.com/github/pivotal/jasmine)
=======
@@ -11,17 +11,26 @@ Jasmine is a Behavior Driven Development testing framework for JavaScript. It do
Documentation & guides live here: [http://jasmine.github.io](http://jasmine.github.io/)
For a quick start guide of Jasmine 2.0, see the beginning of [http://jasmine.github.io/2.0/introduction.html](http://jasmine.github.io/2.0/introduction.html)
Upgrading from Jasmine 1.x? Check out the [2.0 release notes](https://github.com/pivotal/jasmine/blob/v2.0.0/release_notes/20.md) for a list of what's new (including breaking interface changes).
Upgrading from Jasmine 1.x? Check out the [2.0 release notes](https://github.com/jasmine/jasmine/blob/v2.0.0/release_notes/20.md) for a list of what's new (including breaking interface changes). You can also read the [upgrade guide](http://jasmine.github.io/2.0/upgrading.html).
## Contributing
Please read the [contributors' guide](https://github.com/pivotal/jasmine/blob/master/CONTRIBUTING.md)
Please read the [contributors' guide](https://github.com/jasmine/jasmine/blob/master/CONTRIBUTING.md)
## Installation
For the Jasmine NPM module:<br>
[https://github.com/jasmine/jasmine-npm](https://github.com/jasmine/jasmine-npm)
For the Jasmine Ruby Gem:<br>
[https://github.com/jasmine/jasmine-gem](https://github.com/jasmine/jasmine-gem)
For the Jasmine Python Egg:<br>
[https://github.com/jasmine/jasmine-py](https://github.com/jasmine/jasmine-py)
To install Jasmine on your local box:
* Clone Jasmine - `git clone https://github.com/pivotal/jasmine.git`
* Clone Jasmine - `git clone https://github.com/jasmine/jasmine.git`
* Create a Jasmine directory in your project - `mkdir my-project/jasmine`
* Move latest dist to your project directory - `mv jasmine/dist/jasmine-standalone-2.0.0.zip my-project/jasmine`
* Change directory - `cd my-project/jasmine`
@@ -36,12 +45,9 @@ Add the following to your HTML file:
<script type="text/javascript" src="jasmine/lib/jasmine-2.0.0/jasmine-html.js"></script>
<script type="text/javascript" src="jasmine/lib/jasmine-2.0.0/boot.js"></script>
For the Jasmine Ruby Gem:<br>
[https://github.com/pivotal/jasmine-gem](https://github.com/pivotal/jasmine-gem)
For the Jasmine Python Egg:<br>
[https://github.com/pivotal/jasmine-py](https://github.com/pivotal/jasmine-py)
## Supported environments
Jasmine tests itself across many browsers (Safari, Chrome, Firefox, PhantomJS, and new Internet Explorer) as well as node. To see the exact version tests are run against look at our [.travis.yml](https://github.com/jasmine/jasmine/blob/master/.travis.yml)
## Support
@@ -53,12 +59,13 @@ For the Jasmine Python Egg:<br>
## Maintainers
* [Davis W. Frank](mailto:dwfrank@pivotallabs.com), Pivotal Labs
* [Rajan Agaskar](mailto:rajan@pivotallabs.com), Pivotal Labs
* [Sheel Choksi](mailto:schoksi@pivotallabs.com), Pivotal Labs
* [Davis W. Frank](mailto:dwfrank@pivotal.io), Pivotal Labs
* [Rajan Agaskar](mailto:rajan@pivotal.io), Pivotal Labs
* [Gregg Van Hove](mailto:gvanhove@pivotal.io), Pivotal Labs
### Maintainers Emeritus
* [Christian Williams](mailto:antixian666@gmail.com), Square
* [Christian Williams](mailto:antixian666@gmail.com), Cloud Foundry
* Sheel Choksi
Copyright (c) 2008-2014 Pivotal Labs. This software is licensed under the MIT License.

View File

@@ -15,11 +15,16 @@ Please attempt to keep commits to `master` small, but cohesive. If a feature is
We attempt to stick to [Semantic Versioning](http://semver.org/). Most of the time, development should be against a new minor version - fixing bugs and adding new features that are backwards compatible.
The current version lives in the file `/package.json`. This file should be set to the version that is _currently_ under development. That is, if version 1.0.0 is the current release then version should be incremented say, to 1.1.0.
The current version lives in the file `/package.json`. This version will be the version number that is currently released. When releasing a new version, update `package.json` and `bower.json` with the new version and `grunt build:copyVersionToGem` to update the gem version number.
This version is used by both `jasmine.js` and the `jasmine-core` Ruby gem.
Note that Jasmine should *not* use the "patch" version number. Let downstream projects rev their patch versions as needed, keeping their major and minor version numbers in sync with Jasmine core.
Note that Jasmine should only use the "patch" version number in the following cases:
* Changes related to packaging for a specific platform (npm, gem, or pip).
* Fixes for regressions.
When jasmine-core revs its major or minor version, the binding libraries should also rev to that version.
## Release
@@ -33,7 +38,7 @@ When ready to release - specs are all green and the stories are done:
1. Build the standalone distribution with `grunt buildStandaloneDist`
1. Make sure you add the new ZIP file to git
1. Should we still do this? Given we want to use guthub releases...
1. Should we still do this? Given we want to use github releases...
### Release the Python egg
@@ -52,9 +57,16 @@ When ready to release - specs are all green and the stories are done:
1. `npm adduser` to save your credentials locally
1. `npm publish .` to publish what's in `package.json`
### Release the docs
Probably only need to do this when releasing a minor version, and not a patch version.
1. `cp edge ${version}` to copy the current edge docs to the new version
1. Add a link to the new version in `index.html`
### Finally
1. Visit the [Releases page for Jasmine](https://github.com/pivotal/jasmine/releases), find the tag just pushed.
1. Visit the [Releases page for Jasmine](https://github.com/jasmine/jasmine/releases), find the tag just pushed.
1. Paste in a link to the correct release notes for this release. The link should reference the blob and tag correctly, and the markdown file for the notes.
1. If it is a pre-release, mark it as such.
1. Attach the standalone zipfile

38
bower.json Normal file
View File

@@ -0,0 +1,38 @@
{
"name": "jasmine-core",
"version": "2.2.0",
"homepage": "http://jasmine.github.io",
"authors": [
"slackersoft <gregg@slackersoft.net>"
],
"description": "Official packaging of Jasmine's core files",
"keywords": [
"jasmine",
"bdd"
],
"license": "MIT",
"moduleType": "globals",
"ignore": [
"**/.*",
"dist",
"grunt",
"node_modules",
"pkg",
"release_notes",
"spec",
"src",
"Gemfile",
"Gemfile.lock",
"Rakefile",
"jasmine-core.gemspec",
"*.sh",
"*.py",
"Gruntfile.js"
"lib/jasmine-core.rb",
"lib/jasmine-core/boot/",
"lib/jasmine-core/spec",
"lib/jasmine-core/version.rb",
"lib/jasmine-core/*.py",
"sauce_connect.log"
]
}

BIN
dist/jasmine-standalone-2.0.3.zip vendored Normal file

Binary file not shown.

BIN
dist/jasmine-standalone-2.1.0.zip vendored Normal file

Binary file not shown.

BIN
dist/jasmine-standalone-2.1.1.zip vendored Normal file

Binary file not shown.

BIN
dist/jasmine-standalone-2.1.2.zip vendored Normal file

Binary file not shown.

BIN
dist/jasmine-standalone-2.1.3.zip vendored Normal file

Binary file not shown.

BIN
dist/jasmine-standalone-2.2.0.zip vendored Normal file

Binary file not shown.

View File

@@ -1,23 +1,23 @@
<!DOCTYPE HTML>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<title>Jasmine Spec Runner v<%= jasmineVersion %></title>
<link rel="shortcut icon" type="image/png" href="lib/jasmine-<%= jasmineVersion %>/jasmine_favicon.png">
<link rel="stylesheet" type="text/css" href="lib/jasmine-<%= jasmineVersion %>/jasmine.css">
<link rel="stylesheet" href="lib/jasmine-<%= jasmineVersion %>/jasmine.css">
<script type="text/javascript" src="lib/jasmine-<%= jasmineVersion %>/jasmine.js"></script>
<script type="text/javascript" src="lib/jasmine-<%= jasmineVersion %>/jasmine-html.js"></script>
<script type="text/javascript" src="lib/jasmine-<%= jasmineVersion %>/boot.js"></script>
<script src="lib/jasmine-<%= jasmineVersion %>/jasmine.js"></script>
<script src="lib/jasmine-<%= jasmineVersion %>/jasmine-html.js"></script>
<script src="lib/jasmine-<%= jasmineVersion %>/boot.js"></script>
<!-- include source files here... -->
<script type="text/javascript" src="src/Player.js"></script>
<script type="text/javascript" src="src/Song.js"></script>
<script src="src/Player.js"></script>
<script src="src/Song.js"></script>
<!-- include spec files here... -->
<script type="text/javascript" src="spec/SpecHelper.js"></script>
<script type="text/javascript" src="spec/PlayerSpec.js"></script>
<script src="spec/SpecHelper.js"></script>
<script src="spec/PlayerSpec.js"></script>
</head>

View File

@@ -6,11 +6,11 @@ Gem::Specification.new do |s|
s.name = "jasmine-core"
s.version = Jasmine::Core::VERSION
s.platform = Gem::Platform::RUBY
s.authors = ["Rajan Agaskar", "Davis W. Frank", "Christian Williams"]
s.authors = ["Rajan Agaskar", "Davis W. Frank", "Gregg Van Hove"]
s.summary = %q{JavaScript BDD framework}
s.description = %q{Test your JavaScript without any framework dependencies, in any environment, and with a nice descriptive syntax.}
s.email = %q{jasmine-js@googlegroups.com}
s.homepage = "http://pivotal.github.com/jasmine"
s.homepage = "http://jasmine.github.io"
s.rubyforge_project = "jasmine-core"
s.license = "MIT"

View File

@@ -1,5 +1,5 @@
/*
Copyright (c) 2008-2014 Pivotal Labs
Copyright (c) 2008-2015 Pivotal Labs
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
@@ -54,7 +54,10 @@ getJasmineRequireObj().ConsoleReporter = function() {
red: '\x1B[31m',
yellow: '\x1B[33m',
none: '\x1B[0m'
};
},
failedSuites = [];
print('ConsoleReporter is deprecated and will be removed in a future version.');
this.jasmineStarted = function() {
specCount = 0;
@@ -89,9 +92,12 @@ getJasmineRequireObj().ConsoleReporter = function() {
printNewline();
var seconds = timer.elapsed() / 1000;
print('Finished in ' + seconds + ' ' + plural('second', seconds));
printNewline();
for(i = 0; i < failedSuites.length; i++) {
suiteFailureDetails(failedSuites[i]);
}
onComplete(failureCount === 0);
};
@@ -116,6 +122,13 @@ getJasmineRequireObj().ConsoleReporter = function() {
}
};
this.suiteDone = function(result) {
if (result.failedExpectations && result.failedExpectations.length > 0) {
failureCount++;
failedSuites.push(result);
}
};
return this;
function printNewline() {
@@ -160,6 +173,17 @@ getJasmineRequireObj().ConsoleReporter = function() {
printNewline();
}
function suiteFailureDetails(result) {
for (var i = 0; i < result.failedExpectations.length; i++) {
printNewline();
print(colored('red', 'An error was thrown in an afterAll'));
printNewline();
print(colored('red', 'AfterAll ' + result.failedExpectations[i].message));
}
printNewline();
}
}
return ConsoleReporter;

View File

@@ -1,29 +1,37 @@
module.exports = require("./jasmine-core/jasmine.js");
module.exports.boot = require('./jasmine-core/node_boot.js');
module.exports.files = (function() {
var path = require('path'),
fs = require('fs'),
glob = require('glob');
var path = require('path'),
fs = require('fs');
var rootPath = path.join(__dirname, "jasmine-core"),
bootFiles = ['boot.js'],
nodeBootFiles = ['node_boot.js'];
var rootPath = path.join(__dirname, "jasmine-core"),
bootFiles = ['boot.js'],
nodeBootFiles = ['node_boot.js'],
cssFiles = [],
jsFiles = [],
jsFilesToSkip = ['jasmine.js'].concat(bootFiles, nodeBootFiles);
var cssFiles = glob.sync(path.join(rootPath, '*.css')).map(path.basename);
var jsFiles = glob.sync(path.join(rootPath, '*.js')).map(path.basename);
fs.readdirSync(rootPath).forEach(function(file) {
if(fs.statSync(path.join(rootPath, file)).isFile()) {
switch(path.extname(file)) {
case '.css':
cssFiles.push(file);
break;
case '.js':
if (jsFilesToSkip.indexOf(file) < 0) {
jsFiles.push(file);
}
break;
}
}
});
['jasmine.js'].concat(bootFiles, nodeBootFiles).forEach(function(file) {
jsFiles.splice(jsFiles.indexOf(file), 1);
});
return {
path: rootPath,
bootDir: rootPath,
bootFiles: bootFiles,
nodeBootFiles: nodeBootFiles,
cssFiles: cssFiles,
jsFiles: ['jasmine.js'].concat(jsFiles),
imagesDir: path.join(__dirname, '../images')
};
}());
module.exports.files = {
path: rootPath,
bootDir: rootPath,
bootFiles: bootFiles,
nodeBootFiles: nodeBootFiles,
cssFiles: cssFiles,
jsFiles: ['jasmine.js'].concat(jsFiles),
imagesDir: path.join(__dirname, '../images')
};

View File

@@ -1,5 +1,5 @@
/*
Copyright (c) 2008-2014 Pivotal Labs
Copyright (c) 2008-2015 Pivotal Labs
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
@@ -21,7 +21,7 @@ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/**
Starting with version 2.0, this file "boots" Jasmine, performing all of the necessary initialization before executing the loaded environment and all of a project's specs. This file should be loaded after `jasmine.js`, but before any project source files or spec files are loaded. Thus this file can also be used to customize Jasmine for a project.
Starting with version 2.0, this file "boots" Jasmine, performing all of the necessary initialization before executing the loaded environment and all of a project's specs. This file should be loaded after `jasmine.js` and `jasmine_html.js`, but before any project source files or spec files are loaded. Thus this file can also be used to customize Jasmine for a project.
If a project is using Jasmine via the standalone distribution, this file can be customized directly. If a project is using Jasmine via the [Ruby gem][jasmine-gem], this file can be copied into the support directory via `jasmine copy_boot_js`. Other environments (e.g., Python) will have different mechanisms.
@@ -84,7 +84,8 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
var htmlReporter = new jasmine.HtmlReporter({
env: env,
onRaiseExceptionsClick: function() { queryString.setParam("catch", !env.catchingExceptions()); },
onRaiseExceptionsClick: function() { queryString.navigateWithNewParam("catch", !env.catchingExceptions()); },
addToExistingQueryString: function(key, value) { return queryString.fullStringWithNewParam(key, value); },
getContainer: function() { return document.body; },
createElement: function() { return document.createElement.apply(document, arguments); },
createTextNode: function() { return document.createTextNode.apply(document, arguments); },

View File

@@ -1,5 +1,5 @@
/**
Starting with version 2.0, this file "boots" Jasmine, performing all of the necessary initialization before executing the loaded environment and all of a project's specs. This file should be loaded after `jasmine.js`, but before any project source files or spec files are loaded. Thus this file can also be used to customize Jasmine for a project.
Starting with version 2.0, this file "boots" Jasmine, performing all of the necessary initialization before executing the loaded environment and all of a project's specs. This file should be loaded after `jasmine.js` and `jasmine_html.js`, but before any project source files or spec files are loaded. Thus this file can also be used to customize Jasmine for a project.
If a project is using Jasmine via the standalone distribution, this file can be customized directly. If a project is using Jasmine via the [Ruby gem][jasmine-gem], this file can be copied into the support directory via `jasmine copy_boot_js`. Other environments (e.g., Python) will have different mechanisms.
@@ -62,7 +62,8 @@
*/
var htmlReporter = new jasmine.HtmlReporter({
env: env,
onRaiseExceptionsClick: function() { queryString.setParam("catch", !env.catchingExceptions()); },
onRaiseExceptionsClick: function() { queryString.navigateWithNewParam("catch", !env.catchingExceptions()); },
addToExistingQueryString: function(key, value) { return queryString.fullStringWithNewParam(key, value); },
getContainer: function() { return document.body; },
createElement: function() { return document.createElement.apply(document, arguments); },
createTextNode: function() { return document.createTextNode.apply(document, arguments); },

View File

@@ -1,6 +1,6 @@
describe("Player", function() {
var Player = require('../../jasmine_examples/Player.js');
var Song = require('../../jasmine_examples/Song.js');
var Player = require('../../lib/jasmine_examples/Player');
var Song = require('../../lib/jasmine_examples/Song');
var player;
var song;

View File

@@ -1,5 +1,5 @@
/*
Copyright (c) 2008-2014 Pivotal Labs
Copyright (c) 2008-2015 Pivotal Labs
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
@@ -40,13 +40,15 @@ jasmineRequire.HtmlReporter = function(j$) {
createElement = options.createElement,
createTextNode = options.createTextNode,
onRaiseExceptionsClick = options.onRaiseExceptionsClick || function() {},
addToExistingQueryString = options.addToExistingQueryString || defaultQueryString,
timer = options.timer || noopTimer,
results = [],
specsExecuted = 0,
failureCount = 0,
pendingSpecCount = 0,
htmlReporterMain,
symbols;
symbols,
failedSuites = [];
this.initialize = function() {
clearPrior();
@@ -83,6 +85,10 @@ jasmineRequire.HtmlReporter = function(j$) {
};
this.suiteDone = function(result) {
if (result.status == 'failed') {
failedSuites.push(result);
}
if (currentParent == topResults) {
return;
}
@@ -96,7 +102,7 @@ jasmineRequire.HtmlReporter = function(j$) {
var failures = [];
this.specDone = function(result) {
if(noExpectations(result) && console && console.error) {
if(noExpectations(result) && typeof console !== 'undefined' && typeof console.error !== 'undefined') {
console.error('Spec \'' + result.fullName + '\' has no expectations.');
}
@@ -178,6 +184,15 @@ jasmineRequire.HtmlReporter = function(j$) {
alert.appendChild(createDom('span', {className: statusBarClassName}, statusBarMessage));
for(i = 0; i < failedSuites.length; i++) {
var failedSuite = failedSuites[i];
for(var j = 0; j < failedSuite.failedExpectations.length; j++) {
var errorBarMessage = 'AfterAll ' + failedSuite.failedExpectations[j].message;
var errorBarClassName = 'bar errored';
alert.appendChild(createDom('span', {className: errorBarClassName}, errorBarMessage));
}
}
var results = find('.results');
results.appendChild(summary);
@@ -206,6 +221,9 @@ jasmineRequire.HtmlReporter = function(j$) {
if(noExpectations(resultNode.result)) {
specDescription = 'SPEC HAS NO EXPECTATIONS ' + specDescription;
}
if(resultNode.result.status === 'pending' && resultNode.result.pendingReason !== '') {
specDescription = specDescription + ' PENDING WITH MESSAGE: ' + resultNode.result.pendingReason;
}
specListNode.appendChild(
createDom('li', {
className: resultNode.result.status,
@@ -253,7 +271,7 @@ jasmineRequire.HtmlReporter = function(j$) {
function clearPrior() {
// return the reporter
var oldReporter = find('');
if(oldReporter) {
getContainer().removeChild(oldReporter);
}
@@ -292,7 +310,11 @@ jasmineRequire.HtmlReporter = function(j$) {
}
function specHref(result) {
return '?spec=' + encodeURIComponent(result.fullName);
return addToExistingQueryString('spec', result.fullName);
}
function defaultQueryString(key, value) {
return '?' + key + '=' + value;
}
function setMenuModeTo(mode) {
@@ -344,10 +366,14 @@ jasmineRequire.ResultsNode = function() {
jasmineRequire.QueryString = function() {
function QueryString(options) {
this.setParam = function(key, value) {
this.navigateWithNewParam = function(key, value) {
options.getWindowLocation().search = this.fullStringWithNewParam(key, value);
};
this.fullStringWithNewParam = function(key, value) {
var paramMap = queryStringToParamMap();
paramMap[key] = value;
options.getWindowLocation().search = toQueryString(paramMap);
return toQueryString(paramMap);
};
this.getParam = function(key) {

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
/*
http://www.JSON.org/json2.js
2009-08-17
json2.js
2014-02-04
Public Domain.
@@ -8,6 +8,14 @@
See http://www.JSON.org/js.html
This code should be minified before deployment.
See http://javascript.crockford.com/jsmin.html
USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
NOT CONTROL.
This file creates a global JSON object containing two methods: stringify
and parse.
@@ -136,15 +144,9 @@
This is a reference implementation. You are free to copy, modify, or
redistribute.
This code should be minified before deployment.
See http://javascript.crockford.com/jsmin.html
USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
NOT CONTROL.
*/
/*jslint evil: true */
/*jslint evil: true, regexp: true */
/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply,
call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
@@ -153,16 +155,16 @@
test, toJSON, toString, valueOf
*/
"use strict";
// Create a JSON object only if one does not already exist. We create the
// methods in a closure to avoid creating global variables.
if (!this.JSON) {
this.JSON = {};
if (typeof JSON !== 'object') {
JSON = {};
}
(function () {
'use strict';
function f(n) {
// Format integers to have at least two digits.
@@ -171,37 +173,30 @@ if (!this.JSON) {
if (typeof Date.prototype.toJSON !== 'function') {
Date.prototype.toJSON = function (key) {
Date.prototype.toJSON = function () {
return isFinite(this.valueOf()) ?
this.getUTCFullYear() + '-' +
f(this.getUTCMonth() + 1) + '-' +
f(this.getUTCDate()) + 'T' +
f(this.getUTCHours()) + ':' +
f(this.getUTCMinutes()) + ':' +
f(this.getUTCSeconds()) + 'Z' : null;
return isFinite(this.valueOf())
? this.getUTCFullYear() + '-' +
f(this.getUTCMonth() + 1) + '-' +
f(this.getUTCDate()) + 'T' +
f(this.getUTCHours()) + ':' +
f(this.getUTCMinutes()) + ':' +
f(this.getUTCSeconds()) + 'Z'
: null;
};
String.prototype.toJSON =
Number.prototype.toJSON =
Boolean.prototype.toJSON = function (key) {
return this.valueOf();
};
String.prototype.toJSON =
Number.prototype.toJSON =
Boolean.prototype.toJSON = function () {
return this.valueOf();
};
}
var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
var cx,
escapable,
gap,
indent,
meta = { // table of character substitutions
'\b': '\\b',
'\t': '\\t',
'\n': '\\n',
'\f': '\\f',
'\r': '\\r',
'"' : '\\"',
'\\': '\\\\'
},
meta,
rep;
@@ -213,17 +208,17 @@ if (!this.JSON) {
// sequences.
escapable.lastIndex = 0;
return escapable.test(string) ?
'"' + string.replace(escapable, function (a) {
var c = meta[a];
return typeof c === 'string' ? c :
'\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
}) + '"' :
'"' + string + '"';
return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
var c = meta[a];
return typeof c === 'string'
? c
: '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
}) + '"' : '"' + string + '"';
}
function str(key, holder) {
// Produce a string from holder[key].
var i, // The loop counter.
@@ -301,11 +296,11 @@ if (!this.JSON) {
// Join all of the elements together, separated with commas, and wrap them in
// brackets.
v = partial.length === 0 ? '[]' :
gap ? '[\n' + gap +
partial.join(',\n' + gap) + '\n' +
mind + ']' :
'[' + partial.join(',') + ']';
v = partial.length === 0
? '[]'
: gap
? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']'
: '[' + partial.join(',') + ']';
gap = mind;
return v;
}
@@ -315,8 +310,8 @@ if (!this.JSON) {
if (rep && typeof rep === 'object') {
length = rep.length;
for (i = 0; i < length; i += 1) {
k = rep[i];
if (typeof k === 'string') {
if (typeof rep[i] === 'string') {
k = rep[i];
v = str(k, value);
if (v) {
partial.push(quote(k) + (gap ? ': ' : ':') + v);
@@ -328,7 +323,7 @@ if (!this.JSON) {
// Otherwise, iterate through all of the keys in the object.
for (k in value) {
if (Object.hasOwnProperty.call(value, k)) {
if (Object.prototype.hasOwnProperty.call(value, k)) {
v = str(k, value);
if (v) {
partial.push(quote(k) + (gap ? ': ' : ':') + v);
@@ -340,9 +335,11 @@ if (!this.JSON) {
// Join all of the member texts together, separated with commas,
// and wrap them in braces.
v = partial.length === 0 ? '{}' :
gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' +
mind + '}' : '{' + partial.join(',') + '}';
v = partial.length === 0
? '{}'
: gap
? '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}'
: '{' + partial.join(',') + '}';
gap = mind;
return v;
}
@@ -351,7 +348,18 @@ if (!this.JSON) {
// If the JSON object does not yet have a stringify method, give it one.
if (typeof JSON.stringify !== 'function') {
escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
meta = { // table of character substitutions
'\b': '\\b',
'\t': '\\t',
'\n': '\\n',
'\f': '\\f',
'\r': '\\r',
'"' : '\\"',
'\\': '\\\\'
};
JSON.stringify = function (value, replacer, space) {
// The stringify method takes a value and an optional replacer, and an optional
// space parameter, and returns a JSON text. The replacer can be a function
// that can replace values, or an array of strings that will select the keys.
@@ -382,7 +390,7 @@ if (!this.JSON) {
rep = replacer;
if (replacer && typeof replacer !== 'function' &&
(typeof replacer !== 'object' ||
typeof replacer.length !== 'number')) {
typeof replacer.length !== 'number')) {
throw new Error('JSON.stringify');
}
@@ -397,6 +405,7 @@ if (!this.JSON) {
// If the JSON object does not yet have a parse method, give it one.
if (typeof JSON.parse !== 'function') {
cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
JSON.parse = function (text, reviver) {
// The parse method takes a text and an optional reviver function, and returns
@@ -412,7 +421,7 @@ if (!this.JSON) {
var k, v, value = holder[key];
if (value && typeof value === 'object') {
for (k in value) {
if (Object.hasOwnProperty.call(value, k)) {
if (Object.prototype.hasOwnProperty.call(value, k)) {
v = walk(value, k);
if (v !== undefined) {
value[k] = v;
@@ -430,6 +439,7 @@ if (!this.JSON) {
// Unicode characters with escape sequences. JavaScript handles many characters
// incorrectly, either silently deleting them, or treating them as line endings.
text = String(text);
cx.lastIndex = 0;
if (cx.test(text)) {
text = text.replace(cx, function (a) {
@@ -451,10 +461,10 @@ if (!this.JSON) {
// we look to see that the remaining characters are only whitespace or ']' or
// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
if (/^[\],:{}\s]*$/.
test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').
replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').
replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
if (/^[\],:{}\s]*$/
.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
.replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
// In the third stage we use the eval function to compile the text into a
// JavaScript structure. The '{' operator is subject to a syntactic ambiguity
@@ -466,8 +476,9 @@ replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
// In the optional fourth stage, we recursively walk the new structure, passing
// each name/value pair to a reviver function for possible transformation.
return typeof reviver === 'function' ?
walk({'': j}, '') : j;
return typeof reviver === 'function'
? walk({'': j}, '')
: j;
}
// If the text is not JSON parseable, then a SyntaxError is thrown.

View File

@@ -1,5 +1,5 @@
/*
Copyright (c) 2008-2014 Pivotal Labs
Copyright (c) 2008-2015 Pivotal Labs
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the

View File

@@ -4,6 +4,6 @@
#
module Jasmine
module Core
VERSION = "2.0.2"
VERSION = "2.2.0"
end
end

View File

@@ -1,10 +1,10 @@
{
"name": "jasmine-core",
"license": "MIT",
"version": "2.0.2",
"version": "2.2.0",
"repository": {
"type": "git",
"url": "https://github.com/pivotal/jasmine.git"
"url": "https://github.com/jasmine/jasmine.git"
},
"description": "Official packaging of Jasmine's core files for use by Node.js projects.",
"homepage": "http://jasmine.github.io",
@@ -17,7 +17,7 @@
"grunt-contrib-compress": "~0.5.2",
"shelljs": "~0.1.4",
"glob": "~3.2.9",
"jasmine": "https://github.com/pivotal/jasmine-npm/archive/master.tar.gz",
"jasmine": "https://github.com/jasmine/jasmine-npm/archive/master.tar.gz",
"load-grunt-tasks": "^0.4.0"
}
}

22
release_notes/1.3.0.md Normal file
View File

@@ -0,0 +1,22 @@
# Jasmine Core 1.3.0 Release Notes
## Summary
This version was a very incremental release that merged in some pull requests for bug fixes.
## Features
* HTML Runner exposes UI to not swallow Exceptions, instead raising as soon as thrown
* Migrated homepage content to Wiki
* Made a far more useful [tutorial page](http://pivotal.github.com/jasmine)
* Added a `toBeNaN` matcher
## Fixes
* Better detection of in-browser vs. not
* `afterEach` functions will run now even when there is a timeout
* `toBeCloseTo` matcher is more accurate
* More explicit matcher messages for spies
* Better equality comparisons for regular expressions
* Improvements to the Pretty Printer: controllable recursion depth, don't include inherited properties
* Fix where `for` was being used as a property on an object (failed on IE)

12
release_notes/1.3.1.md Normal file
View File

@@ -0,0 +1,12 @@
# Jasmine Core 1.3.1 Release Notes
## Summary
This release is for browser compatibility fixes
## Changes
### Features
Fixing test runner failures in IE 6/7/8

83
release_notes/2.1.0.md Normal file
View File

@@ -0,0 +1,83 @@
# Jasmine Core 2.1.0 Release Notes
## Summary
This is the release of Jasmine 2.1.
## Features
- Support for focused specs via `fit` and `fdescribe`
- Support for `beforeAll` and `afterAll`
- Support for an explicit `fail` function, both in synchronous and asynchronous specs
- Allow custom timeout for `beforeEach`, `afterEach`, `beforeAll`, `afterAll` and `it`
- Spies now track return values
- Specs can now specify their own timeouts
- Testing in Node.js via the official Jasmine Node Module
- Spec results now have `suiteResults` method that behaves similarly to to `specResults`
- HtmlReporter shows error alerts for afterAllExceptions
## Bugs
- CI now works for IE8 (this was releated to `ConsoleReporter` below)
- Detect global object properly when getting the jasmine require obj
- Fixes Issue #[569][issue_569] - [Tracker Story #73684570](http://www.pivotaltracker.com/story/73684570)
## Deprecations
### `ConsoleReporter` as part of Jasmine core
The Console Reporter exists nearly entirely for the old manner of running Jasmine's own specs in node.js. As we are now supporting node.js officially, this reporter code no longer needs to be in this repo and instead will be in the Jasmine npm.
For now you will see a deprecation message. It will be removed entirely in Jasmine 3.0.
## Documentation
- Release Notes from previous releases now live at [Jasmine's GitHub release page][releases]. See Tracker Story #[54582902][tracker_1]
- Better instructions for releasing new documentation
[releases]: https://github.com/pivotal/jasmine/releases
[tracker_1]: http://www.pivotaltracker.com/story/54582902
## Pull Requests and Issues
- Simplification of HTMLtags in SpecRunner.html
- Merges #[700][issue_700] from @tkrotoff
- `toContain` works with array-like objects (Arguments, HTMLCollections, etc)
- Merges #[699][issue_699] from @charleshansen
- Fixed isPendingSpecException test title
- Merges #[691][issue_691] from @ertrzyiks
- Fixed an issue with example code in the npm
- Merges #[686][issue_686] from @akoptsov
- When the Jasmine clock is installed and date is mocked, `new Date() instanceof Date` should equal `true` Issue #[678][issue_678] & Issue #[679][issue_679] from @chernetsov
- Support for an explicit `fail` function, both in synchronous and asynchronous specs
- Fixes Issue #[567][issue_567], Issue #[568][issue_568], and Issue #[563][issue_563]
- Allow custom timeout for `beforeEach`, `afterEach`, `beforeAll`, `afterAll` and `it`
- Fixes Issue #[483][issue_483] - specs can now specify their own timeouts
- Spies can track return values
- Fixes Issue #[660][issue_660], Merged Issue #[669][issue_669] from @mkhanal
- Interval handlers can now clear their interval
- Fixes Issue #[655][issue_655] Merged Issue #[658][issue_658] from @tgirardi
- Updated to the latest `json2.js`
- Merges #[616][issue_616] from @apaladox2015
------
_Release Notes generated with [Anchorman](http://github.com/infews/anchorman)_
[issue_569]: http://github.com/pivotal/jasmine/issues/569
[issue_700]: http://github.com/pivotal/jasmine/issues/700
[issue_699]: http://github.com/pivotal/jasmine/issues/699
[issue_691]: http://github.com/pivotal/jasmine/issues/691
[issue_678]: http://github.com/pivotal/jasmine/issues/678
[issue_679]: http://github.com/pivotal/jasmine/issues/679
[issue_567]: http://github.com/pivotal/jasmine/issues/567
[issue_568]: http://github.com/pivotal/jasmine/issues/568
[issue_563]: http://github.com/pivotal/jasmine/issues/563
[issue_483]: http://github.com/pivotal/jasmine/issues/483
[issue_660]: http://github.com/pivotal/jasmine/issues/660
[issue_669]: http://github.com/pivotal/jasmine/issues/669
[issue_655]: http://github.com/pivotal/jasmine/issues/655
[issue_658]: http://github.com/pivotal/jasmine/issues/658
[issue_616]: http://github.com/pivotal/jasmine/issues/616
[issue_686]: http://github.com/pivotal/jasmine/issues/686

14
release_notes/2.1.1.md Normal file
View File

@@ -0,0 +1,14 @@
# Jasmine Core 2.1.1 Release Notes
## Summary
This is a hotfix release of jasmine core to fix a breaking change with events emitted by the top-level suite
## Issues
- Top-level suite triggers suiteStarted and suiteEnd to be consistent
- Fixes [#706](http://github.com/pivotal/jasmine/issues/706)
------
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_

14
release_notes/2.1.2.md Normal file
View File

@@ -0,0 +1,14 @@
# Jasmine Core 2.1.2 Release Notes
## Summary
This is a hotfix release of jasmine core to fix a breaking change with reporting when all of the specs in a suite are pending.
## Changes
- Suites still run their children even if none are executable
- Fixes [#707](http://github.com/pivotal/jasmine/issues/707)
------
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_

21
release_notes/2.1.3.md Normal file
View File

@@ -0,0 +1,21 @@
# Jasmine Core 2.1.3 Release Notes
## Summary
This release is primarily a bug-fix release to clean up some recent regressions.
## Pull Requests & Issues
* Top level suite no longer reports suiteStart and suiteDone
- Fixes [#716](https://github.com/jasmine/jasmine/issues/716)
* Don't keep the expected and actual for a passed expectation
- Fixes [#640](https://github.com/jasmine/jasmine/issues/640)
- Fixes [#690](https://github.com/jasmine/jasmine/issues/690)
* Use the new build env on Travis
- Merges [#712](https://github.com/jasmine/jasmine/issues/712) from @joshk
------
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_

98
release_notes/2.2.0.md Normal file
View File

@@ -0,0 +1,98 @@
# Jasmine Core 2.2.0 Release Notes
## Changes
* `ObjectContaining` no longer tries to track exact mismatches
* HTML reporter keeps extra query params when focusing on a spec or suite
* Check custom properties on Arrays when computing equality
* Better error message if `spyOn` is called without a method name
* Rename `jasmineMatches` to `asymmetricMatch`
* Don't double escape focus spec links
* Jasmine equality checks if either side implements `asymmetricMatch`
* Add asymmetric equality tester to match a string with a RegExp
* Add jshint to node build on Travis for pull request builds
* Restructure node examples directory to look more realistic
## Pull Requests & Issues
* Add a basic bower config
- Fixes [#719](https://github.com/jasmine/jasmine/issues/719)
* Allow `pending` to take a reason and show it in the HtmlReporter
- Fixes [#671](https://github.com/jasmine/jasmine/issues/671)
* Set jasmineGlobal correctly in GJS
- Merges [#757](https://github.com/jasmine/jasmine/issues/757) from @ptomato
- Fixes [#751](https://github.com/jasmine/jasmine/issues/751)
* Fix some SpiderMonkey lint warnings
- Merges [#752](https://github.com/jasmine/jasmine/issues/752) from @ptomato
- Fixes [#751](https://github.com/jasmine/jasmine/issues/751)
* Prevents *Alls from running when runnables are explicitly set
- Fixes [#732](https://github.com/jasmine/jasmine/issues/732)
* Update contribution guide to mention possible ffi dependencies for Ubuntu
- Fixes [#755](https://github.com/jasmine/jasmine/issues/755)
* Fix spelling mistake in contributors guide
- Merges [#746](https://github.com/jasmine/jasmine/issues/746) from @swirlycheetah
* Use new jasmine github repo url
- Merges [#745](https://github.com/jasmine/jasmine/issues/745) rohit
* Allow `createSpyObj` to be called with just an array of method names
- Fixes [#321](https://github.com/jasmine/jasmine/issues/321)
* Add `arrayContaining` matcher
- Merges [#440](https://github.com/jasmine/jasmine/issues/440) from @slackersoft
* Use the stack trace from the Error object if supplied
- Fixes [#734](https://github.com/jasmine/jasmine/issues/734)
* Update readme with link to upgrading doc and mention browser support.
- Fixes [#739](https://github.com/jasmine/jasmine/issues/739)
* Link to the Jasmine NPM module
- Merges [#736](https://github.com/jasmine/jasmine/issues/736) from @moonmaster9000
* Allow null prototype objects to be compared for equality
- Merges [#731](https://github.com/jasmine/jasmine/issues/731) from @rohit
- Fixes [#729](https://github.com/jasmine/jasmine/issues/729)
* Fix URL's of Jasmine repositories on Github
- Merges [#730](https://github.com/jasmine/jasmine/issues/730) from @rohit
* Add `anything` matcher to match any value that is neither null or undefined
- Fixes [#186](https://github.com/jasmine/jasmine/issues/186)
* Allow asymmetric equality testers to preempt their symmetric brethren
- Fixes [#540](https://github.com/jasmine/jasmine/issues/540)
* Check for `ObjectContaining` on either side of equality
- Fixes [#682](https://github.com/jasmine/jasmine/issues/682)
* Display the name of the constructor when pretty printing objects
- Fixes [#598](https://github.com/jasmine/jasmine/issues/598)
* `toMatch` requires the `expected` to be a String or RegExp
- Fixes [#723](https://github.com/jasmine/jasmine/issues/723)
* Better equality comparison of Dom nodes
- Merges [#657](https://github.com/jasmine/jasmine/issues/657) from @alexeibs
* Hide unnecessary files from the npm package
- Fixes [#726](https://github.com/jasmine/jasmine/issues/726)
* Properly record finishing an `xdescribe` so further cleanup works
- Fixes [#724](https://github.com/jasmine/jasmine/issues/724)
* Reschedule all functions for a tick before executing any. This allows any function run during a tick to cancel any other in the same tick.
- Fixes [#708](https://github.com/jasmine/jasmine/issues/708)
* Pass through all args from external interface for befores, afters, its
- Fixes [#483](https://github.com/jasmine/jasmine/issues/483)
------
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_

View File

@@ -0,0 +1,110 @@
# Release 1.0.1.1 — November 9, 2010
## Jasmine Gem
## Bugs fixed
* Rails 3.0 and RSpec 2.0 are now supported.
## Known issues
* Rails 3 generators are not yet implemented -- coming soon!
-----
# Release 1.0.1 — October 5, 2010
-----
## Jasmine Core
## Bugs fixed
* Bug fixes for Internet Explorer (thanks fschwiet, fabiomcosta, and jfirebaugh).
## Jasmine Gem
## Bugs fixed
* Bug fix for Windows (thanks jfirebaugh).
-----
# Release 1.0 — September 14, 2010
-----
## Jasmine Core
## Features
* `waitsFor()` arguments can now be specified in any order. Timeout and message are optional.
* The default `waitsFor()` timeout period is now specified in `env.defaultTimeoutInterval`; the default value is 5 seconds.
* Added link to jasmine site from html runner.
* Added license file to standalone distribution.
* New friendly version number.
## Bugs fixed
* `waitsFor()` hanged forever if latch function never returned true.
* The `not.toThrow()` matcher threw an exception when used with no args.
* The `toThrow()` matcher, when inverted, gave misleading failure messages.
* Spy matchers, when inverted, gave misleading failure messages.
## Deprecations
* Deprecated `waits()` block in favor of `waitsFor()`; `waits()` will be removed in a future release.
* Deprecated `toNotBe()`, `toNotEqual()`, `toNotMatch()`, and `toNotContain()` matchers; they will be removed in a future release.
* Console X was removed from the distribution as it was no longer used.
* To give us some flexibility for future features, wrapped matcher functions now return `undefined` (they previously returned `true` or `false`, but this was undocumented).
## Jasmine Gem
## Features
* Jasmine now supports JRuby.
* Jasmine now supports Ruby 1.9.
## Bugs fixed
* Various generator issues fixed.
## Known issues
* Rails 3 and RSpec 2 are not yet fully supported.
-----
# Release 0.11.1 — June 25, 2010
-----
## Jasmine Core
### Features
* Jasmine no longer logs "Jasmine Running…" messages to the log by default. This can be enabled in runner.html by adding 'trivialReporter.logRunningSpecs = true;'.
* The `wasCalled()`, `wasCalledWith()`, `wasNotCalled()` and `wasNotCalledWith()` matchers have been deprecated. The new matchers `toHaveBeenCalled()` and `toHaveBeenCalledWith()` have been added. You can use the `not` prefix to achieve equivalent of the `wasNot…()` expectation (e.g. `not.toHaveBeenCalled()`).
## Notables
* A barebones version of Jasmine is now available on <a href="http://pivotal.github.com/jasmine/">http://pivotal.github.com/jasmine/</a>.
-----
# Release 0.11.0 — June 23, 2010
-----
## Jasmine Core
## Features
* The version number has been removed from the generated single-file /lib/jasmine.js. We're also now uploading this file, with the version number in the filename, to github's Downloads page.
* Old-style matchers (those using this.report(), from before 0.10.x) are no longer supported. See the <span class="caps">README</span> for instructions on writing new-style matchers.
* <strong>jasmine.log</strong> pretty-prints its parameters to the spec's output.
* Jasmine no longer depends on 'window'.
* <span class="caps">HTML</span> runner should show number of passes/fails by spec, not expectation.
* Small modification to JsApiReporter data format.
## Bugs fixed:
* If multiple beforeEach blocks were declared, they were executed in reverse order.
* Specs with duplicate names confused TrivialReporter output.
* Errors in describe functions caused later tests to be weirdly nested.
* Nested specs weren't reported properly by the JsApiReporter.
## Known issues:
* If you turn on the mock clock, you'll get a spurious log message at the end of your spec.

View File

@@ -7,7 +7,7 @@ with open('package.json') as packageFile:
setup(
name="jasmine-core",
version=version,
url="http://pivotal.github.io/jasmine/",
url="http://jasmine.github.io",
author="Pivotal Labs",
author_email="jasmine-js@googlegroups.com",
description=('Jasmine is a Behavior Driven Development testing framework for JavaScript. It does not rely on '+

View File

@@ -9,7 +9,7 @@ describe("ConsoleReporter", function() {
output += str;
},
getOutput: function() {
return output;
return output.replace('ConsoleReporter is deprecated and will be removed in a future version.', '');
},
clear: function() {
output = "";
@@ -171,27 +171,44 @@ describe("ConsoleReporter", function() {
out.clear();
reporter.jasmineDone({});
reporter.jasmineDone();
expect(out.getOutput()).toMatch(/true to be false/);
expect(out.getOutput()).toMatch(/foo bar baz/);
});
it("calls the onComplete callback when the suite is done", function() {
var onComplete = jasmine.createSpy('onComplete'),
describe('onComplete callback', function(){
var onComplete, reporter;
beforeEach(function() {
onComplete = jasmine.createSpy('onComplete');
reporter = new j$.ConsoleReporter({
print: out.print,
onComplete: onComplete
});
reporter.jasmineStarted();
});
reporter.jasmineDone({});
it("is called when the suite is done", function() {
reporter.jasmineDone();
expect(onComplete).toHaveBeenCalledWith(true);
});
expect(onComplete).toHaveBeenCalled();
it('calls it with false if there are spec failures', function() {
reporter.specDone({status: "failed", failedExpectations: []});
reporter.jasmineDone();
expect(onComplete).toHaveBeenCalledWith(false);
});
it('calls it with false if there are suite failures', function() {
reporter.specDone({status: "passed"});
reporter.suiteDone({failedExpectations: [{ message: 'bananas' }] });
reporter.jasmineDone();
expect(onComplete).toHaveBeenCalledWith(false);
});
});
describe("with color", function() {
it("reports that the suite has started to the console", function() {
var reporter = new j$.ConsoleReporter({
print: out.print,
@@ -235,5 +252,19 @@ describe("ConsoleReporter", function() {
expect(out.getOutput()).toEqual("\x1B[31mF\x1B[0m");
});
it("displays all afterAll exceptions", function() {
var reporter = new j$.ConsoleReporter({
print: out.print,
showColors: true
});
reporter.suiteDone({ failedExpectations: [{ message: 'After All Exception' }] });
reporter.suiteDone({ failedExpectations: [{ message: 'Some Other Exception' }] });
reporter.jasmineDone();
expect(out.getOutput()).toMatch(/After All Exception/);
expect(out.getOutput()).toMatch(/Some Other Exception/);
});
});
});

View File

@@ -323,6 +323,24 @@ describe("Clock (acceptance)", function() {
expect(clearedFn).not.toHaveBeenCalled();
});
it("can clear a previously set interval using that interval's handler", function() {
var spy = jasmine.createSpy('spy'),
delayedFunctionScheduler = new j$.DelayedFunctionScheduler(),
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
clock = new j$.Clock({setInterval: function() {}}, delayedFunctionScheduler, mockDate),
intervalId;
clock.install();
intervalId = clock.setInterval(function() {
spy();
clock.clearInterval(intervalId);
}, 100);
clock.tick(200);
expect(spy.calls.count()).toEqual(1);
});
it("correctly schedules functions after the Clock has advanced", function() {
var delayedFn1 = jasmine.createSpy('delayedFn1'),
delayedFunctionScheduler = new j$.DelayedFunctionScheduler(),
@@ -371,7 +389,7 @@ describe("Clock (acceptance)", function() {
clock.tick(6);
expect(delayedFn1).toHaveBeenCalled();
expect(delayedFn2).toHaveBeenCalled();
expect(delayedFn2).toHaveBeenCalled();
});
it("does not mock the Date object by default", function() {

View File

@@ -242,5 +242,55 @@ describe("DelayedFunctionScheduler", function() {
expect(innerFn).toHaveBeenCalled();
});
it("executes recurring functions after rescheduling them", function () {
var scheduler = new j$.DelayedFunctionScheduler(),
recurring = function() {
expect(scheduler.scheduleFunction).toHaveBeenCalled();
};
scheduler.scheduleFunction(recurring, 10, [], true);
spyOn(scheduler, "scheduleFunction");
scheduler.tick(10);
});
it("removes functions during a tick that runs the function", function() {
var scheduler = new j$.DelayedFunctionScheduler(),
fn = jasmine.createSpy('fn'),
fnDelay = 10,
timeoutKey;
timeoutKey = scheduler.scheduleFunction(fn, fnDelay, [], true);
scheduler.scheduleFunction(function () {
scheduler.removeFunctionWithId(timeoutKey);
}, 2 * fnDelay);
expect(fn).not.toHaveBeenCalled();
scheduler.tick(3 * fnDelay);
expect(fn).toHaveBeenCalled();
expect(fn.calls.count()).toBe(2);
});
it("removes functions during the first tick that runs the function", function() {
var scheduler = new j$.DelayedFunctionScheduler(),
fn = jasmine.createSpy('fn'),
fnDelay = 10,
timeoutKey;
timeoutKey = scheduler.scheduleFunction(fn, fnDelay, [], true);
scheduler.scheduleFunction(function () {
scheduler.removeFunctionWithId(timeoutKey);
}, fnDelay);
expect(fn).not.toHaveBeenCalled();
scheduler.tick(3 * fnDelay);
expect(fn).toHaveBeenCalled();
expect(fn.calls.count()).toBe(1);
});
});

View File

@@ -5,74 +5,18 @@ describe("Env", function() {
env = new j$.Env();
});
it('removes all spies when env is executed', function(done) {
var originalFoo = function() {},
testObj = {
foo: originalFoo
},
firstSpec = jasmine.createSpy('firstSpec').and.callFake(function() {
env.spyOn(testObj, 'foo');
}),
secondSpec = jasmine.createSpy('secondSpec').and.callFake(function() {
expect(testObj.foo).toBe(originalFoo);
});
env.describe('test suite', function() {
env.it('spec 0', firstSpec);
env.it('spec 1', secondSpec);
});
var assertions = function() {
expect(firstSpec).toHaveBeenCalled();
expect(secondSpec).toHaveBeenCalled();
done();
};
env.addReporter({ jasmineDone: assertions });
env.execute();
});
describe("#spyOn", function() {
it("checks for the existence of the object", function() {
expect(function() {
env.spyOn(void 0, 'pants');
}).toThrowError(/could not find an object/);
});
it("checks for the existence of the method", function() {
var subject = {};
expect(function() {
env.spyOn(subject, 'pants');
}).toThrowError(/method does not exist/);
});
it("checks if it has already been spied upon", function() {
var subject = { spiedFunc: function() {} };
env.spyOn(subject, 'spiedFunc');
expect(function() {
env.spyOn(subject, 'spiedFunc');
}).toThrowError(/has already been spied upon/);
});
it("overrides the method on the object and returns the spy", function() {
var originalFunctionWasCalled = false;
var subject = { spiedFunc: function() { originalFunctionWasCalled = true; } };
var spy = env.spyOn(subject, 'spiedFunc');
expect(subject.spiedFunc).toEqual(spy);
});
});
describe("#pending", function() {
it("throws the Pending Spec exception", function() {
expect(function() {
env.pending();
}).toThrow(j$.Spec.pendingSpecExceptionMessage);
});
it("throws the Pending Spec exception with a custom message", function() {
expect(function() {
env.pending('custom message');
}).toThrow(j$.Spec.pendingSpecExceptionMessage + 'custom message');
});
});
describe("#topSuite", function() {
@@ -82,4 +26,3 @@ describe("Env", function() {
});
});
});

View File

@@ -1,14 +1,14 @@
describe("Expectation", function() {
it(".addMatchers makes matchers available to any expectation", function() {
it("makes custom matchers available to this expectation", function() {
var matchers = {
toFoo: function() {},
toBar: function() {}
},
expectation;
j$.Expectation.addMatchers(matchers);
expectation = new j$.Expectation({});
expectation = new j$.Expectation({
customMatchers: matchers
});
expect(expectation.toFoo).toBeDefined();
expect(expectation.toBar).toBeDefined();
@@ -27,25 +27,6 @@ describe("Expectation", function() {
expect(expectation.toQuux).toBeDefined();
});
it(".resetMatchers should keep only core matchers", function() {
var matchers = {
toFoo: function() {}
},
coreMatchers = {
toQuux: function() {}
},
expectation;
j$.Expectation.addCoreMatchers(coreMatchers);
j$.Expectation.addMatchers(matchers);
j$.Expectation.resetMatchers();
expectation = new j$.Expectation({});
expect(expectation.toQuux).toBeDefined();
expect(expectation.toFoo).toBeUndefined();
});
it("Factory builds an expectation/negative expectation", function() {
var builtExpectation = j$.Expectation.Factory();
@@ -65,10 +46,9 @@ describe("Expectation", function() {
addExpectationResult = jasmine.createSpy("addExpectationResult"),
expectation;
j$.Expectation.addMatchers(matchers);
expectation = new j$.Expectation({
util: util,
customMatchers: matchers,
customEqualityTesters: customEqualityTesters,
actual: "an actual",
addExpectationResult: addExpectationResult
@@ -94,10 +74,9 @@ describe("Expectation", function() {
addExpectationResult = jasmine.createSpy("addExpectationResult"),
expectation;
j$.Expectation.addMatchers(matchers);
expectation = new j$.Expectation({
util: util,
customMatchers: matchers,
actual: "an actual",
addExpectationResult: addExpectationResult
});
@@ -121,10 +100,8 @@ describe("Expectation", function() {
addExpectationResult = jasmine.createSpy("addExpectationResult"),
expectation;
j$.Expectation.addMatchers(matchers);
expectation = new j$.Expectation({
matchers: matchers,
customMatchers: matchers,
util: util,
actual: "an actual",
addExpectationResult: addExpectationResult
@@ -155,10 +132,8 @@ describe("Expectation", function() {
addExpectationResult = jasmine.createSpy("addExpectationResult"),
expectation;
j$.Expectation.addMatchers(matchers);
expectation = new j$.Expectation({
matchers: matchers,
customMatchers: matchers,
util: util,
actual: "an actual",
addExpectationResult: addExpectationResult
@@ -191,10 +166,9 @@ describe("Expectation", function() {
addExpectationResult = jasmine.createSpy("addExpectationResult"),
expectation;
j$.Expectation.addMatchers(matchers);
expectation = new j$.Expectation({
actual: "an actual",
customMatchers: matchers,
addExpectationResult: addExpectationResult
});
@@ -225,10 +199,8 @@ describe("Expectation", function() {
addExpectationResult = jasmine.createSpy("addExpectationResult"),
expectation;
j$.Expectation.addMatchers(matchers);
expectation = new j$.Expectation({
matchers: matchers,
customMatchers: matchers,
actual: "an actual",
addExpectationResult: addExpectationResult
});
@@ -259,10 +231,8 @@ describe("Expectation", function() {
actual = "an actual",
expectation;
j$.Expectation.addMatchers(matchers);
expectation = new j$.Expectation({
matchers: matchers,
customMatchers: matchers,
actual: "an actual",
addExpectationResult: addExpectationResult,
isNot: true
@@ -294,10 +264,8 @@ describe("Expectation", function() {
actual = "an actual",
expectation;
j$.Expectation.addMatchers(matchers);
expectation = new j$.Expectation({
matchers: matchers,
customMatchers: matchers,
actual: "an actual",
util: util,
addExpectationResult: addExpectationResult,
@@ -332,10 +300,8 @@ describe("Expectation", function() {
actual = "an actual",
expectation;
j$.Expectation.addMatchers(matchers);
expectation = new j$.Expectation({
matchers: matchers,
customMatchers: matchers,
actual: "an actual",
addExpectationResult: addExpectationResult,
isNot: true
@@ -365,10 +331,8 @@ describe("Expectation", function() {
actual = "an actual",
expectation;
j$.Expectation.addMatchers(matchers);
expectation = new j$.Expectation({
matchers: matchers,
customMatchers: matchers,
actual: "an actual",
addExpectationResult: addExpectationResult,
isNot: true
@@ -403,10 +367,8 @@ describe("Expectation", function() {
actual = "an actual",
expectation;
j$.Expectation.addMatchers(matchers);
expectation = new j$.Expectation({
matchers: matchers,
customMatchers: matchers,
actual: "an actual",
addExpectationResult: addExpectationResult,
isNot: true

View File

@@ -178,6 +178,43 @@ describe("JsApiReporter", function() {
});
});
describe("#suiteResults", function(){
var reporter, suiteResult1, suiteResult2;
beforeEach(function() {
reporter = new j$.JsApiReporter({});
suiteStarted1 = {
id: 1
};
suiteResult1 = {
id: 1,
status: 'failed',
failedExpectations: [{ message: 'My After All Exception' }]
};
suiteResult2 = {
id: 2,
status: 'finished'
};
reporter.suiteStarted(suiteStarted1);
reporter.suiteDone(suiteResult1);
reporter.suiteDone(suiteResult2);
});
it('should not include suite starts', function(){
expect(reporter.suiteResults(0,3).length).toEqual(2);
});
it("should return a slice of results", function() {
expect(reporter.suiteResults(0, 1)).toEqual([suiteResult1]);
expect(reporter.suiteResults(1, 1)).toEqual([suiteResult2]);
});
it("returns nothing for out of bounds indicies", function() {
expect(reporter.suiteResults(0, 3)).toEqual([suiteResult1, suiteResult2]);
expect(reporter.suiteResults(2, 3)).toEqual([]);
});
});
describe("#executionTime", function() {
it("should start the timer when jasmine starts", function() {
var timerSpy = jasmine.createSpyObj('timer', ['start', 'elapsed']),

View File

@@ -75,6 +75,7 @@ describe("FakeDate", function() {
mockDate.install();
expect(new fakeGlobal.Date()).toEqual(jasmine.any(Date));
expect(new fakeGlobal.Date() instanceof fakeGlobal.Date).toBe(true);
});
it("fakes current time when using Date.now()", function() {

View File

@@ -1,70 +0,0 @@
describe("ObjectContaining", function() {
it("matches any actual to an empty object", function() {
var containing = new j$.ObjectContaining({});
expect(containing.jasmineMatches("foo")).toBe(true);
});
it("does not match an empty object actual", function() {
var containing = new j$.ObjectContaining("foo");
expect(function() {
containing.jasmineMatches({})
}).toThrowError(/not 'foo'/)
});
it("matches when the key/value pair is present in the actual", function() {
var containing = new j$.ObjectContaining({foo: "fooVal"});
expect(containing.jasmineMatches({foo: "fooVal", bar: "barVal"})).toBe(true);
});
it("does not match when the key/value pair is not present in the actual", function() {
var containing = new j$.ObjectContaining({foo: "fooVal"});
expect(containing.jasmineMatches({bar: "barVal", quux: "quuxVal"})).toBe(false);
});
it("does not match when the key is present but the value is different in the actual", function() {
var containing = new j$.ObjectContaining({foo: "other"});
expect(containing.jasmineMatches({foo: "fooVal", bar: "barVal"})).toBe(false);
});
it("mismatchValues parameter must return array with mismatched reason", function() {
var containing = new j$.ObjectContaining({foo: "other"});
var mismatchKeys = [];
var mismatchValues = [];
containing.jasmineMatches({foo: "fooVal", bar: "barVal"}, mismatchKeys, mismatchValues);
expect(mismatchValues.length).toBe(1);
expect(mismatchValues[0]).toEqual("'foo' was 'fooVal' in actual, but was 'other' in expected.");
});
it("adds keys in expected but not actual to the mismatchKeys parameter", function() {
var containing = new j$.ObjectContaining({foo: "fooVal"});
var mismatchKeys = [];
var mismatchValues = [];
containing.jasmineMatches({bar: "barVal"}, mismatchKeys, mismatchValues);
expect(mismatchKeys.length).toBe(1);
expect(mismatchKeys[0]).toEqual("expected has key 'foo', but missing from actual.");
});
it("jasmineToString's itself", function() {
var containing = new j$.ObjectContaining({});
expect(containing.jasmineToString()).toMatch("<jasmine.objectContaining");
});
it("matches recursively", function() {
var containing = new j$.ObjectContaining({one: new j$.ObjectContaining({two: {}})});
expect(containing.jasmineMatches({one: {two: {}}})).toBe(true);
});
});

View File

@@ -16,7 +16,7 @@ describe("j$.pp", function () {
it("should stringify arrays properly", function() {
expect(j$.pp([1, 2])).toEqual("[ 1, 2 ]");
expect(j$.pp([1, 'foo', {}, jasmine.undefined, null])).toEqual("[ 1, 'foo', { }, undefined, null ]");
expect(j$.pp([1, 'foo', {}, jasmine.undefined, null])).toEqual("[ 1, 'foo', Object({ }), undefined, null ]");
});
it("should indicate circular array references", function() {
@@ -26,19 +26,24 @@ describe("j$.pp", function () {
expect(j$.pp(array1)).toEqual("[ 1, 2, [ <circular reference: Array> ] ]");
});
it("should not indicate circular references incorrectly", function() {
var array = [ [1] ];
expect(j$.pp(array)).toEqual("[ [ 1 ] ]");
});
it("should stringify objects properly", function() {
expect(j$.pp({foo: 'bar'})).toEqual("{ foo: 'bar' }");
expect(j$.pp({foo:'bar', baz:3, nullValue: null, undefinedValue: jasmine.undefined})).toEqual("{ foo: 'bar', baz: 3, nullValue: null, undefinedValue: undefined }");
expect(j$.pp({foo: 'bar'})).toEqual("Object({ foo: 'bar' })");
expect(j$.pp({foo:'bar', baz:3, nullValue: null, undefinedValue: jasmine.undefined})).toEqual("Object({ foo: 'bar', baz: 3, nullValue: null, undefinedValue: undefined })");
expect(j$.pp({foo: function () {
}, bar: [1, 2, 3]})).toEqual("{ foo: Function, bar: [ 1, 2, 3 ] }");
}, bar: [1, 2, 3]})).toEqual("Object({ foo: Function, bar: [ 1, 2, 3 ] })");
});
it("should not include inherited properties when stringifying an object", function() {
var SomeClass = function() {};
var SomeClass = function SomeClass() {};
SomeClass.prototype.foo = "inherited foo";
var instance = new SomeClass();
instance.bar = "my own bar";
expect(j$.pp(instance)).toEqual("{ bar: 'my own bar' }");
expect(j$.pp(instance)).toEqual("SomeClass({ bar: 'my own bar' })");
});
it("should not recurse objects and arrays more deeply than j$.MAX_PRETTY_PRINT_DEPTH", function() {
@@ -48,15 +53,15 @@ describe("j$.pp", function () {
try {
j$.MAX_PRETTY_PRINT_DEPTH = 2;
expect(j$.pp(nestedObject)).toEqual("{ level1: { level2: Object } }");
expect(j$.pp(nestedObject)).toEqual("Object({ level1: Object({ level2: Object }) })");
expect(j$.pp(nestedArray)).toEqual("[ 1, [ 2, Array ] ]");
j$.MAX_PRETTY_PRINT_DEPTH = 3;
expect(j$.pp(nestedObject)).toEqual("{ level1: { level2: { level3: Object } } }");
expect(j$.pp(nestedObject)).toEqual("Object({ level1: Object({ level2: Object({ level3: Object }) }) })");
expect(j$.pp(nestedArray)).toEqual("[ 1, [ 2, [ 3, Array ] ] ]");
j$.MAX_PRETTY_PRINT_DEPTH = 4;
expect(j$.pp(nestedObject)).toEqual("{ level1: { level2: { level3: { level4: 'leaf' } } } }");
expect(j$.pp(nestedObject)).toEqual("Object({ level1: Object({ level2: Object({ level3: Object({ level4: 'leaf' }) }) }) })");
expect(j$.pp(nestedArray)).toEqual("[ 1, [ 2, [ 3, [ 4, 'leaf' ] ] ] ]");
} finally {
j$.MAX_PRETTY_PRINT_DEPTH = originalMaxDepth;
@@ -68,7 +73,7 @@ describe("j$.pp", function () {
var frozenObject = {foo: {bar: 'baz'}};
frozenObject.circular = frozenObject;
frozenObject = Object.freeze(frozenObject);
expect(j$.pp(frozenObject)).toEqual("{ foo: { bar: 'baz' }, circular: <circular reference: Object> }");
expect(j$.pp(frozenObject)).toEqual("Object({ foo: Object({ bar: 'baz' }), circular: <circular reference: Object> })");
}
});
@@ -91,7 +96,7 @@ describe("j$.pp", function () {
it("should indicate circular object references", function() {
var sampleValue = {foo: 'hello'};
sampleValue.nested = sampleValue;
expect(j$.pp(sampleValue)).toEqual("{ foo: 'hello', nested: <circular reference: Object> }");
expect(j$.pp(sampleValue)).toEqual("Object({ foo: 'hello', nested: <circular reference: Object> })");
});
it("should indicate getters on objects as such", function() {
@@ -103,10 +108,10 @@ describe("j$.pp", function () {
});
}
if (sampleValue.__defineGetter__) {
expect(j$.pp(sampleValue)).toEqual("{ id: 1, calculatedValue: <getter> }");
expect(j$.pp(sampleValue)).toEqual("Object({ id: 1, calculatedValue: <getter> })");
}
else {
expect(j$.pp(sampleValue)).toEqual("{ id: 1 }");
expect(j$.pp(sampleValue)).toEqual("Object({ id: 1 })");
}
});
@@ -130,7 +135,9 @@ describe("j$.pp", function () {
},
env = new j$.Env();
env.spyOn(TestObject, 'someFunction');
var spyRegistry = new j$.SpyRegistry({currentSpies: function() {return [];}});
spyRegistry.spyOn(TestObject, 'someFunction');
expect(j$.pp(TestObject.someFunction)).toEqual("spy on someFunction");
expect(j$.pp(j$.createSpy("something"))).toEqual("spy on something");
@@ -150,7 +157,6 @@ describe("j$.pp", function () {
var obj = Object.create(null);
obj.foo = 'bar';
expect(j$.pp(obj)).toEqual("{ foo: 'bar' }");
expect(j$.pp(obj)).toEqual("null({ foo: 'bar' })");
});
});

View File

@@ -2,15 +2,15 @@ describe("QueueRunner", function() {
it("runs all the functions it's passed", function() {
var calls = [],
fn1 = jasmine.createSpy('fn1'),
fn2 = jasmine.createSpy('fn2'),
queueableFn1 = { fn: jasmine.createSpy('fn1') },
queueableFn2 = { fn: jasmine.createSpy('fn2') },
queueRunner = new j$.QueueRunner({
fns: [fn1, fn2]
queueableFns: [queueableFn1, queueableFn2]
});
fn1.and.callFake(function() {
queueableFn1.fn.and.callFake(function() {
calls.push('fn1');
});
fn2.and.callFake(function() {
queueableFn2.fn.and.callFake(function() {
calls.push('fn2');
});
@@ -20,19 +20,19 @@ describe("QueueRunner", function() {
});
it("calls each function with a consistent 'this'-- an empty object", function() {
var fn1 = jasmine.createSpy('fn1'),
fn2 = jasmine.createSpy('fn2'),
fn3 = function(done) { asyncContext = this; done(); },
var queueableFn1 = { fn: jasmine.createSpy('fn1') },
queueableFn2 = { fn: jasmine.createSpy('fn2') },
queueableFn3 = { fn: function(done) { asyncContext = this; done(); } },
queueRunner = new j$.QueueRunner({
fns: [fn1, fn2, fn3]
queueableFns: [queueableFn1, queueableFn2, queueableFn3]
}),
asyncContext;
queueRunner.execute();
var context = fn1.calls.first().object;
var context = queueableFn1.fn.calls.first().object;
expect(context).toEqual({});
expect(fn2.calls.first().object).toBe(context);
expect(queueableFn2.fn.calls.first().object).toBe(context);
expect(asyncContext).toBe(context);
});
@@ -53,20 +53,20 @@ describe("QueueRunner", function() {
beforeCallback = jasmine.createSpy('beforeCallback'),
fnCallback = jasmine.createSpy('fnCallback'),
afterCallback = jasmine.createSpy('afterCallback'),
fn1 = function(done) {
queueableFn1 = { fn: function(done) {
beforeCallback();
setTimeout(done, 100);
},
fn2 = function(done) {
} },
queueableFn2 = { fn: function(done) {
fnCallback();
setTimeout(done, 100);
},
fn3 = function(done) {
} },
queueableFn3 = { fn: function(done) {
afterCallback();
setTimeout(done, 100);
},
} },
queueRunner = new j$.QueueRunner({
fns: [fn1, fn2, fn3],
queueableFns: [queueableFn1, queueableFn2, queueableFn3],
onComplete: onComplete
});
@@ -93,55 +93,77 @@ describe("QueueRunner", function() {
expect(onComplete).toHaveBeenCalled();
});
it("sets a timeout if requested for asynchronous functions so they don't go on forever", function() {
var beforeFn = function(done) { },
fn = jasmine.createSpy('fn'),
onComplete = jasmine.createSpy('onComplete'),
onException = jasmine.createSpy('onException'),
it("explicitly fails an async function with a provided fail function and moves to the next function", function() {
var queueableFn1 = { fn: function(done) {
setTimeout(function() { done.fail('foo'); }, 100);
} },
queueableFn2 = { fn: jasmine.createSpy('fn2') },
failFn = jasmine.createSpy('fail'),
queueRunner = new j$.QueueRunner({
fns: [beforeFn, fn],
onComplete: onComplete,
onException: onException,
enforceTimeout: function() { return true; }
queueableFns: [queueableFn1, queueableFn2],
fail: failFn
});
queueRunner.execute();
expect(fn).not.toHaveBeenCalled();
jasmine.clock().tick(j$.DEFAULT_TIMEOUT_INTERVAL);
expect(failFn).not.toHaveBeenCalled();
expect(queueableFn2.fn).not.toHaveBeenCalled();
jasmine.clock().tick(100);
expect(failFn).toHaveBeenCalledWith('foo');
expect(queueableFn2.fn).toHaveBeenCalled();
});
it("sets a timeout if requested for asynchronous functions so they don't go on forever", function() {
var timeout = 3,
beforeFn = { fn: function(done) { }, type: 'before', timeout: function() { return timeout; } },
queueableFn = { fn: jasmine.createSpy('fn'), type: 'queueable' },
onComplete = jasmine.createSpy('onComplete'),
onException = jasmine.createSpy('onException'),
queueRunner = new j$.QueueRunner({
queueableFns: [beforeFn, queueableFn],
onComplete: onComplete,
onException: onException
});
queueRunner.execute();
expect(queueableFn.fn).not.toHaveBeenCalled();
jasmine.clock().tick(timeout);
expect(onException).toHaveBeenCalledWith(jasmine.any(Error));
expect(fn).toHaveBeenCalled();
expect(queueableFn.fn).toHaveBeenCalled();
expect(onComplete).toHaveBeenCalled();
});
it("by default does not set a timeout for asynchronous functions", function() {
var beforeFn = function(done) { },
fn = jasmine.createSpy('fn'),
var beforeFn = { fn: function(done) { } },
queueableFn = { fn: jasmine.createSpy('fn') },
onComplete = jasmine.createSpy('onComplete'),
onException = jasmine.createSpy('onException'),
queueRunner = new j$.QueueRunner({
fns: [beforeFn, fn],
queueableFns: [beforeFn, queueableFn],
onComplete: onComplete,
onException: onException,
});
queueRunner.execute();
expect(fn).not.toHaveBeenCalled();
expect(queueableFn.fn).not.toHaveBeenCalled();
jasmine.clock().tick(j$.DEFAULT_TIMEOUT_INTERVAL);
expect(onException).not.toHaveBeenCalled();
expect(fn).not.toHaveBeenCalled();
expect(queueableFn.fn).not.toHaveBeenCalled();
expect(onComplete).not.toHaveBeenCalled();
});
it("clears the timeout when an async function throws an exception, to prevent additional onException calls", function() {
var fn = function(done) { throw new Error("error!"); },
it("clears the timeout when an async function throws an exception, to prevent additional exception reporting", function() {
var queueableFn = { fn: function(done) { throw new Error("error!"); } },
onComplete = jasmine.createSpy('onComplete'),
onException = jasmine.createSpy('onException'),
queueRunner = new j$.QueueRunner({
fns: [fn],
queueableFns: [queueableFn],
onComplete: onComplete,
onException: onException
});
@@ -156,11 +178,11 @@ describe("QueueRunner", function() {
});
it("clears the timeout when the done callback is called", function() {
var fn = function(done) { done(); },
var queueableFn = { fn: function(done) { done(); } },
onComplete = jasmine.createSpy('onComplete'),
onException = jasmine.createSpy('onException'),
queueRunner = new j$.QueueRunner({
fns: [fn],
queueableFns: [queueableFn],
onComplete: onComplete,
onException: onException
});
@@ -174,75 +196,78 @@ describe("QueueRunner", function() {
});
it("only moves to the next spec the first time you call done", function() {
var fn = function(done) {done(); done();},
nextFn = jasmine.createSpy('nextFn');
var queueableFn = { fn: function(done) {done(); done();} },
nextQueueableFn = { fn: jasmine.createSpy('nextFn') };
queueRunner = new j$.QueueRunner({
fns: [fn, nextFn]
queueableFns: [queueableFn, nextQueueableFn]
});
queueRunner.execute();
expect(nextFn.calls.count()).toEqual(1);
expect(nextQueueableFn.fn.calls.count()).toEqual(1);
});
it("does not move to the next spec if done is called after an exception has ended the spec", function() {
var fn = function(done) {
var queueableFn = { fn: function(done) {
setTimeout(done, 1);
throw new Error('error!');
},
nextFn = jasmine.createSpy('nextFn');
} },
nextQueueableFn = { fn: jasmine.createSpy('nextFn') };
queueRunner = new j$.QueueRunner({
fns: [fn, nextFn]
queueableFns: [queueableFn, nextQueueableFn]
});
queueRunner.execute();
jasmine.clock().tick(1);
expect(nextFn.calls.count()).toEqual(1);
expect(nextQueueableFn.fn.calls.count()).toEqual(1);
});
});
it("calls an exception handler when an exception is thrown in a fn", function() {
var fn = function() {
it("calls exception handlers when an exception is thrown in a fn", function() {
var queueableFn = { type: 'queueable',
fn: function() {
throw new Error('fake error');
},
exceptionCallback = jasmine.createSpy('exception callback'),
} },
onExceptionCallback = jasmine.createSpy('on exception callback'),
queueRunner = new j$.QueueRunner({
fns: [fn],
onException: exceptionCallback
queueableFns: [queueableFn],
onException: onExceptionCallback
});
queueRunner.execute();
expect(exceptionCallback).toHaveBeenCalledWith(jasmine.any(Error));
expect(onExceptionCallback).toHaveBeenCalledWith(jasmine.any(Error));
});
it("rethrows an exception if told to", function() {
var fn = function() {
var queueableFn = { fn: function() {
throw new Error('fake error');
},
} },
queueRunner = new j$.QueueRunner({
fns: [fn],
queueableFns: [queueableFn],
catchException: function(e) { return false; }
});
expect(queueRunner.execute).toThrow();
expect(function() {
queueRunner.execute();
}).toThrowError('fake error');
});
it("continues running the functions even after an exception is thrown in an async spec", function() {
var fn = function(done) { throw new Error("error"); },
nextFn = jasmine.createSpy("nextFunction"),
var queueableFn = { fn: function(done) { throw new Error("error"); } },
nextQueueableFn = { fn: jasmine.createSpy("nextFunction") },
queueRunner = new j$.QueueRunner({
fns: [fn, nextFn]
queueableFns: [queueableFn, nextQueueableFn]
});
queueRunner.execute();
expect(nextFn).toHaveBeenCalled();
expect(nextQueueableFn.fn).toHaveBeenCalled();
});
it("calls a provided complete callback when done", function() {
var fn = jasmine.createSpy('fn'),
var queueableFn = { fn: jasmine.createSpy('fn') },
completeCallback = jasmine.createSpy('completeCallback'),
queueRunner = new j$.QueueRunner({
fns: [fn],
queueableFns: [queueableFn],
onComplete: completeCallback
});
@@ -252,12 +277,12 @@ describe("QueueRunner", function() {
});
it("calls a provided stack clearing function when done", function() {
var asyncFn = function(done) { done() },
afterFn = jasmine.createSpy('afterFn'),
var asyncFn = { fn: function(done) { done() } },
afterFn = { fn: jasmine.createSpy('afterFn') },
completeCallback = jasmine.createSpy('completeCallback'),
clearStack = jasmine.createSpy('clearStack'),
queueRunner = new j$.QueueRunner({
fns: [asyncFn, afterFn],
queueableFns: [asyncFn, afterFn],
clearStack: clearStack,
onComplete: completeCallback
});
@@ -265,7 +290,7 @@ describe("QueueRunner", function() {
clearStack.and.callFake(function(fn) { fn(); });
queueRunner.execute();
expect(afterFn).toHaveBeenCalled();
expect(afterFn.fn).toHaveBeenCalled();
expect(clearStack).toHaveBeenCalledWith(completeCallback);
});
});

View File

@@ -14,7 +14,11 @@ describe("Spec", function() {
expect(j$.Spec.isPendingSpecException(fakeError)).toBe(true);
});
it("#isPendingSpecException returns true for a pending spec exception", function() {
it("#isPendingSpecException returns true for a pending spec exception with a custom message", function() {
expect(j$.Spec.isPendingSpecException(j$.Spec.pendingSpecExceptionMessage + 'foo')).toBe(true);
});
it("#isPendingSpecException returns false for not a pending spec exception", function() {
var e = new Error("foo");
expect(j$.Spec.isPendingSpecException(e)).toBe(false);
@@ -29,7 +33,7 @@ describe("Spec", function() {
spec = new j$.Spec({
description: 'my test',
id: 'some-id',
fn: function() {},
queueableFn: { fn: function() {} },
queueRunnerFactory: fakeQueueRunner
});
@@ -44,7 +48,7 @@ describe("Spec", function() {
spec = new j$.Spec({
id: 123,
description: 'foo bar',
fn: function() {},
queueableFn: { fn: function() {} },
onStart: startCallback,
queueRunnerFactory: fakeQueueRunner
});
@@ -66,7 +70,7 @@ describe("Spec", function() {
expect(beforesWereCalled).toBe(false);
}),
spec = new j$.Spec({
fn: function() {},
queueableFn: { fn: function() {} },
beforeFns: function() {
return [function() {
beforesWereCalled = true
@@ -85,25 +89,22 @@ describe("Spec", function() {
var fakeQueueRunner = jasmine.createSpy('fakeQueueRunner'),
before = jasmine.createSpy('before'),
after = jasmine.createSpy('after'),
fn = jasmine.createSpy('test body').and.callFake(function() {
queueableFn = { fn: jasmine.createSpy('test body').and.callFake(function() {
expect(before).toHaveBeenCalled();
expect(after).not.toHaveBeenCalled();
}),
}) },
spec = new j$.Spec({
fn: fn,
beforeFns: function() {
return [before]
},
afterFns: function() {
return [after]
queueableFn: queueableFn,
beforeAndAfterFns: function() {
return {befores: [before], afters: [after]}
},
queueRunnerFactory: fakeQueueRunner
});
spec.execute();
var allSpecFns = fakeQueueRunner.calls.mostRecent().args[0].fns;
expect(allSpecFns).toEqual([before, fn, after]);
var allSpecFns = fakeQueueRunner.calls.mostRecent().args[0].queueableFns;
expect(allSpecFns).toEqual([before, queueableFn, after]);
});
it("is marked pending if created without a function body", function() {
@@ -113,7 +114,7 @@ describe("Spec", function() {
resultCallback = jasmine.createSpy('resultCallback'),
spec = new j$.Spec({
onStart: startCallback,
fn: null,
queueableFn: { fn: null },
resultCallback: resultCallback,
queueRunnerFactory: fakeQueueRunner
});
@@ -129,7 +130,7 @@ describe("Spec", function() {
resultCallback = jasmine.createSpy('resultCallback'),
spec = new j$.Spec({
onStart:startCallback,
fn: specBody,
queueableFn: { fn: specBody },
resultCallback: resultCallback,
queueRunnerFactory: fakeQueueRunner
});
@@ -158,7 +159,8 @@ describe("Spec", function() {
getSpecName: function() {
return "a suite with a spec"
},
queueRunnerFactory: fakeQueueRunner
queueRunnerFactory: fakeQueueRunner,
queueableFn: { fn: null }
});
spec.pend();
@@ -176,14 +178,15 @@ describe("Spec", function() {
description: 'with a spec',
fullName: 'a suite with a spec',
failedExpectations: [],
passedExpectations: []
passedExpectations: [],
pendingReason: ''
});
});
it("should call the done callback on execution complete", function() {
var done = jasmine.createSpy('done callback'),
spec = new j$.Spec({
fn: function() {},
queueableFn: { fn: function() {} },
catchExceptions: function() { return false; },
resultCallback: function() {},
queueRunnerFactory: function(attrs) { attrs.onComplete(); }
@@ -194,19 +197,19 @@ describe("Spec", function() {
expect(done).toHaveBeenCalled();
});
it("#status returns passing by default", function(){
var spec = new j$.Spec({ fn: function () {} });
expect(spec.status()).toBe("passed");
it("#status returns passing by default", function() {
var spec = new j$.Spec({queueableFn: { fn: jasmine.createSpy("spec body")} });
expect(spec.status()).toBe('passed');
});
it("#status returns passed if all expectations in the spec have passed", function() {
var spec = new j$.Spec({fn: jasmine.createSpy("spec body")});
var spec = new j$.Spec({queueableFn: { fn: jasmine.createSpy("spec body")} });
spec.addExpectationResult(true);
expect(spec.status()).toBe('passed');
});
it("#status returns failed if any expectations in the spec have failed", function() {
var spec = new j$.Spec({ fn: jasmine.createSpy("spec body") });
var spec = new j$.Spec({queueableFn: { fn: jasmine.createSpy("spec body") } });
spec.addExpectationResult(true);
spec.addExpectationResult(false);
expect(spec.status()).toBe('failed');
@@ -215,7 +218,7 @@ describe("Spec", function() {
it("keeps track of passed and failed expectations", function() {
var resultCallback = jasmine.createSpy('resultCallback'),
spec = new j$.Spec({
fn: jasmine.createSpy("spec body"),
queueableFn: { fn: jasmine.createSpy("spec body") },
expectationResultFactory: function (data) { return data; },
queueRunnerFactory: function(attrs) { attrs.onComplete(); },
resultCallback: resultCallback
@@ -233,7 +236,8 @@ describe("Spec", function() {
var specNameSpy = jasmine.createSpy('specNameSpy').and.returnValue('expected val');
var spec = new j$.Spec({
getSpecName: specNameSpy
getSpecName: specNameSpy,
queueableFn: { fn: null }
});
expect(spec.getFullName()).toBe('expected val');
@@ -248,13 +252,31 @@ describe("Spec", function() {
spec = new j$.Spec({
description: 'my test',
id: 'some-id',
fn: function() { },
queueableFn: { fn: function() { } },
queueRunnerFactory: fakeQueueRunner
});
spec.execute();
expect(spec.status()).toEqual("pending");
expect(spec.result.pendingReason).toEqual('');
});
it("should set the pendingReason", function() {
var fakeQueueRunner = function(opts) {
opts.onException(new Error(j$.Spec.pendingSpecExceptionMessage + 'custom message'));
},
spec = new j$.Spec({
description: 'my test',
id: 'some-id',
queueableFn: { fn: function() { } },
queueRunnerFactory: fakeQueueRunner
});
spec.execute();
expect(spec.status()).toEqual("pending");
expect(spec.result.pendingReason).toEqual('custom message');
});
});
});

View File

@@ -0,0 +1,64 @@
describe("SpyRegistry", function() {
describe("#spyOn", function() {
it("checks for the existence of the object", function() {
var spyRegistry = new j$.SpyRegistry();
expect(function() {
spyRegistry.spyOn(void 0, 'pants');
}).toThrowError(/could not find an object/);
});
it("checks that a method name was passed", function() {
var spyRegistry = new j$.SpyRegistry(),
subject = {};
expect(function() {
spyRegistry.spyOn(subject);
}).toThrowError(/No method name supplied/);
});
it("checks for the existence of the method", function() {
var spyRegistry = new j$.SpyRegistry(),
subject = {};
expect(function() {
spyRegistry.spyOn(subject, 'pants');
}).toThrowError(/method does not exist/);
});
it("checks if it has already been spied upon", function() {
var spies = [],
spyRegistry = new j$.SpyRegistry({currentSpies: function() { return spies; }}),
subject = { spiedFunc: function() {} };
spyRegistry.spyOn(subject, 'spiedFunc');
expect(function() {
spyRegistry.spyOn(subject, 'spiedFunc');
}).toThrowError(/has already been spied upon/);
});
it("overrides the method on the object and returns the spy", function() {
var originalFunctionWasCalled = false,
spyRegistry = new j$.SpyRegistry(),
subject = { spiedFunc: function() { originalFunctionWasCalled = true; } };
var spy = spyRegistry.spyOn(subject, 'spiedFunc');
expect(subject.spiedFunc).toEqual(spy);
});
});
describe("#clearSpies", function() {
it("restores the original functions on the spied-upon objects", function() {
var spies = [],
spyRegistry = new j$.SpyRegistry({currentSpies: function() { return spies; }}),
originalFunction = function() {},
subject = { spiedFunc: originalFunction };
spyRegistry.spyOn(subject, 'spiedFunc');
spyRegistry.clearSpies();
expect(subject.spiedFunc).toBe(originalFunction);
});
});
});

View File

@@ -7,7 +7,7 @@ describe('Spies', function () {
TestClass.prototype.someFunction = function() {};
TestClass.prototype.someFunction.bob = "test";
});
it("preserves the properties of the spied function", function() {
var spy = j$.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
@@ -47,6 +47,16 @@ describe('Spies', function () {
expect(trackSpy.calls.mostRecent().args[0].object).toEqual(contextObject);
});
it("tracks the return value of calls", function () {
var spy = j$.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
var trackSpy = spyOn(spy.calls, "track");
spy.and.returnValue("return value");
spy();
expect(trackSpy.calls.mostRecent().args[0].returnValue).toEqual("return value");
});
});
describe("createSpyObj", function() {
@@ -58,6 +68,14 @@ describe('Spies', function () {
expect(spyObj.method2.and.identity()).toEqual('BaseName.method2');
});
it("should allow you to omit the baseName", function() {
var spyObj = j$.createSpyObj(['method1', 'method2']);
expect(spyObj).toEqual({ method1: jasmine.any(Function), method2: jasmine.any(Function)});
expect(spyObj.method1.and.identity()).toEqual('unknown.method1');
expect(spyObj.method2.and.identity()).toEqual('unknown.method2');
});
it("should throw if you do not pass an array argument", function() {
expect(function() {
j$.createSpyObj('BaseName');

View File

@@ -46,6 +46,19 @@ describe("SpyStrategy", function() {
expect(returnValue).toEqual(17);
});
it("can return specified values in order specified when executed", function() {
var originalFn = jasmine.createSpy("original"),
spyStrategy = new j$.SpyStrategy({fn: originalFn});
spyStrategy.returnValues('value1', 'value2', 'value3');
expect(spyStrategy.exec()).toEqual('value1');
expect(spyStrategy.exec()).toEqual('value2');
expect(spyStrategy.exec()).toBe('value3');
expect(spyStrategy.exec()).toBeUndefined();
expect(originalFn).not.toHaveBeenCalled();
});
it("allows an exception to be thrown when executed", function() {
var originalFn = jasmine.createSpy("original"),
spyStrategy = new j$.SpyStrategy({fn: originalFn});

View File

@@ -52,6 +52,31 @@ describe("Suite", function() {
expect(suite.beforeFns).toEqual([innerBefore, outerBefore]);
});
it("runs beforeAll functions in order of needed execution", function() {
var env = new j$.Env(),
fakeQueueRunner = jasmine.createSpy('fake queue runner'),
suite = new j$.Suite({
env: env,
description: "I am a suite",
queueRunner: fakeQueueRunner
}),
firstBefore = jasmine.createSpy('outerBeforeAll'),
lastBefore = jasmine.createSpy('insideBeforeAll'),
fakeIt = {execute: jasmine.createSpy('it'), isExecutable: function() { return true; } };
suite.beforeAll(firstBefore);
suite.beforeAll(lastBefore);
suite.addChild(fakeIt);
suite.execute();
var suiteFns = fakeQueueRunner.calls.mostRecent().args[0].queueableFns;
suiteFns[0]();
expect(firstBefore).toHaveBeenCalled();
suiteFns[1]();
expect(lastBefore).toHaveBeenCalled();
});
it("adds after functions in order of needed execution", function() {
var env = new j$.Env(),
suite = new j$.Suite({
@@ -67,6 +92,57 @@ describe("Suite", function() {
expect(suite.afterFns).toEqual([innerAfter, outerAfter]);
});
it("runs afterAll functions in order of needed execution", function() {
var env = new j$.Env(),
fakeQueueRunner = jasmine.createSpy('fake queue runner'),
suite = new j$.Suite({
env: env,
description: "I am a suite",
queueRunner: fakeQueueRunner
}),
firstAfter = jasmine.createSpy('outerAfterAll'),
lastAfter = jasmine.createSpy('insideAfterAll'),
fakeIt = {execute: jasmine.createSpy('it'), isExecutable: function() { return true; } };
suite.afterAll(firstAfter);
suite.afterAll(lastAfter);
suite.addChild(fakeIt);
suite.execute();
var suiteFns = fakeQueueRunner.calls.mostRecent().args[0].queueableFns;
suiteFns[1]();
expect(firstAfter).toHaveBeenCalled();
suiteFns[2]();
expect(lastAfter).toHaveBeenCalled();
});
it("does not run *All functions if runnables are explicitly set", function(){
var env = new j$.Env(),
fakeQueueRunner = jasmine.createSpy('fake queue runner'),
suite = new j$.Suite({
env: env,
description: "I am a suite",
queueRunner: fakeQueueRunner,
runnablesExplictlySetGetter: function(){return true;}
}),
beforeAll = jasmine.createSpy('beforeAll'),
afterAll = jasmine.createSpy('afterAll'),
fakeIt = {execute: jasmine.createSpy('it'), isExecutable: function() { return true; } };
suite.beforeAll(beforeAll);
suite.afterAll(afterAll);
suite.addChild(fakeIt);
suite.execute();
var suiteFns = fakeQueueRunner.calls.mostRecent().args[0].queueableFns;
expect(suite.isExecutable()).toBeFalsy();
expect(suiteFns.length).toEqual(1);
expect(beforeAll).not.toHaveBeenCalled();
expect(afterAll).not.toHaveBeenCalled();
});
it("can be disabled, but still calls callbacks", function() {
var env = new j$.Env(),
fakeQueueRunner = jasmine.createSpy('fake queue runner'),
@@ -93,7 +169,7 @@ describe("Suite", function() {
expect(onComplete).toHaveBeenCalled();
});
it("delegates execution of its specs and suites", function() {
it("delegates execution of its specs, suites, beforeAlls, and afterAlls", function() {
var env = new j$.Env(),
parentSuiteDone = jasmine.createSpy('parent suite done'),
fakeQueueRunnerForParent = jasmine.createSpy('fake parent queue runner'),
@@ -109,22 +185,59 @@ describe("Suite", function() {
queueRunner: fakeQueueRunner
}),
fakeSpec1 = {
execute: jasmine.createSpy('fakeSpec1')
};
execute: jasmine.createSpy('fakeSpec1'),
isExecutable: function() { return true; }
},
beforeAllFn = { fn: jasmine.createSpy('beforeAll') },
afterAllFn = { fn: jasmine.createSpy('afterAll') };
spyOn(suite, "execute");
parentSuite.addChild(fakeSpec1);
parentSuite.addChild(suite);
parentSuite.beforeAll(beforeAllFn);
parentSuite.afterAll(afterAllFn);
parentSuite.execute(parentSuiteDone);
var parentSuiteFns = fakeQueueRunnerForParent.calls.mostRecent().args[0].fns;
var parentSuiteFns = fakeQueueRunnerForParent.calls.mostRecent().args[0].queueableFns;
parentSuiteFns[0]();
parentSuiteFns[0].fn();
expect(beforeAllFn.fn).toHaveBeenCalled();
parentSuiteFns[1].fn();
expect(fakeSpec1.execute).toHaveBeenCalled();
parentSuiteFns[1]();
parentSuiteFns[2].fn();
expect(suite.execute).toHaveBeenCalled();
parentSuiteFns[3].fn();
expect(afterAllFn.fn).toHaveBeenCalled();
});
it("does not run beforeAll or afterAll if there are no executable child specs", function() {
var env = new j$.Env(),
fakeQueueRunnerForParent = jasmine.createSpy('fake parent queue runner'),
fakeQueueRunnerForChild = jasmine.createSpy('fake child queue runner'),
parentSuite = new j$.Suite({
env: env,
description: "I am a suite",
queueRunner: fakeQueueRunnerForParent
}),
childSuite = new j$.Suite({
env: env,
description: "I am a suite",
queueRunner: fakeQueueRunnerForChild,
parentSuite: parentSuite
}),
beforeAllFn = jasmine.createSpy('beforeAll'),
afterAllFn = jasmine.createSpy('afterAll');
parentSuite.addChild(childSuite);
parentSuite.beforeAll(beforeAllFn);
parentSuite.afterAll(afterAllFn);
parentSuite.execute();
expect(fakeQueueRunnerForParent).toHaveBeenCalledWith(jasmine.objectContaining({
queueableFns: [{ fn: jasmine.any(Function) }]
}));
});
it("calls a provided onStart callback when starting", function() {
@@ -138,7 +251,8 @@ describe("Suite", function() {
queueRunner: fakeQueueRunner
}),
fakeSpec1 = {
execute: jasmine.createSpy('fakeSpec1')
execute: jasmine.createSpy('fakeSpec1'),
isExecutable: function() { return true; }
};
suite.execute();
@@ -182,9 +296,10 @@ describe("Suite", function() {
expect(suiteResultsCallback).toHaveBeenCalledWith({
id: suite.id,
status: '',
status: 'finished',
description: "with a child suite",
fullName: "with a child suite"
fullName: "with a child suite",
failedExpectations: []
});
});
@@ -210,7 +325,18 @@ describe("Suite", function() {
id: suite.id,
status: 'disabled',
description: "with a child suite",
fullName: "with a child suite"
fullName: "with a child suite",
failedExpectations: []
});
});
it('has a status of failed if any afterAll expectations have failed', function() {
var suite = new j$.Suite({
expectationResultFactory: function() { return 'hi'; }
});
suite.addChild({ result: { status: 'done' } });
suite.addExpectationResult(false);
expect(suite.status()).toBe('failed');
});
});

View File

@@ -2,38 +2,38 @@ describe("Any", function() {
it("matches a string", function() {
var any = new j$.Any(String);
expect(any.jasmineMatches("foo")).toBe(true);
expect(any.asymmetricMatch("foo")).toBe(true);
});
it("matches a number", function() {
var any = new j$.Any(Number);
expect(any.jasmineMatches(1)).toBe(true);
expect(any.asymmetricMatch(1)).toBe(true);
});
it("matches a function", function() {
var any = new j$.Any(Function);
expect(any.jasmineMatches(function(){})).toBe(true);
expect(any.asymmetricMatch(function(){})).toBe(true);
});
it("matches an Object", function() {
var any = new j$.Any(Object);
expect(any.jasmineMatches({})).toBe(true);
expect(any.asymmetricMatch({})).toBe(true);
});
it("matches a Boolean", function() {
var any = new j$.Any(Boolean);
expect(any.jasmineMatches(true)).toBe(true);
expect(any.asymmetricMatch(true)).toBe(true);
});
it("matches another constructed object", function() {
var Thing = function() {},
any = new j$.Any(Thing);
expect(any.jasmineMatches(new Thing())).toBe(true);
expect(any.asymmetricMatch(new Thing())).toBe(true);
});
it("jasmineToString's itself", function() {

View File

@@ -0,0 +1,44 @@
describe("Anything", function() {
it("matches a string", function() {
var anything = new j$.Anything();
expect(anything.asymmetricMatch('foo')).toBe(true);
});
it("matches a number", function() {
var anything = new j$.Anything();
expect(anything.asymmetricMatch(42)).toBe(true);
});
it("matches an object", function() {
var anything = new j$.Anything();
expect(anything.asymmetricMatch({ foo: 'bar' })).toBe(true);
});
it("matches an array", function() {
var anything = new j$.Anything();
expect(anything.asymmetricMatch([1,2,3])).toBe(true);
});
it("doesn't match undefined", function() {
var anything = new j$.Anything();
expect(anything.asymmetricMatch()).toBe(false);
expect(anything.asymmetricMatch(undefined)).toBe(false);
});
it("doesn't match null", function() {
var anything = new j$.Anything();
expect(anything.asymmetricMatch(null)).toBe(false);
});
it("jasmineToString's itself", function() {
var anything = new j$.Anything();
expect(anything.jasmineToString()).toEqual("<jasmine.anything>");
});
});

View File

@@ -0,0 +1,39 @@
describe("ArrayContaining", function() {
it("matches any actual to an empty array", function() {
var containing = new j$.ArrayContaining([]);
expect(containing.asymmetricMatch("foo")).toBe(true);
});
it("does not work when not passed an array", function() {
var containing = new j$.ArrayContaining("foo");
expect(function() {
containing.asymmetricMatch([]);
}).toThrowError(/not 'foo'/);
});
it("matches when the item is in the actual", function() {
var containing = new j$.ArrayContaining(["foo"]);
expect(containing.asymmetricMatch(["foo"])).toBe(true);
});
it("matches when additional items are in the actual", function() {
var containing = new j$.ArrayContaining(["foo"]);
expect(containing.asymmetricMatch(["foo", "bar"])).toBe(true);
});
it("does not match when the item is not in the actual", function() {
var containing = new j$.ArrayContaining(["foo"]);
expect(containing.asymmetricMatch(["bar"])).toBe(false);
});
it("jasmineToStrings itself", function() {
var containing = new j$.ArrayContaining([]);
expect(containing.jasmineToString()).toMatch("<jasmine.arrayContaining");
});
});

View File

@@ -0,0 +1,58 @@
describe("ObjectContaining", function() {
it("matches any actual to an empty object", function() {
var containing = new j$.ObjectContaining({});
expect(containing.asymmetricMatch("foo")).toBe(true);
});
it("does not match an empty object actual", function() {
var containing = new j$.ObjectContaining("foo");
expect(function() {
containing.asymmetricMatch({})
}).toThrowError(/not 'foo'/)
});
it("matches when the key/value pair is present in the actual", function() {
var containing = new j$.ObjectContaining({foo: "fooVal"});
expect(containing.asymmetricMatch({foo: "fooVal", bar: "barVal"})).toBe(true);
});
it("does not match when the key/value pair is not present in the actual", function() {
var containing = new j$.ObjectContaining({foo: "fooVal"});
expect(containing.asymmetricMatch({bar: "barVal", quux: "quuxVal"})).toBe(false);
});
it("does not match when the key is present but the value is different in the actual", function() {
var containing = new j$.ObjectContaining({foo: "other"});
expect(containing.asymmetricMatch({foo: "fooVal", bar: "barVal"})).toBe(false);
});
it("jasmineToString's itself", function() {
var containing = new j$.ObjectContaining({});
expect(containing.jasmineToString()).toMatch("<jasmine.objectContaining");
});
it("matches recursively", function() {
var containing = new j$.ObjectContaining({one: new j$.ObjectContaining({two: {}})});
expect(containing.asymmetricMatch({one: {two: {}}})).toBe(true);
});
it("matches when key is present with undefined value", function() {
var containing = new j$.ObjectContaining({ one: undefined });
expect(containing.asymmetricMatch({ one: undefined })).toBe(true);
});
it("does not match when key with undefined value is not present", function() {
var containing = new j$.ObjectContaining({ one: undefined });
expect(containing.asymmetricMatch({})).toBe(false);
});
});

View File

@@ -0,0 +1,27 @@
describe("StringMatching", function() {
it("matches a string against a provided regexp", function() {
var matcher = new j$.StringMatching(/foo/);
expect(matcher.asymmetricMatch('barfoobaz')).toBe(true);
expect(matcher.asymmetricMatch('barbaz')).toBe(false);
});
it("matches a string against provided string", function() {
var matcher = new j$.StringMatching('foo');
expect(matcher.asymmetricMatch('barfoobaz')).toBe(true);
expect(matcher.asymmetricMatch('barbaz')).toBe(false);
});
it("raises an Error when the expected is not a String or RegExp", function() {
expect(function() {
new j$.StringMatching({});
}).toThrowError(/not a String or a RegExp/);
});
it("jasmineToString's itself", function() {
var matching = new j$.StringMatching(/^foo/);
expect(matching.jasmineToString()).toEqual("<jasmine.stringMatching(/^foo/)>");
});
});

View File

@@ -38,13 +38,13 @@ describe("Custom Matchers (Integration)", function() {
});
it("passes the spec if the custom matcher passes", function(done) {
env.addMatchers({
toBeReal: function() {
return { compare: function() { return { pass: true }; } };
}
});
env.it("spec using custom matcher", function() {
env.addMatchers({
toBeReal: function() {
return { compare: function() { return { pass: true }; } };
}
});
env.expect(true).toBeReal();
});
@@ -57,16 +57,16 @@ describe("Custom Matchers (Integration)", function() {
});
it("uses the negative compare function for a negative comparison, if provided", function(done) {
env.addMatchers({
toBeReal: function() {
return {
compare: function() { return { pass: true }; },
negativeCompare: function() { return { pass: true }; }
};
}
});
env.it("spec with custom negative comparison matcher", function() {
env.addMatchers({
toBeReal: function() {
return {
compare: function() { return { pass: true }; },
negativeCompare: function() { return { pass: true }; }
};
}
});
env.expect(true).not.toBeReal();
});
@@ -79,17 +79,17 @@ describe("Custom Matchers (Integration)", function() {
});
it("generates messages with the same rules as built in matchers absent a custom message", function(done) {
env.addMatchers({
toBeReal: function() {
return {
compare: function() {
return { pass: false };
env.it('spec with an expectation', function() {
env.addMatchers({
toBeReal: function() {
return {
compare: function() {
return { pass: false };
}
}
}
}
});
});
env.it('spec with an expectation', function() {
env.expect("a").toBeReal();
});
@@ -103,13 +103,14 @@ describe("Custom Matchers (Integration)", function() {
it("passes the expected and actual arguments to the comparison function", function(done) {
var argumentSpy = jasmine.createSpy("argument spy").and.returnValue({ pass: true });
env.addMatchers({
toBeReal: function() {
return { compare: argumentSpy };
}
});
env.it('spec with an expectation', function () {
env.addMatchers({
toBeReal: function() {
return { compare: argumentSpy };
}
});
env.expect(true).toBeReal();
env.expect(true).toBeReal("arg");
env.expect(true).toBeReal("arg1", "arg2");
@@ -130,12 +131,13 @@ describe("Custom Matchers (Integration)", function() {
argumentSpy = jasmine.createSpy("argument spy").and.returnValue(matcherFactory),
customEqualityFn = function() { return true; };
env.addCustomEqualityTester(customEqualityFn);
env.addMatchers({
toBeReal: argumentSpy
});
env.it("spec with expectation", function() {
env.addCustomEqualityTester(customEqualityFn);
env.addMatchers({
toBeReal: argumentSpy
});
env.expect(true).toBeReal();
});

File diff suppressed because it is too large Load Diff

View File

@@ -159,7 +159,7 @@ describe("jasmine spec running", function () {
];
expect(actions).toEqual(expected);
done();
}
};
env.addReporter({jasmineDone: assertions});
@@ -228,6 +228,281 @@ describe("jasmine spec running", function () {
env.execute();
});
it('should run beforeAlls before beforeEachs and afterAlls after afterEachs', function(done) {
var actions = [];
env.beforeAll(function() {
actions.push('runner beforeAll');
});
env.afterAll(function() {
actions.push('runner afterAll');
});
env.beforeEach(function () {
actions.push('runner beforeEach');
});
env.afterEach(function () {
actions.push('runner afterEach');
});
env.describe('Something', function() {
env.beforeEach(function() {
actions.push('inner beforeEach');
});
env.afterEach(function() {
actions.push('inner afterEach');
});
env.beforeAll(function() {
actions.push('inner beforeAll');
});
env.afterAll(function() {
actions.push('inner afterAll');
});
env.it('does something or other', function() {
actions.push('it');
});
});
var assertions = function() {
var expected = [
"runner beforeAll",
"inner beforeAll",
"runner beforeEach",
"inner beforeEach",
"it",
"inner afterEach",
"runner afterEach",
"inner afterAll",
"runner afterAll"
];
expect(actions).toEqual(expected);
done();
};
env.addReporter({jasmineDone: assertions});
env.execute();
});
it('should run beforeAlls and afterAlls as beforeEachs and afterEachs in the order declared when runnablesToRun is provided', function(done) {
var actions = [],
spec,
spec2;
env.beforeAll(function() {
actions.push('runner beforeAll');
});
env.afterAll(function() {
actions.push('runner afterAll');
});
env.beforeEach(function () {
actions.push('runner beforeEach');
});
env.afterEach(function () {
actions.push('runner afterEach');
});
env.describe('Something', function() {
env.beforeEach(function() {
actions.push('inner beforeEach');
});
env.afterEach(function() {
actions.push('inner afterEach');
});
env.beforeAll(function() {
actions.push('inner beforeAll');
});
env.afterAll(function() {
actions.push('inner afterAll');
});
spec = env.it('does something', function() {
actions.push('it');
});
spec2 = env.it('does something or other', function() {
actions.push('it2');
});
});
var assertions = function() {
var expected = [
"runner beforeAll",
"inner beforeAll",
"runner beforeEach",
"inner beforeEach",
"it",
"inner afterEach",
"runner afterEach",
"inner afterAll",
"runner afterAll",
"runner beforeAll",
"inner beforeAll",
"runner beforeEach",
"inner beforeEach",
"it2",
"inner afterEach",
"runner afterEach",
"inner afterAll",
"runner afterAll"
];
expect(actions).toEqual(expected);
done();
};
env.addReporter({jasmineDone: assertions});
env.execute([spec.id, spec2.id]);
});
it('only runs *Alls once in a focused suite', function(done){
var actions = [];
env.fdescribe('Suite', function() {
env.beforeAll(function(){
actions.push('beforeAll');
});
env.it('should run beforeAll once', function() {
actions.push('spec');
});
env.afterAll(function(){
actions.push('afterAll');
});
});
var assertions = function() {
expect(actions).toEqual(['beforeAll', 'spec', 'afterAll']);
done();
};
env.addReporter({jasmineDone: assertions});
env.execute();
});
describe('focused runnables', function() {
it('runs the relevant alls and eachs for each runnable', function(done) {
var actions = [];
env.beforeAll(function() {actions.push('beforeAll')});
env.afterAll(function() {actions.push('afterAll')});
env.beforeEach(function() {actions.push('beforeEach')});
env.afterEach(function() {actions.push('afterEach')});
env.fdescribe('a focused suite', function() {
env.it('is run', function() {
actions.push('spec in fdescribe')
});
});
env.describe('an unfocused suite', function() {
env.fit('has a focused spec', function() {
actions.push('focused spec')
});
});
var assertions = function() {
var expected = [
'beforeAll',
'beforeEach',
'spec in fdescribe',
'afterEach',
'afterAll',
'beforeAll',
'beforeEach',
'focused spec',
'afterEach',
'afterAll'
];
expect(actions).toEqual(expected);
done();
};
env.addReporter({jasmineDone: assertions});
env.execute();
});
it('focused specs in focused suites cause non-focused siblings to not run', function(done){
var actions = [];
env.fdescribe('focused suite', function() {
env.it('unfocused spec', function() {
actions.push('unfocused spec')
});
env.fit('focused spec', function() {
actions.push('focused spec')
});
});
var assertions = function() {
var expected = ['focused spec'];
expect(actions).toEqual(expected);
done();
};
env.addReporter({jasmineDone: assertions});
env.execute();
});
it('focused suites in focused suites cause non-focused siblings to not run', function(done){
var actions = [];
env.fdescribe('focused suite', function() {
env.it('unfocused spec', function() {
actions.push('unfocused spec')
});
env.fdescribe('inner focused suite', function() {
env.it('inner spec', function() {
actions.push('inner spec');
});
});
});
var assertions = function() {
var expected = ['inner spec'];
expect(actions).toEqual(expected);
done();
};
env.addReporter({jasmineDone: assertions});
env.execute();
});
it('focused runnables unfocus ancestor focused suites', function() {
var actions = [];
env.fdescribe('focused suite', function() {
env.it('unfocused spec', function() {
actions.push('unfocused spec')
});
env.describe('inner focused suite', function() {
env.fit('focused spec', function() {
actions.push('focused spec');
});
});
});
var assertions = function() {
var expected = ['focused spec'];
expect(actions).toEqual(expected);
done();
};
env.addReporter({jasmineDone: assertions});
env.execute();
});
});
it("shouldn't run disabled suites", function(done) {
var specInADisabledSuite = jasmine.createSpy("specInADisabledSuite"),
suite = env.describe('A Suite', function() {
@@ -236,10 +511,36 @@ describe("jasmine spec running", function () {
});
});
suite.execute(function() {
var assertions = function() {
expect(specInADisabledSuite).not.toHaveBeenCalled();
done();
};
env.addReporter({jasmineDone: assertions});
env.execute();
});
it("should allow top level suites to be disabled", function() {
var specInADisabledSuite = jasmine.createSpy("specInADisabledSuite"),
otherSpec = jasmine.createSpy("otherSpec");
env.xdescribe('A disabled suite', function() {
env.it('spec inside a disabled suite', specInADisabledSuite);
});
env.describe('Another suite', function() {
env.it('another spec', otherSpec);
});
var assertions = function() {
expect(specInADisabledSuite).not.toHaveBeenCalled();
expect(otherSpec).toHaveBeenCalled();
done();
};
env.addReporter({jasmineDone: assertions});
env.execute();
});
it("should set all pending specs to pending when a suite is run", function(done) {
@@ -254,7 +555,6 @@ describe("jasmine spec running", function () {
});
});
// TODO: is this useful? It doesn't catch syntax errors
xit("should recover gracefully when there are errors in describe functions", function() {
var specs = [];

View File

@@ -58,6 +58,16 @@ describe("matchersUtil", function() {
expect(j$.matchersUtil.equals([1, 2], [1, 2, 3])).toBe(false);
});
it("fails for Arrays whose contents are equivalent, but have differing properties", function() {
var one = [1,2,3],
two = [1,2,3];
one.foo = 'bar';
two.foo = 'baz';
expect(j$.matchersUtil.equals(one, two)).toBe(false);
});
it("passes for Errors that are the same type and have the same message", function() {
expect(j$.matchersUtil.equals(new Error("foo"), new Error("foo"))).toBe(true);
});
@@ -122,6 +132,45 @@ describe("matchersUtil", function() {
expect(j$.matchersUtil.equals(a,b)).toBe(true);
});
it("passes for equivalent DOM nodes", function() {
if (typeof document === 'undefined') {
return;
}
var a = document.createElement("div");
a.setAttribute("test-attr", "attr-value")
a.appendChild(document.createTextNode('test'));
var b = document.createElement("div");
b.setAttribute("test-attr", "attr-value")
b.appendChild(document.createTextNode('test'));
expect(j$.matchersUtil.equals(a,b)).toBe(true);
});
it("fails for DOM nodes with different attributes or child nodes", function() {
if (typeof document === 'undefined') {
return;
}
var a = document.createElement("div");
a.setAttribute("test-attr", "attr-value")
a.appendChild(document.createTextNode('test'));
var b = document.createElement("div");
b.setAttribute("test-attr", "attr-value2")
b.appendChild(document.createTextNode('test'));
expect(j$.matchersUtil.equals(a,b)).toBe(false);
b.setAttribute("test-attr", "attr-value");
expect(j$.matchersUtil.equals(a,b)).toBe(true);
b.appendChild(document.createTextNode('2'));
expect(j$.matchersUtil.equals(a,b)).toBe(false);
a.appendChild(document.createTextNode('2'));
expect(j$.matchersUtil.equals(a,b)).toBe(true);
});
it("passes when Any is used", function() {
var number = 3,
anyNumber = new j$.Any(Number);
@@ -142,9 +191,31 @@ describe("matchersUtil", function() {
var obj = {
foo: 3,
bar: 7
};
},
containing = new j$.ObjectContaining({foo: 3});
expect(j$.matchersUtil.equals(obj, new j$.ObjectContaining({foo: 3}))).toBe(true);
expect(j$.matchersUtil.equals(obj, containing)).toBe(true);
expect(j$.matchersUtil.equals(containing, obj)).toBe(true);
});
it("passes when an asymmetric equality tester returns true", function() {
var tester = { asymmetricMatch: function(other) { return true; } };
expect(j$.matchersUtil.equals(false, tester)).toBe(true);
expect(j$.matchersUtil.equals(tester, false)).toBe(true);
});
it("fails when an asymmetric equality tester returns false", function() {
var tester = { asymmetricMatch: function(other) { return false; } };
expect(j$.matchersUtil.equals(true, tester)).toBe(false);
expect(j$.matchersUtil.equals(tester, true)).toBe(false);
});
it("passes when ArrayContaining is used", function() {
var arr = ["foo", "bar"];
expect(j$.matchersUtil.equals(arr, new j$.ArrayContaining(["bar"]))).toBe(true);
});
it("passes when a custom equality matcher returns true", function() {
@@ -170,11 +241,50 @@ describe("matchersUtil", function() {
expect(j$.matchersUtil.equals(1, 1, [tester])).toBe(false);
});
it("passes for an asymmetric equality tester that returns true when a custom equality tester return false", function() {
var asymmetricTester = { asymmetricMatch: function(other) { return true; } },
symmetricTester = function(a, b) { return false; };
expect(j$.matchersUtil.equals(asymmetricTester, true, [symmetricTester])).toBe(true);
expect(j$.matchersUtil.equals(true, asymmetricTester, [symmetricTester])).toBe(true);
});
it("passes when an Any is compared to an Any that checks for the same type", function() {
var any1 = new j$.Any(Function),
any2 = new j$.Any(Function);
expect(j$.matchersUtil.equals(any1, any2)).toBe(true);
});
it("passes for null prototype objects with same properties", function () {
if (jasmine.getEnv().ieVersion < 9) { return; }
var objA = Object.create(null),
objB = Object.create(null);
objA.name = 'test';
objB.name = 'test';
expect(j$.matchersUtil.equals(objA, objB)).toBe(true);
});
it("fails for null prototype objects with different properties", function () {
if (jasmine.getEnv().ieVersion < 9) { return; }
var objA = Object.create(null),
objB = Object.create(null);
objA.name = 'test';
objB.test = 'name';
expect(j$.matchersUtil.equals(objA, objB)).toBe(false);
});
});
describe("contains", function() {
it("passes when expected is a substring of actual", function() {
expect(j$.matchersUtil.contains("ABC", "B")).toBe(true);
expect(j$.matchersUtil.contains("ABC", "BC")).toBe(true);
});
it("fails when expected is a not substring of actual", function() {
@@ -207,6 +317,15 @@ describe("matchersUtil", function() {
it("fails when actual is null", function() {
expect(j$.matchersUtil.contains(null, 'A')).toBe(false);
});
it("passes with array-like objects", function() {
var capturedArgs = null;
function testFunction(){
capturedArgs = arguments;
}
testFunction('foo', 'bar');
expect(j$.matchersUtil.contains(capturedArgs, 'bar')).toBe(true);
});
});
describe("buildMessage", function() {

View File

@@ -30,5 +30,13 @@ describe("toMatch", function() {
result = matcher.compare('bar', 'foo');
expect(result.pass).toBe(false);
});
it("throws an Error when the expected is not a String or RegExp", function() {
var matcher = j$.matchers.toMatch();
expect(function() {
matcher.compare('foo', { bar: 'baz' });
}).toThrowError('Expected is not a String or a RegExp');
});
});

View File

@@ -155,7 +155,7 @@ describe("toThrowError", function() {
result = matcher.compare(fn, Error);
expect(result.pass).toBe(true);
expect(result.message).toEqual("Expected function not to throw Error.");
expect(result.message()).toEqual("Expected function not to throw Error.");
});
it("passes if thrown is a custom error that takes arguments and the expected is the same error", function() {
@@ -175,7 +175,7 @@ describe("toThrowError", function() {
result = matcher.compare(fn, CustomError);
expect(result.pass).toBe(true);
expect(result.message).toEqual("Expected function not to throw CustomError.");
expect(result.message()).toEqual("Expected function not to throw CustomError.");
});
it("fails if thrown is an Error and the expected is a different Error", function() {
@@ -191,7 +191,7 @@ describe("toThrowError", function() {
result = matcher.compare(fn, TypeError);
expect(result.pass).toBe(false);
expect(result.message).toEqual("Expected function to throw TypeError, but it threw Error.");
expect(result.message()).toEqual("Expected function to throw TypeError, but it threw Error.");
});
it("passes if thrown is a type of Error and it is equal to the expected Error and message", function() {
@@ -259,7 +259,7 @@ describe("toThrowError", function() {
result = matcher.compare(fn, TypeError, /foo/);
expect(result.pass).toBe(true);
expect(result.message()).toEqual("Expected function not to throw TypeError with message matching /foo/.");
expect(result.message()).toEqual("Expected function not to throw TypeError with a message matching /foo/.");
});
it("fails if thrown is a type of Error and the expected is a different Error", function() {
@@ -275,6 +275,6 @@ describe("toThrowError", function() {
result = matcher.compare(fn, TypeError, /bar/);
expect(result.pass).toBe(false);
expect(result.message()).toEqual("Expected function to throw TypeError with message matching /bar/, but it threw TypeError with message 'foo'.");
expect(result.message()).toEqual("Expected function to throw TypeError with a message matching /bar/, but it threw TypeError with message 'foo'.");
});
});

View File

@@ -65,8 +65,8 @@ describe("New HtmlReporter", function() {
describe("when a spec is done", function() {
it("logs errors to the console and prints a special symbol if it is an empty spec", function() {
if (!window.console) {
window.console = { error: function(){} };
if (typeof console === "undefined") {
console = { error: function(){} };
}
var env = new j$.Env(),
@@ -179,6 +179,34 @@ describe("New HtmlReporter", function() {
});
});
describe("when there are suite failures", function () {
it("displays the exceptions in their own alert bars", function(){
var env = new j$.Env(),
container = document.createElement("div"),
getContainer = function() { return container; },
reporter = new j$.HtmlReporter({
env: env,
getContainer: getContainer,
createElement: function() { return document.createElement.apply(document, arguments); },
createTextNode: function() { return document.createTextNode.apply(document, arguments); }
});
reporter.initialize();
reporter.jasmineStarted({});
reporter.suiteDone({ status: 'failed', failedExpectations: [{ message: 'My After All Exception' }] });
reporter.suiteDone({ status: 'failed', failedExpectations: [{ message: 'My Other Exception' }] });
reporter.jasmineDone({});
var alertBars = container.querySelectorAll(".alert .bar");
expect(alertBars.length).toEqual(3);
expect(alertBars[1].innerHTML).toMatch(/My After All Exception/);
expect(alertBars[1].getAttribute("class")).toEqual('bar errored');
expect(alertBars[2].innerHTML).toMatch(/My Other Exception/);
});
});
describe("when Jasmine is done", function() {
it("adds EMPTY to the link title of specs that have no expectations", function() {
if (!window.console) {
@@ -250,7 +278,8 @@ describe("New HtmlReporter", function() {
env: env,
getContainer: getContainer,
createElement: function() { return document.createElement.apply(document, arguments); },
createTextNode: function() { return document.createTextNode.apply(document, arguments); }
createTextNode: function() { return document.createTextNode.apply(document, arguments); },
addToExistingQueryString: function(key, value) { return "?foo=bar&" + key + "=" + value; }
});
reporter.initialize();
@@ -322,7 +351,7 @@ describe("New HtmlReporter", function() {
var suiteDetail = outerSuite.childNodes[0];
var suiteLink = suiteDetail.childNodes[0];
expect(suiteLink.innerHTML).toEqual("A Suite");
expect(suiteLink.getAttribute('href')).toEqual("?spec=A%20Suite");
expect(suiteLink.getAttribute('href')).toEqual("?foo=bar&spec=A Suite");
var specs = outerSuite.childNodes[1];
var spec = specs.childNodes[0];
@@ -331,7 +360,7 @@ describe("New HtmlReporter", function() {
var specLink = spec.childNodes[0];
expect(specLink.innerHTML).toEqual("with a spec");
expect(specLink.getAttribute("href")).toEqual("?spec=A%20Suite%20with%20a%20spec");
expect(specLink.getAttribute("href")).toEqual("?foo=bar&spec=A Suite with a spec");
// expect(specLink.getAttribute("title")).toEqual("A Suite with a spec");
});
@@ -504,14 +533,17 @@ describe("New HtmlReporter", function() {
reporter.initialize();
reporter.jasmineStarted({ totalSpecsDefined: 1 });
reporter.specDone({
var specStatus = {
id: 123,
description: "with a spec",
fullName: "A Suite with a spec",
status: "pending",
passedExpectations: [],
failedExpectations: []
});
failedExpectations: [],
pendingReason: "my custom pending reason"
};
reporter.specStarted(specStatus);
reporter.specDone(specStatus);
reporter.jasmineDone({});
});
@@ -526,6 +558,12 @@ describe("New HtmlReporter", function() {
expect(specFailure.childNodes.length).toEqual(0);
});
it("displays the custom pending reason", function() {
var pendingDetails = container.querySelector(".summary .pending");
expect(pendingDetails.innerHTML).toContain("my custom pending reason");
});
});
describe("and some tests fail", function() {
@@ -539,7 +577,8 @@ describe("New HtmlReporter", function() {
env: env,
getContainer: getContainer,
createElement: function() { return document.createElement.apply(document, arguments); },
createTextNode: function() { return document.createTextNode.apply(document, arguments); }
createTextNode: function() { return document.createTextNode.apply(document, arguments); },
addToExistingQueryString: function(key, value) { return "?foo=bar&" + key + "=" + value; }
});
reporter.initialize();
@@ -586,7 +625,7 @@ describe("New HtmlReporter", function() {
var specLink = specDiv.childNodes[0];
expect(specLink.getAttribute("title")).toEqual("a suite with a failing spec");
expect(specLink.getAttribute("href")).toEqual("?spec=a%20suite%20with%20a%20failing%20spec");
expect(specLink.getAttribute("href")).toEqual("?foo=bar&spec=a suite with a failing spec");
var message = failure.childNodes[1].childNodes[0];
expect(message.getAttribute("class")).toEqual("result-message");

View File

@@ -3,7 +3,7 @@ describe("j$.pp (HTML Dependent)", function () {
var sampleNode = document.createElement('div');
sampleNode.innerHTML = 'foo<b>bar</b>';
expect(j$.pp(sampleNode)).toEqual("HTMLNode");
expect(j$.pp({foo: sampleNode})).toEqual("{ foo: HTMLNode }");
expect(j$.pp({foo: sampleNode})).toEqual("Object({ foo: HTMLNode })");
});
it("should print Firefox's wrapped native objects correctly", function() {

View File

@@ -1,7 +1,6 @@
describe("QueryString", function() {
describe("#setParam", function() {
describe("#navigateWithNewParam", function() {
it("sets the query string to include the given key/value pair", function() {
var windowLocation = {
search: ""
@@ -10,10 +9,40 @@ describe("QueryString", function() {
getWindowLocation: function() { return windowLocation }
});
queryString.setParam("foo", "bar baz");
queryString.navigateWithNewParam("foo", "bar baz");
expect(windowLocation.search).toMatch(/foo=bar%20baz/);
});
it("leaves existing params alone", function() {
var windowLocation = {
search: "?foo=bar"
},
queryString = new j$.QueryString({
getWindowLocation: function() { return windowLocation }
});
queryString.navigateWithNewParam("baz", "quux");
expect(windowLocation.search).toMatch(/foo=bar/);
expect(windowLocation.search).toMatch(/baz=quux/);
});
});
describe('#fullStringWithNewParam', function() {
it("gets the query string including the given key/value pair", function() {
var windowLocation = {
search: "?foo=bar"
},
queryString = new j$.QueryString({
getWindowLocation: function() { return windowLocation }
});
var result = queryString.fullStringWithNewParam("baz", "quux");
expect(result).toMatch(/foo=bar/);
expect(result).toMatch(/baz=quux/);
});
});
describe("#getParam", function() {

195
spec/node_suite.js Normal file
View File

@@ -0,0 +1,195 @@
var fs = require('fs');
var util = require('util');
var path = require('path');
// boot code for jasmine
var jasmineRequire = require('../lib/jasmine-core/jasmine.js');
var jasmine = jasmineRequire.core(jasmineRequire);
var consoleFns = require('../lib/console/console.js');
extend(jasmineRequire, consoleFns);
jasmineRequire.console(jasmineRequire, jasmine);
var env = jasmine.getEnv();
var jasmineInterface = {
describe: function(description, specDefinitions) {
return env.describe(description, specDefinitions);
},
xdescribe: function(description, specDefinitions) {
return env.xdescribe(description, specDefinitions);
},
it: function(desc, func) {
return env.it(desc, func);
},
xit: function(desc, func) {
return env.xit(desc, func);
},
beforeEach: function(beforeEachFunction) {
return env.beforeEach(beforeEachFunction);
},
afterEach: function(afterEachFunction) {
return env.afterEach(afterEachFunction);
},
expect: function(actual) {
return env.expect(actual);
},
spyOn: function(obj, methodName) {
return env.spyOn(obj, methodName);
},
jsApiReporter: new jasmine.JsApiReporter({
timer: new jasmine.Timer()
}),
beforeAll: function(beforeAllFunction) {
return env.beforeAll(beforeAllFunction);
},
afterAll: function(afterAllFunction) {
return env.afterAll(afterAllFunction);
}
};
extend(global, jasmineInterface);
function extend(destination, source) {
for (var property in source) destination[property] = source[property];
return destination;
}
jasmine.addCustomEqualityTester = function(tester) {
env.addCustomEqualityTester(tester);
};
jasmine.addMatchers = function(matchers) {
return env.addMatchers(matchers);
};
jasmine.clock = function() {
return env.clock;
};
// Jasmine "runner"
function executeSpecs(specs, done, isVerbose, showColors) {
global.jasmine = jasmine;
for (var i = 0; i < specs.length; i++) {
var filename = specs[i];
require(filename.replace(/\.\w+$/, ""));
}
var env = jasmine.getEnv();
var consoleReporter = new jasmine.ConsoleReporter({
print: util.print,
onComplete: done,
showColors: showColors,
timer: new jasmine.Timer()
});
env.addReporter(consoleReporter);
env.execute();
}
function getFiles(dir, matcher) {
var allFiles = [];
if (fs.statSync(dir).isFile() && dir.match(matcher)) {
allFiles.push(dir);
} else {
var files = fs.readdirSync(dir);
for (var i = 0, len = files.length; i < len; ++i) {
var filename = dir + '/' + files[i];
if (fs.statSync(filename).isFile() && filename.match(matcher)) {
allFiles.push(filename);
} else if (fs.statSync(filename).isDirectory()) {
var subfiles = getFiles(filename);
subfiles.forEach(function(result) {
allFiles.push(result);
});
}
}
}
return allFiles;
}
function getSpecFiles(dir) {
return getFiles(dir, new RegExp("Spec.js$"));
}
var j$require = (function() {
var exported = {},
j$req;
global.getJasmineRequireObj = getJasmineRequireObj;
j$req = require(__dirname + "/../src/core/requireCore.js");
extend(j$req, require(__dirname + "/../src/console/requireConsole.js"));
var srcFiles = getFiles(__dirname + "/../src/core");
srcFiles.push(__dirname + "/../src/version.js");
srcFiles.push(__dirname + "/../src/console/ConsoleReporter.js");
for (var i = 0; i < srcFiles.length; i++) {
require(srcFiles[i]);
}
extend(j$req, exported);
delete global.getJasmineRequireObj;
return j$req;
function getJasmineRequireObj() {
return exported;
}
}());
j$ = j$require.core(j$require);
j$require.console(j$require, j$);
// options from command line
var isVerbose = false;
var showColors = true;
var perfSuite = false;
process.argv.forEach(function(arg) {
switch (arg) {
case '--color':
showColors = true;
break;
case '--noColor':
showColors = false;
break;
case '--verbose':
isVerbose = true;
break;
case '--perf':
perfSuite = true;
break;
}
});
specs = [];
if (perfSuite) {
specs = getFiles(__dirname + '/performance', new RegExp("test.js$"));
} else {
var consoleSpecs = getSpecFiles(__dirname + "/console"),
coreSpecs = getSpecFiles(__dirname + "/core"),
specs = consoleSpecs.concat(coreSpecs);
}
executeSpecs(specs, function(passed) {
if (passed) {
process.exit(0);
} else {
process.exit(1);
}
}, isVerbose, showColors);

View File

@@ -0,0 +1,104 @@
describe('npm package', function() {
var path = require('path'),
fs = require('fs');
beforeAll(function() {
var shell = require('shelljs'),
pack = shell.exec('npm pack', { silent: true });
this.tarball = pack.output.split('\n')[0];
this.tmpDir = '/tmp/jasmine-core';
fs.mkdirSync(this.tmpDir);
var untar = shell.exec('tar -xzf ' + this.tarball + ' -C ' + this.tmpDir, { silent: true });
expect(untar.code).toBe(0);
this.packagedCore = require(path.join(this.tmpDir, 'package/lib/jasmine-core.js'));
});
beforeEach(function() {
jasmine.addMatchers({
toExistInPath: function(util, customEquality) {
return {
compare: function(actual, expected) {
var fullPath = path.resolve(expected, actual);
return {
pass: fs.existsSync(fullPath)
};
}
};
}
});
});
afterAll(function() {
var cleanup = function (parent, fileOrFolder) {
var fullPath = path.join(parent, fileOrFolder);
if (fs.statSync(fullPath).isFile()) {
fs.unlinkSync(fullPath);
} else {
fs.readdirSync(fullPath).forEach(cleanup.bind(null, fullPath));
fs.rmdirSync(fullPath);
}
};
fs.unlink(this.tarball);
fs.readdirSync(this.tmpDir).forEach(cleanup.bind(null, this.tmpDir));
fs.rmdirSync(this.tmpDir);
});
it('has a root path', function() {
expect(this.packagedCore.files.path).toEqual(fs.realpathSync(path.resolve(this.tmpDir, 'package/lib/jasmine-core')));
});
it('has a bootDir', function() {
expect(this.packagedCore.files.bootDir).toEqual(fs.realpathSync(path.resolve(this.tmpDir, 'package/lib/jasmine-core')));
});
it('has jsFiles', function() {
expect(this.packagedCore.files.jsFiles).toEqual([
'jasmine.js',
'jasmine-html.js',
'json2.js'
]);
var packagedCore = this.packagedCore;
this.packagedCore.files.jsFiles.forEach(function(fileName) {
expect(fileName).toExistInPath(packagedCore.files.path);
});
});
it('has cssFiles', function() {
expect(this.packagedCore.files.cssFiles).toEqual(['jasmine.css']);
var packagedCore = this.packagedCore;
this.packagedCore.files.cssFiles.forEach(function(fileName) {
expect(fileName).toExistInPath(packagedCore.files.path);
});
});
it('has bootFiles', function() {
expect(this.packagedCore.files.bootFiles).toEqual(['boot.js']);
expect(this.packagedCore.files.nodeBootFiles).toEqual(['node_boot.js']);
var packagedCore = this.packagedCore;
this.packagedCore.files.bootFiles.forEach(function(fileName) {
expect(fileName).toExistInPath(packagedCore.files.bootDir);
});
var packagedCore = this.packagedCore;
this.packagedCore.files.nodeBootFiles.forEach(function(fileName) {
expect(fileName).toExistInPath(packagedCore.files.bootDir);
});
});
it('has an imagesDir', function() {
expect(this.packagedCore.files.imagesDir).toEqual(fs.realpathSync(path.resolve(this.tmpDir, 'package/images')));
var images = fs.readdirSync(path.resolve(this.tmpDir, 'package/images'));
expect(images).toContain('jasmine-horizontal.png');
expect(images).toContain('jasmine-horizontal.svg');
expect(images).toContain('jasmine_favicon.png');
});
});

View File

@@ -2,7 +2,8 @@
"spec_dir": "spec",
"spec_files": [
"core/**/*.js",
"console/**/*.js"
"console/**/*.js",
"npmPackage/**/*.js"
],
"helpers": [
"helpers/nodeDefineJasmineUnderTest.js"

View File

@@ -20,6 +20,7 @@ helpers:
- 'helpers/defineJasmineUnderTest.js'
spec_files:
- '**/*[Ss]pec.js'
- '!npmPackage/**/*'
spec_dir: spec

View File

@@ -19,7 +19,10 @@ getJasmineRequireObj().ConsoleReporter = function() {
red: '\x1B[31m',
yellow: '\x1B[33m',
none: '\x1B[0m'
};
},
failedSuites = [];
print('ConsoleReporter is deprecated and will be removed in a future version.');
this.jasmineStarted = function() {
specCount = 0;
@@ -54,9 +57,12 @@ getJasmineRequireObj().ConsoleReporter = function() {
printNewline();
var seconds = timer.elapsed() / 1000;
print('Finished in ' + seconds + ' ' + plural('second', seconds));
printNewline();
for(i = 0; i < failedSuites.length; i++) {
suiteFailureDetails(failedSuites[i]);
}
onComplete(failureCount === 0);
};
@@ -81,6 +87,13 @@ getJasmineRequireObj().ConsoleReporter = function() {
}
};
this.suiteDone = function(result) {
if (result.failedExpectations && result.failedExpectations.length > 0) {
failureCount++;
failedSuites.push(result);
}
};
return this;
function printNewline() {
@@ -125,6 +138,17 @@ getJasmineRequireObj().ConsoleReporter = function() {
printNewline();
}
function suiteFailureDetails(result) {
for (var i = 0; i < result.failedExpectations.length; i++) {
printNewline();
print(colored('red', 'An error was thrown in an afterAll'));
printNewline();
print(colored('red', 'AfterAll ' + result.failedExpectations[i].message));
}
printNewline();
}
}
return ConsoleReporter;

View File

@@ -114,6 +114,12 @@ getJasmineRequireObj().DelayedFunctionScheduler = function() {
scheduledFn.runAtMillis + scheduledFn.millis);
}
function forEachFunction(funcsToRun, callback) {
for (var i = 0; i < funcsToRun.length; ++i) {
callback(funcsToRun[i]);
}
}
function runScheduledFunctions(endTime) {
if (scheduledLookup.length === 0 || scheduledLookup[0] > endTime) {
return;
@@ -125,14 +131,15 @@ getJasmineRequireObj().DelayedFunctionScheduler = function() {
var funcsToRun = scheduledFunctions[currentTime];
delete scheduledFunctions[currentTime];
for (var i = 0; i < funcsToRun.length; ++i) {
var funcToRun = funcsToRun[i];
funcToRun.funcToCall.apply(null, funcToRun.params || []);
forEachFunction(funcsToRun, function(funcToRun) {
if (funcToRun.recurring) {
reschedule(funcToRun);
}
}
});
forEachFunction(funcsToRun, function(funcToRun) {
funcToRun.funcToCall.apply(null, funcToRun.params || []);
});
} while (scheduledLookup.length > 0 &&
// checking first if we're out of time prevents setTimeout(0)
// scheduled in a funcToRun from forcing an extra iteration

View File

@@ -14,11 +14,19 @@ getJasmineRequireObj().Env = function(j$) {
this.clock = new j$.Clock(global, new j$.DelayedFunctionScheduler(), new j$.MockDate(global));
var runnableLookupTable = {};
var spies = [];
var runnableResources = {};
var currentSpec = null;
var currentSuite = null;
var currentlyExecutingSuites = [];
var currentDeclarationSuite = null;
var currentSuite = function() {
return currentlyExecutingSuites[currentlyExecutingSuites.length - 1];
};
var currentRunnable = function() {
return currentSpec || currentSuite();
};
var reporter = new j$.ReportDispatcher([
'jasmineStarted',
@@ -33,11 +41,21 @@ getJasmineRequireObj().Env = function(j$) {
return true;
};
var equalityTesters = [];
var customEqualityTesters = [];
this.addCustomEqualityTester = function(tester) {
customEqualityTesters.push(tester);
if(!currentRunnable()) {
throw new Error('Custom Equalities must be added in a before function or a spec');
}
runnableResources[currentRunnable().id].customEqualityTesters.push(tester);
};
this.addMatchers = function(matchersToAdd) {
if(!currentRunnable()) {
throw new Error('Matchers must be added in a before function or a spec');
}
var customMatchers = runnableResources[currentRunnable().id].customMatchers;
for (var matcherName in matchersToAdd) {
customMatchers[matcherName] = matchersToAdd[matcherName];
}
};
j$.Expectation.addCoreMatchers(j$.matchers);
@@ -55,7 +73,8 @@ getJasmineRequireObj().Env = function(j$) {
var expectationFactory = function(actual, spec) {
return j$.Expectation.Factory({
util: j$.matchersUtil,
customEqualityTesters: customEqualityTesters,
customEqualityTesters: runnableResources[spec.id].customEqualityTesters,
customMatchers: runnableResources[spec.id].customMatchers,
actual: actual,
addExpectationResult: addExpectationResult
});
@@ -65,30 +84,44 @@ getJasmineRequireObj().Env = function(j$) {
}
};
var specStarted = function(spec) {
currentSpec = spec;
reporter.specStarted(spec.result);
var defaultResourcesForRunnable = function(id, parentRunnableId) {
var resources = {spies: [], customEqualityTesters: [], customMatchers: {}};
if(runnableResources[parentRunnableId]){
resources.customEqualityTesters = j$.util.clone(runnableResources[parentRunnableId].customEqualityTesters);
resources.customMatchers = j$.util.clone(runnableResources[parentRunnableId].customMatchers);
}
runnableResources[id] = resources;
};
var beforeFns = function(suite) {
var clearResourcesForRunnable = function(id) {
spyRegistry.clearSpies();
delete runnableResources[id];
};
var beforeAndAfterFns = function(suite, runnablesExplictlySet) {
return function() {
var befores = [];
var befores = [],
afters = [],
beforeAlls = [],
afterAlls = [];
while(suite) {
befores = befores.concat(suite.beforeFns);
suite = suite.parentSuite;
}
return befores.reverse();
};
};
var afterFns = function(suite) {
return function() {
var afters = [];
while(suite) {
afters = afters.concat(suite.afterFns);
if (runnablesExplictlySet()) {
beforeAlls = beforeAlls.concat(suite.beforeAllFns);
afterAlls = afterAlls.concat(suite.afterAllFns);
}
suite = suite.parentSuite;
}
return afters;
return {
befores: beforeAlls.reverse().concat(befores.reverse()),
afters: afters.concat(afterAlls)
};
};
};
@@ -137,6 +170,7 @@ getJasmineRequireObj().Env = function(j$) {
options.catchException = catchException;
options.clearStack = options.clearStack || clearStack;
options.timer = {setTimeout: realSetTimeout, clearTimeout: realClearTimeout};
options.fail = self.fail;
new j$.QueueRunner(options).execute();
};
@@ -145,66 +179,52 @@ getJasmineRequireObj().Env = function(j$) {
env: this,
id: getNextSuiteId(),
description: 'Jasmine__TopLevel__Suite',
queueRunner: queueRunnerFactory,
resultCallback: function() {} // TODO - hook this up
queueRunner: queueRunnerFactory
});
runnableLookupTable[topSuite.id] = topSuite;
currentSuite = topSuite;
defaultResourcesForRunnable(topSuite.id);
currentDeclarationSuite = topSuite;
this.topSuite = function() {
return topSuite;
};
this.execute = function(runnablesToRun) {
runnablesToRun = runnablesToRun || [topSuite.id];
if(runnablesToRun) {
runnablesExplictlySet = true;
} else if (focusedRunnables.length) {
runnablesExplictlySet = true;
runnablesToRun = focusedRunnables;
} else {
runnablesToRun = [topSuite.id];
}
var allFns = [];
for(var i = 0; i < runnablesToRun.length; i++) {
var runnable = runnableLookupTable[runnablesToRun[i]];
allFns.push((function(runnable) { return function(done) { runnable.execute(done); }; })(runnable));
allFns.push((function(runnable) { return { fn: function(done) { runnable.execute(done); } }; })(runnable));
}
reporter.jasmineStarted({
totalSpecsDefined: totalSpecsDefined
});
queueRunnerFactory({fns: allFns, onComplete: reporter.jasmineDone});
queueRunnerFactory({queueableFns: allFns, onComplete: reporter.jasmineDone});
};
this.addReporter = function(reporterToAdd) {
reporter.addReporter(reporterToAdd);
};
this.addMatchers = function(matchersToAdd) {
j$.Expectation.addMatchers(matchersToAdd);
};
this.spyOn = function(obj, methodName) {
if (j$.util.isUndefined(obj)) {
throw new Error('spyOn could not find an object to spy upon for ' + methodName + '()');
var spyRegistry = new j$.SpyRegistry({currentSpies: function() {
if(!currentRunnable()) {
throw new Error('Spies must be created in a before function or a spec');
}
return runnableResources[currentRunnable().id].spies;
}});
if (j$.util.isUndefined(obj[methodName])) {
throw new Error(methodName + '() method does not exist');
}
if (obj[methodName] && j$.isSpy(obj[methodName])) {
//TODO?: should this return the current spy? Downside: may cause user confusion about spy state
throw new Error(methodName + ' has already been spied upon');
}
var spy = j$.createSpy(methodName, obj[methodName]);
spies.push({
spy: spy,
baseObj: obj,
methodName: methodName,
originalValue: obj[methodName]
});
obj[methodName] = spy;
return spy;
this.spyOn = function() {
return spyRegistry.spyOn.apply(spyRegistry, arguments);
};
var suiteFactory = function(description) {
@@ -212,40 +232,34 @@ getJasmineRequireObj().Env = function(j$) {
env: self,
id: getNextSuiteId(),
description: description,
parentSuite: currentSuite,
parentSuite: currentDeclarationSuite,
queueRunner: queueRunnerFactory,
onStart: suiteStarted,
expectationFactory: expectationFactory,
expectationResultFactory: expectationResultFactory,
runnablesExplictlySetGetter: runnablesExplictlySetGetter,
resultCallback: function(attrs) {
if (!suite.disabled) {
clearResourcesForRunnable(suite.id);
}
currentlyExecutingSuites.pop();
reporter.suiteDone(attrs);
}
});
runnableLookupTable[suite.id] = suite;
return suite;
function suiteStarted(suite) {
currentlyExecutingSuites.push(suite);
defaultResourcesForRunnable(suite.id, suite.parentSuite.id);
reporter.suiteStarted(suite.result);
}
};
this.describe = function(description, specDefinitions) {
var suite = suiteFactory(description);
var parentSuite = currentSuite;
parentSuite.addChild(suite);
currentSuite = suite;
var declarationError = null;
try {
specDefinitions.call(suite);
} catch (e) {
declarationError = e;
}
if (declarationError) {
this.it('encountered a declaration exception', function() {
throw declarationError;
});
}
currentSuite = parentSuite;
addSpecsToSuite(suite, specDefinitions);
return suite;
};
@@ -255,15 +269,75 @@ getJasmineRequireObj().Env = function(j$) {
return suite;
};
var specFactory = function(description, fn, suite) {
totalSpecsDefined++;
var focusedRunnables = [];
this.fdescribe = function(description, specDefinitions) {
var suite = suiteFactory(description);
suite.isFocused = true;
focusedRunnables.push(suite.id);
unfocusAncestor();
addSpecsToSuite(suite, specDefinitions);
return suite;
};
function addSpecsToSuite(suite, specDefinitions) {
var parentSuite = currentDeclarationSuite;
parentSuite.addChild(suite);
currentDeclarationSuite = suite;
var declarationError = null;
try {
specDefinitions.call(suite);
} catch (e) {
declarationError = e;
}
if (declarationError) {
self.it('encountered a declaration exception', function() {
throw declarationError;
});
}
currentDeclarationSuite = parentSuite;
}
function findFocusedAncestor(suite) {
while (suite) {
if (suite.isFocused) {
return suite.id;
}
suite = suite.parentSuite;
}
return null;
}
function unfocusAncestor() {
var focusedAncestor = findFocusedAncestor(currentDeclarationSuite);
if (focusedAncestor) {
for (var i = 0; i < focusedRunnables.length; i++) {
if (focusedRunnables[i] === focusedAncestor) {
focusedRunnables.splice(i, 1);
break;
}
}
}
}
var runnablesExplictlySet = false;
var runnablesExplictlySetGetter = function(){
return runnablesExplictlySet;
};
var specFactory = function(description, fn, suite, timeout) {
totalSpecsDefined++;
var spec = new j$.Spec({
id: getNextSpecId(),
beforeFns: beforeFns(suite),
afterFns: afterFns(suite),
beforeAndAfterFns: beforeAndAfterFns(suite, runnablesExplictlySetGetter),
expectationFactory: expectationFactory,
exceptionFormatter: exceptionFormatter,
resultCallback: specResultCallback,
getSpecName: function(spec) {
return getSpecName(spec, suite);
@@ -272,7 +346,11 @@ getJasmineRequireObj().Env = function(j$) {
description: description,
expectationResultFactory: expectationResultFactory,
queueRunnerFactory: queueRunnerFactory,
fn: fn
userContext: function() { return suite.clonedSharedUserContext(); },
queueableFn: {
fn: fn,
timeout: function() { return timeout || j$.DEFAULT_TIMEOUT_INTERVAL; }
}
});
runnableLookupTable[spec.id] = spec;
@@ -283,57 +361,98 @@ getJasmineRequireObj().Env = function(j$) {
return spec;
function removeAllSpies() {
for (var i = 0; i < spies.length; i++) {
var spyEntry = spies[i];
spyEntry.baseObj[spyEntry.methodName] = spyEntry.originalValue;
}
spies = [];
}
function specResultCallback(result) {
removeAllSpies();
j$.Expectation.resetMatchers();
customEqualityTesters = [];
clearResourcesForRunnable(spec.id);
currentSpec = null;
reporter.specDone(result);
}
function specStarted(spec) {
currentSpec = spec;
defaultResourcesForRunnable(spec.id, suite.id);
reporter.specStarted(spec.result);
}
};
var suiteStarted = function(suite) {
reporter.suiteStarted(suite.result);
};
this.it = function(description, fn) {
var spec = specFactory(description, fn, currentSuite);
currentSuite.addChild(spec);
this.it = function(description, fn, timeout) {
var spec = specFactory(description, fn, currentDeclarationSuite, timeout);
currentDeclarationSuite.addChild(spec);
return spec;
};
this.xit = function(description, fn) {
var spec = this.it(description, fn);
this.xit = function() {
var spec = this.it.apply(this, arguments);
spec.pend();
return spec;
};
this.fit = function(){
var spec = this.it.apply(this, arguments);
focusedRunnables.push(spec.id);
unfocusAncestor();
return spec;
};
this.expect = function(actual) {
if (!currentSpec) {
if (!currentRunnable()) {
throw new Error('\'expect\' was used when there was no current spec, this could be because an asynchronous test timed out');
}
return currentSpec.expect(actual);
return currentRunnable().expect(actual);
};
this.beforeEach = function(beforeEachFunction) {
currentSuite.beforeEach(beforeEachFunction);
this.beforeEach = function(beforeEachFunction, timeout) {
currentDeclarationSuite.beforeEach({
fn: beforeEachFunction,
timeout: function() { return timeout || j$.DEFAULT_TIMEOUT_INTERVAL; }
});
};
this.afterEach = function(afterEachFunction) {
currentSuite.afterEach(afterEachFunction);
this.beforeAll = function(beforeAllFunction, timeout) {
currentDeclarationSuite.beforeAll({
fn: beforeAllFunction,
timeout: function() { return timeout || j$.DEFAULT_TIMEOUT_INTERVAL; }
});
};
this.pending = function() {
throw j$.Spec.pendingSpecExceptionMessage;
this.afterEach = function(afterEachFunction, timeout) {
currentDeclarationSuite.afterEach({
fn: afterEachFunction,
timeout: function() { return timeout || j$.DEFAULT_TIMEOUT_INTERVAL; }
});
};
this.afterAll = function(afterAllFunction, timeout) {
currentDeclarationSuite.afterAll({
fn: afterAllFunction,
timeout: function() { return timeout || j$.DEFAULT_TIMEOUT_INTERVAL; }
});
};
this.pending = function(message) {
var fullMessage = j$.Spec.pendingSpecExceptionMessage;
if(message) {
fullMessage += message;
}
throw fullMessage;
};
this.fail = function(error) {
var message = 'Failed';
if (error) {
message += ': ';
message += error.message || error;
}
currentRunnable().addExpectationResult(false, {
matcherName: '',
passed: false,
expected: '',
actual: '',
message: message,
error: error && error.message ? error : null
});
};
}

View File

@@ -1,7 +1,5 @@
getJasmineRequireObj().Expectation = function() {
var matchers = {};
function Expectation(options) {
this.util = options.util || { buildFailureMessage: function() {} };
this.customEqualityTesters = options.customEqualityTesters || [];
@@ -9,8 +7,9 @@ getJasmineRequireObj().Expectation = function() {
this.addExpectationResult = options.addExpectationResult || function(){};
this.isNot = options.isNot;
for (var matcherName in matchers) {
this[matcherName] = matchers[matcherName];
var customMatchers = options.customMatchers || {};
for (var matcherName in customMatchers) {
this[matcherName] = Expectation.prototype.wrapCompare(matcherName, customMatchers[matcherName]);
}
}
@@ -77,19 +76,6 @@ getJasmineRequireObj().Expectation = function() {
}
};
Expectation.addMatchers = function(matchersToAdd) {
for (var name in matchersToAdd) {
var matcher = matchersToAdd[name];
matchers[name] = Expectation.prototype.wrapCompare(name, matcher);
}
};
Expectation.resetMatchers = function() {
for (var name in matchers) {
delete matchers[name];
}
};
Expectation.Factory = function(options) {
options = options || {};

View File

@@ -4,15 +4,20 @@ getJasmineRequireObj().buildExpectationResult = function() {
var messageFormatter = options.messageFormatter || function() {},
stackFormatter = options.stackFormatter || function() {};
return {
var result = {
matcherName: options.matcherName,
expected: options.expected,
actual: options.actual,
message: message(),
stack: stack(),
passed: options.passed
};
if(!result.passed) {
result.expected = options.expected;
result.actual = options.actual;
}
return result;
function message() {
if (options.passed) {
return 'Passed.';

View File

@@ -30,26 +30,31 @@ getJasmineRequireObj().JsApiReporter = function() {
return status;
};
var suites = {};
var suites = [],
suites_hash = {};
this.suiteStarted = function(result) {
storeSuite(result);
suites_hash[result.id] = result;
};
this.suiteDone = function(result) {
storeSuite(result);
};
this.suiteResults = function(index, length) {
return suites.slice(index, index + length);
};
function storeSuite(result) {
suites[result.id] = result;
suites.push(result);
suites_hash[result.id] = result;
}
this.suites = function() {
return suites;
return suites_hash;
};
var specs = [];
this.specStarted = function(result) { };
this.specDone = function(result) {
specs.push(result);

View File

@@ -54,13 +54,14 @@ getJasmineRequireObj().MockDate = function() {
case 6:
return new GlobalDate(arguments[0], arguments[1], arguments[2], arguments[3],
arguments[4], arguments[5]);
case 7:
default:
return new GlobalDate(arguments[0], arguments[1], arguments[2], arguments[3],
arguments[4], arguments[5], arguments[6]);
}
}
function createDateProperties() {
FakeDate.prototype = GlobalDate.prototype;
FakeDate.now = function() {
if (GlobalDate.now) {

View File

@@ -1,34 +0,0 @@
getJasmineRequireObj().ObjectContaining = function(j$) {
function ObjectContaining(sample) {
this.sample = sample;
}
ObjectContaining.prototype.jasmineMatches = function(other, mismatchKeys, mismatchValues) {
if (typeof(this.sample) !== 'object') { throw new Error('You must provide an object to objectContaining, not \''+this.sample+'\'.'); }
mismatchKeys = mismatchKeys || [];
mismatchValues = mismatchValues || [];
var hasKey = function(obj, keyName) {
return obj !== null && !j$.util.isUndefined(obj[keyName]);
};
for (var property in this.sample) {
if (!hasKey(other, property) && hasKey(this.sample, property)) {
mismatchKeys.push('expected has key \'' + property + '\', but missing from actual.');
}
else if (!j$.matchersUtil.equals(other[property], this.sample[property])) {
mismatchValues.push('\'' + property + '\' was \'' + (other[property] ? j$.util.htmlEscape(other[property].toString()) : other[property]) + '\' in actual, but was \'' + (this.sample[property] ? j$.util.htmlEscape(this.sample[property].toString()) : this.sample[property]) + '\' in expected.');
}
}
return (mismatchKeys.length === 0 && mismatchValues.length === 0);
};
ObjectContaining.prototype.jasmineToString = function() {
return '<jasmine.objectContaining(' + j$.pp(this.sample) + ')>';
};
return ObjectContaining;
};

View File

@@ -97,13 +97,15 @@ getJasmineRequireObj().pp = function(j$) {
};
StringPrettyPrinter.prototype.emitObject = function(obj) {
var constructorName = obj.constructor ? j$.fnNameFor(obj.constructor) : 'null';
this.append(constructorName);
if (this.ppNestLevel_ > j$.MAX_PRETTY_PRINT_DEPTH) {
this.append('Object');
return;
}
var self = this;
this.append('{ ');
this.append('({ ');
var first = true;
this.iterateObject(obj, function(property, isGetter) {
@@ -122,7 +124,7 @@ getJasmineRequireObj().pp = function(j$) {
}
});
this.append(' }');
this.append(' })');
};
StringPrettyPrinter.prototype.append = function(value) {

View File

@@ -11,31 +11,33 @@ getJasmineRequireObj().QueueRunner = function(j$) {
}
function QueueRunner(attrs) {
this.fns = attrs.fns || [];
this.queueableFns = attrs.queueableFns || [];
this.onComplete = attrs.onComplete || function() {};
this.clearStack = attrs.clearStack || function(fn) {fn();};
this.onException = attrs.onException || function() {};
this.catchException = attrs.catchException || function() { return true; };
this.enforceTimeout = attrs.enforceTimeout || function() { return false; };
this.userContext = {};
this.userContext = attrs.userContext || {};
this.timer = attrs.timeout || {setTimeout: setTimeout, clearTimeout: clearTimeout};
this.fail = attrs.fail || function() {};
}
QueueRunner.prototype.execute = function() {
this.run(this.fns, 0);
this.run(this.queueableFns, 0);
};
QueueRunner.prototype.run = function(fns, recursiveIndex) {
var length = fns.length,
self = this,
iterativeIndex;
QueueRunner.prototype.run = function(queueableFns, recursiveIndex) {
var length = queueableFns.length,
self = this,
iterativeIndex;
for(iterativeIndex = recursiveIndex; iterativeIndex < length; iterativeIndex++) {
var fn = fns[iterativeIndex];
if (fn.length > 0) {
return attemptAsync(fn);
var queueableFn = queueableFns[iterativeIndex];
if (queueableFn.fn.length > 0) {
attemptAsync(queueableFn);
return;
} else {
attemptSync(fn);
attemptSync(queueableFn);
}
}
@@ -45,41 +47,51 @@ getJasmineRequireObj().QueueRunner = function(j$) {
this.clearStack(this.onComplete);
}
function attemptSync(fn) {
function attemptSync(queueableFn) {
try {
fn.call(self.userContext);
queueableFn.fn.call(self.userContext);
} catch (e) {
handleException(e);
handleException(e, queueableFn);
}
}
function attemptAsync(fn) {
function attemptAsync(queueableFn) {
var clearTimeout = function () {
Function.prototype.apply.apply(self.timer.clearTimeout, [j$.getGlobal(), [timeoutId]]);
},
next = once(function () {
clearTimeout(timeoutId);
self.run(fns, iterativeIndex + 1);
self.run(queueableFns, iterativeIndex + 1);
}),
timeoutId;
if (self.enforceTimeout()) {
next.fail = function() {
self.fail.apply(null, arguments);
next();
};
if (queueableFn.timeout) {
timeoutId = Function.prototype.apply.apply(self.timer.setTimeout, [j$.getGlobal(), [function() {
self.onException(new Error('Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.'));
var error = new Error('Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.');
onException(error, queueableFn);
next();
}, j$.DEFAULT_TIMEOUT_INTERVAL]]);
}, queueableFn.timeout()]]);
}
try {
fn.call(self.userContext, next);
queueableFn.fn.call(self.userContext, next);
} catch (e) {
handleException(e);
handleException(e, queueableFn);
next();
}
}
function handleException(e) {
function onException(e, queueableFn) {
self.onException(e);
}
function handleException(e, queueableFn) {
onException(e, queueableFn);
if (!self.catchException(e)) {
//TODO: set a var when we catch an exception and
//use a finally block to close the loop in a nice way..

View File

@@ -4,17 +4,16 @@ getJasmineRequireObj().Spec = function(j$) {
this.resultCallback = attrs.resultCallback || function() {};
this.id = attrs.id;
this.description = attrs.description || '';
this.fn = attrs.fn;
this.beforeFns = attrs.beforeFns || function() { return []; };
this.afterFns = attrs.afterFns || function() { return []; };
this.queueableFn = attrs.queueableFn;
this.beforeAndAfterFns = attrs.beforeAndAfterFns || function() { return {befores: [], afters: []}; };
this.userContext = attrs.userContext || function() { return {}; };
this.onStart = attrs.onStart || function() {};
this.exceptionFormatter = attrs.exceptionFormatter || function() {};
this.getSpecName = attrs.getSpecName || function() { return ''; };
this.expectationResultFactory = attrs.expectationResultFactory || function() { };
this.queueRunnerFactory = attrs.queueRunnerFactory || function() {};
this.catchingExceptions = attrs.catchingExceptions || function() { return true; };
if (!this.fn) {
if (!this.queueableFn.fn) {
this.pend();
}
@@ -23,7 +22,8 @@ getJasmineRequireObj().Spec = function(j$) {
description: this.description,
fullName: this.getFullName(),
failedExpectations: [],
passedExpectations: []
passedExpectations: [],
pendingReason: ''
};
}
@@ -50,30 +50,16 @@ getJasmineRequireObj().Spec = function(j$) {
return;
}
var allFns = this.beforeFns().concat(this.fn).concat(this.afterFns());
var fns = this.beforeAndAfterFns();
var allFns = fns.befores.concat(this.queueableFn).concat(fns.afters);
this.queueRunnerFactory({
fns: allFns,
onException: onException,
queueableFns: allFns,
onException: function() { self.onException.apply(self, arguments); },
onComplete: complete,
enforceTimeout: function() { return true; }
userContext: this.userContext()
});
function onException(e) {
if (Spec.isPendingSpecException(e)) {
self.pend();
return;
}
self.addExpectationResult(false, {
matcherName: '',
passed: false,
expected: '',
actual: '',
error: e
});
}
function complete() {
self.result.status = self.status();
self.resultCallback(self.result);
@@ -84,12 +70,30 @@ getJasmineRequireObj().Spec = function(j$) {
}
};
Spec.prototype.onException = function onException(e) {
if (Spec.isPendingSpecException(e)) {
this.pend(extractCustomPendingMessage(e));
return;
}
this.addExpectationResult(false, {
matcherName: '',
passed: false,
expected: '',
actual: '',
error: e
});
};
Spec.prototype.disable = function() {
this.disabled = true;
};
Spec.prototype.pend = function() {
Spec.prototype.pend = function(message) {
this.markedPending = true;
if (message) {
this.result.pendingReason = message;
}
};
Spec.prototype.status = function() {
@@ -108,10 +112,22 @@ getJasmineRequireObj().Spec = function(j$) {
}
};
Spec.prototype.isExecutable = function() {
return !this.disabled && !this.markedPending;
};
Spec.prototype.getFullName = function() {
return this.getSpecName(this);
};
var extractCustomPendingMessage = function(e) {
var fullMessage = e.toString(),
boilerplateStart = fullMessage.indexOf(Spec.pendingSpecExceptionMessage),
boilerplateEnd = boilerplateStart + Spec.pendingSpecExceptionMessage.length;
return fullMessage.substr(boilerplateEnd);
};
Spec.pendingSpecExceptionMessage = '=> marked Pending';
Spec.isPendingSpecException = function(e) {

49
src/core/SpyRegistry.js Normal file
View File

@@ -0,0 +1,49 @@
getJasmineRequireObj().SpyRegistry = function(j$) {
function SpyRegistry(options) {
options = options || {};
var currentSpies = options.currentSpies || function() { return []; };
this.spyOn = function(obj, methodName) {
if (j$.util.isUndefined(obj)) {
throw new Error('spyOn could not find an object to spy upon for ' + methodName + '()');
}
if (j$.util.isUndefined(methodName)) {
throw new Error('No method name supplied');
}
if (j$.util.isUndefined(obj[methodName])) {
throw new Error(methodName + '() method does not exist');
}
if (obj[methodName] && j$.isSpy(obj[methodName])) {
//TODO?: should this return the current spy? Downside: may cause user confusion about spy state
throw new Error(methodName + ' has already been spied upon');
}
var spy = j$.createSpy(methodName, obj[methodName]);
currentSpies().push({
spy: spy,
baseObj: obj,
methodName: methodName,
originalValue: obj[methodName]
});
obj[methodName] = spy;
return spy;
};
this.clearSpies = function() {
var spies = currentSpies();
for (var i = 0; i < spies.length; i++) {
var spyEntry = spies[i];
spyEntry.baseObj[spyEntry.methodName] = spyEntry.originalValue;
}
};
}
return SpyRegistry;
};

View File

@@ -28,6 +28,14 @@ getJasmineRequireObj().SpyStrategy = function() {
return getSpy();
};
this.returnValues = function() {
var values = Array.prototype.slice.call(arguments);
plan = function () {
return values.shift();
};
return getSpy();
};
this.throwError = function(something) {
var error = (something instanceof Error) ? something : new Error(something);
plan = function() {

View File

@@ -7,9 +7,14 @@ getJasmineRequireObj().Suite = function() {
this.onStart = attrs.onStart || function() {};
this.resultCallback = attrs.resultCallback || function() {};
this.clearStack = attrs.clearStack || function(fn) {fn();};
this.expectationFactory = attrs.expectationFactory;
this.expectationResultFactory = attrs.expectationResultFactory;
this.runnablesExplictlySetGetter = attrs.runnablesExplictlySetGetter || function() {};
this.beforeFns = [];
this.afterFns = [];
this.beforeAllFns = [];
this.afterAllFns = [];
this.queueRunner = attrs.queueRunner || function() {};
this.disabled = false;
@@ -17,12 +22,16 @@ getJasmineRequireObj().Suite = function() {
this.result = {
id: this.id,
status: this.disabled ? 'disabled' : '',
description: this.description,
fullName: this.getFullName()
fullName: this.getFullName(),
failedExpectations: []
};
}
Suite.prototype.expect = function(actual) {
return this.expectationFactory(actual, this);
};
Suite.prototype.getFullName = function() {
var fullName = this.description;
for (var parentSuite = this.parentSuite; parentSuite; parentSuite = parentSuite.parentSuite) {
@@ -35,21 +44,40 @@ getJasmineRequireObj().Suite = function() {
Suite.prototype.disable = function() {
this.disabled = true;
this.result.status = 'disabled';
};
Suite.prototype.beforeEach = function(fn) {
this.beforeFns.unshift(fn);
};
Suite.prototype.beforeAll = function(fn) {
this.beforeAllFns.push(fn);
};
Suite.prototype.afterEach = function(fn) {
this.afterFns.unshift(fn);
};
Suite.prototype.afterAll = function(fn) {
this.afterAllFns.push(fn);
};
Suite.prototype.addChild = function(child) {
this.children.push(child);
};
Suite.prototype.status = function() {
if (this.disabled) {
return 'disabled';
}
if (this.result.failedExpectations.length > 0) {
return 'failed';
} else {
return 'finished';
}
};
Suite.prototype.execute = function(onComplete) {
var self = this;
@@ -66,12 +94,20 @@ getJasmineRequireObj().Suite = function() {
allFns.push(wrapChildAsAsync(this.children[i]));
}
if (this.isExecutable()) {
allFns = this.beforeAllFns.concat(allFns);
allFns = allFns.concat(this.afterAllFns);
}
this.queueRunner({
fns: allFns,
onComplete: complete
queueableFns: allFns,
onComplete: complete,
userContext: this.sharedUserContext(),
onException: function() { self.onException.apply(self, arguments); }
});
function complete() {
self.result.status = self.status();
self.resultCallback(self.result);
if (onComplete) {
@@ -80,10 +116,87 @@ getJasmineRequireObj().Suite = function() {
}
function wrapChildAsAsync(child) {
return function(done) { child.execute(done); };
return { fn: function(done) { child.execute(done); } };
}
};
Suite.prototype.isExecutable = function() {
var runnablesExplicitlySet = this.runnablesExplictlySetGetter();
return !runnablesExplicitlySet && hasExecutableChild(this.children);
};
Suite.prototype.sharedUserContext = function() {
if (!this.sharedContext) {
this.sharedContext = this.parentSuite ? clone(this.parentSuite.sharedUserContext()) : {};
}
return this.sharedContext;
};
Suite.prototype.clonedSharedUserContext = function() {
return clone(this.sharedUserContext());
};
Suite.prototype.onException = function() {
if(isAfterAll(this.children)) {
var data = {
matcherName: '',
passed: false,
expected: '',
actual: '',
error: arguments[0]
};
this.result.failedExpectations.push(this.expectationResultFactory(data));
} else {
for (var i = 0; i < this.children.length; i++) {
var child = this.children[i];
child.onException.apply(child, arguments);
}
}
};
Suite.prototype.addExpectationResult = function () {
if(isAfterAll(this.children) && isFailure(arguments)){
var data = arguments[1];
this.result.failedExpectations.push(this.expectationResultFactory(data));
} else {
for (var i = 0; i < this.children.length; i++) {
var child = this.children[i];
child.addExpectationResult.apply(child, arguments);
}
}
};
function isAfterAll(children) {
return children && children[0].result.status;
}
function isFailure(args) {
return !args[0];
}
function hasExecutableChild(children) {
var foundActive = false;
for (var i = 0; i < children.length; i++) {
if (children[i].isExecutable()) {
foundActive = true;
break;
}
}
return foundActive;
}
function clone(obj) {
var clonedObj = {};
for (var prop in obj) {
if (obj.hasOwnProperty(prop)) {
clonedObj[prop] = obj[prop];
}
}
return clonedObj;
}
return Suite;
};

View File

@@ -4,7 +4,7 @@ getJasmineRequireObj().Any = function() {
this.expectedObject = expectedObject;
}
Any.prototype.jasmineMatches = function(other) {
Any.prototype.asymmetricMatch = function(other) {
if (this.expectedObject == String) {
return typeof other == 'string' || other instanceof String;
}
@@ -20,7 +20,7 @@ getJasmineRequireObj().Any = function() {
if (this.expectedObject == Object) {
return typeof other == 'object';
}
if (this.expectedObject == Boolean) {
return typeof other == 'boolean';
}

View File

@@ -0,0 +1,14 @@
getJasmineRequireObj().Anything = function(j$) {
function Anything() {}
Anything.prototype.asymmetricMatch = function(other) {
return !j$.util.isUndefined(other) && other !== null;
};
Anything.prototype.jasmineToString = function() {
return '<jasmine.anything>';
};
return Anything;
};

View File

@@ -0,0 +1,25 @@
getJasmineRequireObj().ArrayContaining = function(j$) {
function ArrayContaining(sample) {
this.sample = sample;
}
ArrayContaining.prototype.asymmetricMatch = function(other) {
var className = Object.prototype.toString.call(this.sample);
if (className !== '[object Array]') { throw new Error('You must provide an array to arrayContaining, not \'' + this.sample + '\'.'); }
for (var i = 0; i < this.sample.length; i++) {
var item = this.sample[i];
if (!j$.matchersUtil.contains(other, item)) {
return false;
}
}
return true;
};
ArrayContaining.prototype.jasmineToString = function () {
return '<jasmine.arrayContaining(' + jasmine.pp(this.sample) +')>';
};
return ArrayContaining;
};

View File

@@ -0,0 +1,25 @@
getJasmineRequireObj().ObjectContaining = function(j$) {
function ObjectContaining(sample) {
this.sample = sample;
}
ObjectContaining.prototype.asymmetricMatch = function(other) {
if (typeof(this.sample) !== 'object') { throw new Error('You must provide an object to objectContaining, not \''+this.sample+'\'.'); }
for (var property in this.sample) {
if (!Object.prototype.hasOwnProperty.call(other, property) ||
!j$.matchersUtil.equals(this.sample[property], other[property])) {
return false;
}
}
return true;
};
ObjectContaining.prototype.jasmineToString = function() {
return '<jasmine.objectContaining(' + j$.pp(this.sample) + ')>';
};
return ObjectContaining;
};

View File

@@ -0,0 +1,20 @@
getJasmineRequireObj().StringMatching = function(j$) {
function StringMatching(expected) {
if (!j$.isString_(expected) && !j$.isA_('RegExp', expected)) {
throw new Error('Expected is not a String or a RegExp');
}
this.regexp = new RegExp(expected);
}
StringMatching.prototype.asymmetricMatch = function(other) {
return this.regexp.test(other);
};
StringMatching.prototype.jasmineToString = function() {
return '<jasmine.stringMatching(' + this.regexp + ')>';
};
return StringMatching;
};

View File

@@ -1,102 +1,122 @@
getJasmineRequireObj().base = (function (jasmineGlobal) {
if (typeof module !== 'undefined' && module.exports) {
jasmineGlobal = global;
}
getJasmineRequireObj().base = function(j$, jasmineGlobal) {
j$.unimplementedMethod_ = function() {
throw new Error('unimplemented method');
};
return function(j$) {
j$.unimplementedMethod_ = function() {
throw new Error('unimplemented method');
};
j$.MAX_PRETTY_PRINT_DEPTH = 40;
j$.MAX_PRETTY_PRINT_ARRAY_LENGTH = 100;
j$.DEFAULT_TIMEOUT_INTERVAL = 5000;
j$.MAX_PRETTY_PRINT_DEPTH = 40;
j$.MAX_PRETTY_PRINT_ARRAY_LENGTH = 100;
j$.DEFAULT_TIMEOUT_INTERVAL = 5000;
j$.getGlobal = function() {
return jasmineGlobal;
};
j$.getGlobal = function() {
return jasmineGlobal;
};
j$.getEnv = function(options) {
var env = j$.currentEnv_ = j$.currentEnv_ || new j$.Env(options);
//jasmine. singletons in here (setTimeout blah blah).
return env;
};
j$.getEnv = function(options) {
var env = j$.currentEnv_ = j$.currentEnv_ || new j$.Env(options);
//jasmine. singletons in here (setTimeout blah blah).
return env;
};
j$.isArray_ = function(value) {
return j$.isA_('Array', value);
};
j$.isArray_ = function(value) {
return j$.isA_('Array', value);
};
j$.isString_ = function(value) {
return j$.isA_('String', value);
};
j$.isString_ = function(value) {
return j$.isA_('String', value);
};
j$.isNumber_ = function(value) {
return j$.isA_('Number', value);
};
j$.isNumber_ = function(value) {
return j$.isA_('Number', value);
};
j$.isA_ = function(typeName, value) {
return Object.prototype.toString.apply(value) === '[object ' + typeName + ']';
};
j$.isA_ = function(typeName, value) {
return Object.prototype.toString.apply(value) === '[object ' + typeName + ']';
};
j$.isDomNode = function(obj) {
return obj.nodeType > 0;
};
j$.isDomNode = function(obj) {
return obj.nodeType > 0;
};
j$.fnNameFor = function(func) {
return func.name || func.toString().match(/^\s*function\s*(\w*)\s*\(/)[1];
};
j$.any = function(clazz) {
return new j$.Any(clazz);
};
j$.any = function(clazz) {
return new j$.Any(clazz);
};
j$.objectContaining = function(sample) {
return new j$.ObjectContaining(sample);
};
j$.anything = function() {
return new j$.Anything();
};
j$.createSpy = function(name, originalFn) {
j$.objectContaining = function(sample) {
return new j$.ObjectContaining(sample);
};
var spyStrategy = new j$.SpyStrategy({
name: name,
fn: originalFn,
getSpy: function() { return spy; }
}),
callTracker = new j$.CallTracker(),
spy = function() {
callTracker.track({
object: this,
args: Array.prototype.slice.apply(arguments)
});
return spyStrategy.exec.apply(this, arguments);
j$.stringMatching = function(expected) {
return new j$.StringMatching(expected);
};
j$.arrayContaining = function(sample) {
return new j$.ArrayContaining(sample);
};
j$.createSpy = function(name, originalFn) {
var spyStrategy = new j$.SpyStrategy({
name: name,
fn: originalFn,
getSpy: function() { return spy; }
}),
callTracker = new j$.CallTracker(),
spy = function() {
var callData = {
object: this,
args: Array.prototype.slice.apply(arguments)
};
for (var prop in originalFn) {
if (prop === 'and' || prop === 'calls') {
throw new Error('Jasmine spies would overwrite the \'and\' and \'calls\' properties on the object being spied upon');
}
callTracker.track(callData);
var returnValue = spyStrategy.exec.apply(this, arguments);
callData.returnValue = returnValue;
spy[prop] = originalFn[prop];
return returnValue;
};
for (var prop in originalFn) {
if (prop === 'and' || prop === 'calls') {
throw new Error('Jasmine spies would overwrite the \'and\' and \'calls\' properties on the object being spied upon');
}
spy.and = spyStrategy;
spy.calls = callTracker;
spy[prop] = originalFn[prop];
}
return spy;
};
spy.and = spyStrategy;
spy.calls = callTracker;
j$.isSpy = function(putativeSpy) {
if (!putativeSpy) {
return false;
}
return putativeSpy.and instanceof j$.SpyStrategy &&
putativeSpy.calls instanceof j$.CallTracker;
};
j$.createSpyObj = function(baseName, methodNames) {
if (!j$.isArray_(methodNames) || methodNames.length === 0) {
throw 'createSpyObj requires a non-empty array of method names to create spies for';
}
var obj = {};
for (var i = 0; i < methodNames.length; i++) {
obj[methodNames[i]] = j$.createSpy(baseName + '.' + methodNames[i]);
}
return obj;
};
return spy;
};
})(this);
j$.isSpy = function(putativeSpy) {
if (!putativeSpy) {
return false;
}
return putativeSpy.and instanceof j$.SpyStrategy &&
putativeSpy.calls instanceof j$.CallTracker;
};
j$.createSpyObj = function(baseName, methodNames) {
if (j$.isArray_(baseName) && j$.util.isUndefined(methodNames)) {
methodNames = baseName;
baseName = 'unknown';
}
if (!j$.isArray_(methodNames) || methodNames.length === 0) {
throw 'createSpyObj requires a non-empty array of method names to create spies for';
}
var obj = {};
for (var i = 0; i < methodNames.length; i++) {
obj[methodNames[i]] = j$.createSpy(baseName + '.' + methodNames[i]);
}
return obj;
};
};

View File

@@ -11,7 +11,9 @@ getJasmineRequireObj().matchersUtil = function(j$) {
contains: function(haystack, needle, customTesters) {
customTesters = customTesters || [];
if (Object.prototype.toString.apply(haystack) === '[object Array]') {
if ((Object.prototype.toString.apply(haystack) === '[object Array]') ||
(!!haystack && !haystack.indexOf))
{
for (var i = 0; i < haystack.length; i++) {
if (eq(haystack[i], needle, [], [], customTesters)) {
return true;
@@ -19,6 +21,7 @@ getJasmineRequireObj().matchersUtil = function(j$) {
}
return false;
}
return !!haystack && haystack.indexOf(needle) >= 0;
},
@@ -48,11 +51,37 @@ getJasmineRequireObj().matchersUtil = function(j$) {
}
};
function isAsymmetric(obj) {
return obj && j$.isA_('Function', obj.asymmetricMatch);
}
function asymmetricMatch(a, b) {
var asymmetricA = isAsymmetric(a),
asymmetricB = isAsymmetric(b);
if (asymmetricA && asymmetricB) {
return undefined;
}
if (asymmetricA) {
return a.asymmetricMatch(b);
}
if (asymmetricB) {
return b.asymmetricMatch(a);
}
}
// Equality function lovingly adapted from isEqual in
// [Underscore](http://underscorejs.org)
function eq(a, b, aStack, bStack, customTesters) {
var result = true;
var asymmetricResult = asymmetricMatch(a, b);
if (!j$.util.isUndefined(asymmetricResult)) {
return asymmetricResult;
}
for (var i = 0; i < customTesters.length; i++) {
var customTesterResult = customTesters[i](a, b);
if (!j$.util.isUndefined(customTesterResult)) {
@@ -60,27 +89,6 @@ getJasmineRequireObj().matchersUtil = function(j$) {
}
}
if (a instanceof j$.Any) {
result = a.jasmineMatches(b);
if (result) {
return true;
}
}
if (b instanceof j$.Any) {
result = b.jasmineMatches(a);
if (result) {
return true;
}
}
if (b instanceof j$.ObjectContaining) {
result = b.jasmineMatches(a);
if (result) {
return true;
}
}
if (a instanceof Error && b instanceof Error) {
return a.message == b.message;
}
@@ -116,6 +124,29 @@ getJasmineRequireObj().matchersUtil = function(j$) {
a.ignoreCase == b.ignoreCase;
}
if (typeof a != 'object' || typeof b != 'object') { return false; }
var aIsDomNode = j$.isDomNode(a);
var bIsDomNode = j$.isDomNode(b);
if (aIsDomNode && bIsDomNode) {
// At first try to use DOM3 method isEqualNode
if (a.isEqualNode) {
return a.isEqualNode(b);
}
// IE8 doesn't support isEqualNode, try to use outerHTML && innerText
var aIsElement = a instanceof Element;
var bIsElement = b instanceof Element;
if (aIsElement && bIsElement) {
return a.outerHTML == b.outerHTML;
}
if (aIsElement || bIsElement) {
return false;
}
return a.innerText == b.innerText && a.textContent == b.textContent;
}
if (aIsDomNode || bIsDomNode) {
return false;
}
// Assume equality for cyclic structures. The algorithm for detecting cyclic
// structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`.
var length = aStack.length;
@@ -129,17 +160,12 @@ getJasmineRequireObj().matchersUtil = function(j$) {
bStack.push(b);
var size = 0;
// Recursively compare objects and arrays.
if (className == '[object Array]') {
// Compare array lengths to determine if a deep comparison is necessary.
size = a.length;
result = size == b.length;
if (result) {
// Deep compare the contents, ignoring non-numeric properties.
while (size--) {
if (!(result = eq(a[size], b[size], aStack, bStack, customTesters))) { break; }
}
}
} else {
// Compare array lengths to determine if a deep comparison is necessary.
if (className == '[object Array]' && a.length !== b.length) {
result = false;
}
if (result) {
// Objects with different constructors are not equivalent, but `Object`s
// from different frames are.
var aCtor = a.constructor, bCtor = b.constructor;
@@ -171,7 +197,7 @@ getJasmineRequireObj().matchersUtil = function(j$) {
return result;
function has(obj, key) {
return obj.hasOwnProperty(key);
return Object.prototype.hasOwnProperty.call(obj, key);
}
function isFunction(obj) {

View File

@@ -1,8 +1,12 @@
getJasmineRequireObj().toMatch = function() {
getJasmineRequireObj().toMatch = function(j$) {
function toMatch() {
return {
compare: function(actual, expected) {
if (!j$.isString_(expected) && !j$.isA_('RegExp', expected)) {
throw new Error('Expected is not a String or a RegExp');
}
var regexp = new RegExp(expected);
return {

View File

@@ -5,18 +5,13 @@ getJasmineRequireObj().toThrowError = function(j$) {
var threw = false,
pass = {pass: true},
fail = {pass: false},
thrown,
errorType,
message,
regexp,
name,
constructorName;
thrown;
if (typeof actual != 'function') {
throw new Error('Actual is not a Function');
}
extractExpectedParams.apply(null, arguments);
var errorMatcher = getMatcher.apply(null, arguments);
try {
actual();
@@ -35,121 +30,104 @@ getJasmineRequireObj().toThrowError = function(j$) {
return fail;
}
if (arguments.length == 1) {
pass.message = 'Expected function not to throw an Error, but it threw ' + fnNameFor(thrown) + '.';
if (errorMatcher.hasNoSpecifics()) {
pass.message = 'Expected function not to throw an Error, but it threw ' + j$.fnNameFor(thrown) + '.';
return pass;
}
if (errorType) {
name = fnNameFor(errorType);
constructorName = fnNameFor(thrown.constructor);
}
if (errorType && message) {
if (thrown.constructor == errorType && util.equals(thrown.message, message)) {
pass.message = function() { return 'Expected function not to throw ' + name + ' with message ' + j$.pp(message) + '.'; };
return pass;
} else {
fail.message = function() { return 'Expected function to throw ' + name + ' with message ' + j$.pp(message) +
', but it threw ' + constructorName + ' with message ' + j$.pp(thrown.message) + '.'; };
return fail;
}
}
if (errorType && regexp) {
if (thrown.constructor == errorType && regexp.test(thrown.message)) {
pass.message = function() { return 'Expected function not to throw ' + name + ' with message matching ' + j$.pp(regexp) + '.'; };
return pass;
} else {
fail.message = function() { return 'Expected function to throw ' + name + ' with message matching ' + j$.pp(regexp) +
', but it threw ' + constructorName + ' with message ' + j$.pp(thrown.message) + '.'; };
return fail;
}
}
if (errorType) {
if (thrown.constructor == errorType) {
pass.message = 'Expected function not to throw ' + name + '.';
return pass;
} else {
fail.message = 'Expected function to throw ' + name + ', but it threw ' + constructorName + '.';
return fail;
}
}
if (message) {
if (thrown.message == message) {
pass.message = function() { return 'Expected function not to throw an exception with message ' + j$.pp(message) + '.'; };
return pass;
} else {
fail.message = function() { return 'Expected function to throw an exception with message ' + j$.pp(message) +
', but it threw an exception with message ' + j$.pp(thrown.message) + '.'; };
return fail;
}
}
if (regexp) {
if (regexp.test(thrown.message)) {
pass.message = function() { return 'Expected function not to throw an exception with a message matching ' + j$.pp(regexp) + '.'; };
return pass;
} else {
fail.message = function() { return 'Expected function to throw an exception with a message matching ' + j$.pp(regexp) +
', but it threw an exception with message ' + j$.pp(thrown.message) + '.'; };
return fail;
}
}
function fnNameFor(func) {
return func.name || func.toString().match(/^\s*function\s*(\w*)\s*\(/)[1];
}
function extractExpectedParams() {
if (arguments.length == 1) {
return;
}
if (arguments.length == 2) {
var expected = arguments[1];
if (expected instanceof RegExp) {
regexp = expected;
} else if (typeof expected == 'string') {
message = expected;
} else if (checkForAnErrorType(expected)) {
errorType = expected;
}
if (!(errorType || message || regexp)) {
throw new Error('Expected is not an Error, string, or RegExp.');
}
} else {
if (checkForAnErrorType(arguments[1])) {
errorType = arguments[1];
} else {
throw new Error('Expected error type is not an Error.');
}
if (arguments[2] instanceof RegExp) {
regexp = arguments[2];
} else if (typeof arguments[2] == 'string') {
message = arguments[2];
} else {
throw new Error('Expected error message is not a string or RegExp.');
}
}
}
function checkForAnErrorType(type) {
if (typeof type !== 'function') {
return false;
}
var Surrogate = function() {};
Surrogate.prototype = type.prototype;
return (new Surrogate()) instanceof Error;
if (errorMatcher.matches(thrown)) {
pass.message = function() {
return 'Expected function not to throw ' + errorMatcher.errorTypeDescription + errorMatcher.messageDescription() + '.';
};
return pass;
} else {
fail.message = function() {
return 'Expected function to throw ' + errorMatcher.errorTypeDescription + errorMatcher.messageDescription() +
', but it threw ' + errorMatcher.thrownDescription(thrown) + '.';
};
return fail;
}
}
};
function getMatcher() {
var expected = null,
errorType = null;
if (arguments.length == 2) {
expected = arguments[1];
if (isAnErrorType(expected)) {
errorType = expected;
expected = null;
}
} else if (arguments.length > 2) {
errorType = arguments[1];
expected = arguments[2];
if (!isAnErrorType(errorType)) {
throw new Error('Expected error type is not an Error.');
}
}
if (expected && !isStringOrRegExp(expected)) {
if (errorType) {
throw new Error('Expected error message is not a string or RegExp.');
} else {
throw new Error('Expected is not an Error, string, or RegExp.');
}
}
function messageMatch(message) {
if (typeof expected == 'string') {
return expected == message;
} else {
return expected.test(message);
}
}
return {
errorTypeDescription: errorType ? j$.fnNameFor(errorType) : 'an exception',
thrownDescription: function(thrown) {
var thrownName = errorType ? j$.fnNameFor(thrown.constructor) : 'an exception',
thrownMessage = '';
if (expected) {
thrownMessage = ' with message ' + j$.pp(thrown.message);
}
return thrownName + thrownMessage;
},
messageDescription: function() {
if (expected === null) {
return '';
} else if (expected instanceof RegExp) {
return ' with a message matching ' + j$.pp(expected);
} else {
return ' with message ' + j$.pp(expected);
}
},
hasNoSpecifics: function() {
return expected === null && errorType === null;
},
matches: function(error) {
return (errorType === null || error.constructor === errorType) &&
(expected === null || messageMatch(error.message));
}
};
}
function isStringOrRegExp(potential) {
return potential instanceof RegExp || (typeof potential == 'string');
}
function isAnErrorType(type) {
if (typeof type !== 'function') {
return false;
}
var Surrogate = function() {};
Surrogate.prototype = type.prototype;
return (new Surrogate()) instanceof Error;
}
}
return toThrowError;

View File

@@ -1,39 +1,54 @@
function getJasmineRequireObj() {
var getJasmineRequireObj = (function (jasmineGlobal) {
var jasmineRequire;
if (typeof module !== 'undefined' && module.exports) {
return exports;
jasmineGlobal = global;
jasmineRequire = exports;
} else {
window.jasmineRequire = window.jasmineRequire || {};
return window.jasmineRequire;
if (typeof window !== 'undefined' && typeof window.toString === 'function' && window.toString() === '[object GjsGlobal]') {
jasmineGlobal = window;
}
jasmineRequire = jasmineGlobal.jasmineRequire = jasmineGlobal.jasmineRequire || {};
}
}
getJasmineRequireObj().core = function(jRequire) {
var j$ = {};
function getJasmineRequire() {
return jasmineRequire;
}
jRequire.base(j$);
j$.util = jRequire.util();
j$.Any = jRequire.Any();
j$.CallTracker = jRequire.CallTracker();
j$.MockDate = jRequire.MockDate();
j$.Clock = jRequire.Clock();
j$.DelayedFunctionScheduler = jRequire.DelayedFunctionScheduler();
j$.Env = jRequire.Env(j$);
j$.ExceptionFormatter = jRequire.ExceptionFormatter();
j$.Expectation = jRequire.Expectation();
j$.buildExpectationResult = jRequire.buildExpectationResult();
j$.JsApiReporter = jRequire.JsApiReporter();
j$.matchersUtil = jRequire.matchersUtil(j$);
j$.ObjectContaining = jRequire.ObjectContaining(j$);
j$.pp = jRequire.pp(j$);
j$.QueueRunner = jRequire.QueueRunner(j$);
j$.ReportDispatcher = jRequire.ReportDispatcher();
j$.Spec = jRequire.Spec(j$);
j$.SpyStrategy = jRequire.SpyStrategy();
j$.Suite = jRequire.Suite();
j$.Timer = jRequire.Timer();
j$.version = jRequire.version();
getJasmineRequire().core = function(jRequire) {
var j$ = {};
j$.matchers = jRequire.requireMatchers(jRequire, j$);
jRequire.base(j$, jasmineGlobal);
j$.util = jRequire.util();
j$.Any = jRequire.Any();
j$.Anything = jRequire.Anything(j$);
j$.CallTracker = jRequire.CallTracker();
j$.MockDate = jRequire.MockDate();
j$.Clock = jRequire.Clock();
j$.DelayedFunctionScheduler = jRequire.DelayedFunctionScheduler();
j$.Env = jRequire.Env(j$);
j$.ExceptionFormatter = jRequire.ExceptionFormatter();
j$.Expectation = jRequire.Expectation();
j$.buildExpectationResult = jRequire.buildExpectationResult();
j$.JsApiReporter = jRequire.JsApiReporter();
j$.matchersUtil = jRequire.matchersUtil(j$);
j$.ObjectContaining = jRequire.ObjectContaining(j$);
j$.ArrayContaining = jRequire.ArrayContaining(j$);
j$.pp = jRequire.pp(j$);
j$.QueueRunner = jRequire.QueueRunner(j$);
j$.ReportDispatcher = jRequire.ReportDispatcher();
j$.Spec = jRequire.Spec(j$);
j$.SpyRegistry = jRequire.SpyRegistry(j$);
j$.SpyStrategy = jRequire.SpyStrategy();
j$.StringMatching = jRequire.StringMatching(j$);
j$.Suite = jRequire.Suite();
j$.Timer = jRequire.Timer();
j$.version = jRequire.version();
return j$;
};
j$.matchers = jRequire.requireMatchers(jRequire, j$);
return j$;
};
return getJasmineRequire;
})(this);

View File

@@ -8,20 +8,36 @@ getJasmineRequireObj().interface = function(jasmine, env) {
return env.xdescribe(description, specDefinitions);
},
it: function(desc, func) {
return env.it(desc, func);
fdescribe: function(description, specDefinitions) {
return env.fdescribe(description, specDefinitions);
},
xit: function(desc, func) {
return env.xit(desc, func);
it: function() {
return env.it.apply(env, arguments);
},
beforeEach: function(beforeEachFunction) {
return env.beforeEach(beforeEachFunction);
xit: function() {
return env.xit.apply(env, arguments);
},
afterEach: function(afterEachFunction) {
return env.afterEach(afterEachFunction);
fit: function() {
return env.fit.apply(env, arguments);
},
beforeEach: function() {
return env.beforeEach.apply(env, arguments);
},
afterEach: function() {
return env.afterEach.apply(env, arguments);
},
beforeAll: function() {
return env.beforeAll.apply(env, arguments);
},
afterAll: function() {
return env.afterAll.apply(env, arguments);
},
expect: function(actual) {
@@ -29,7 +45,11 @@ getJasmineRequireObj().interface = function(jasmine, env) {
},
pending: function() {
return env.pending();
return env.pending.apply(env, arguments);
},
fail: function() {
return env.fail.apply(env, arguments);
},
spyOn: function(obj, methodName) {

View File

@@ -33,12 +33,27 @@ getJasmineRequireObj().util = function() {
util.arrayContains = function(array, search) {
var i = array.length;
while (i--) {
if (array[i] == search) {
if (array[i] === search) {
return true;
}
}
return false;
};
util.clone = function(obj) {
if (Object.prototype.toString.apply(obj) === '[object Array]') {
return obj.slice();
}
var cloned = {};
for (var prop in obj) {
if (obj.hasOwnProperty(prop)) {
cloned[prop] = obj[prop];
}
}
return cloned;
};
return util;
};

View File

@@ -11,13 +11,15 @@ jasmineRequire.HtmlReporter = function(j$) {
createElement = options.createElement,
createTextNode = options.createTextNode,
onRaiseExceptionsClick = options.onRaiseExceptionsClick || function() {},
addToExistingQueryString = options.addToExistingQueryString || defaultQueryString,
timer = options.timer || noopTimer,
results = [],
specsExecuted = 0,
failureCount = 0,
pendingSpecCount = 0,
htmlReporterMain,
symbols;
symbols,
failedSuites = [];
this.initialize = function() {
clearPrior();
@@ -54,6 +56,10 @@ jasmineRequire.HtmlReporter = function(j$) {
};
this.suiteDone = function(result) {
if (result.status == 'failed') {
failedSuites.push(result);
}
if (currentParent == topResults) {
return;
}
@@ -67,7 +73,7 @@ jasmineRequire.HtmlReporter = function(j$) {
var failures = [];
this.specDone = function(result) {
if(noExpectations(result) && console && console.error) {
if(noExpectations(result) && typeof console !== 'undefined' && typeof console.error !== 'undefined') {
console.error('Spec \'' + result.fullName + '\' has no expectations.');
}
@@ -149,6 +155,15 @@ jasmineRequire.HtmlReporter = function(j$) {
alert.appendChild(createDom('span', {className: statusBarClassName}, statusBarMessage));
for(i = 0; i < failedSuites.length; i++) {
var failedSuite = failedSuites[i];
for(var j = 0; j < failedSuite.failedExpectations.length; j++) {
var errorBarMessage = 'AfterAll ' + failedSuite.failedExpectations[j].message;
var errorBarClassName = 'bar errored';
alert.appendChild(createDom('span', {className: errorBarClassName}, errorBarMessage));
}
}
var results = find('.results');
results.appendChild(summary);
@@ -177,6 +192,9 @@ jasmineRequire.HtmlReporter = function(j$) {
if(noExpectations(resultNode.result)) {
specDescription = 'SPEC HAS NO EXPECTATIONS ' + specDescription;
}
if(resultNode.result.status === 'pending' && resultNode.result.pendingReason !== '') {
specDescription = specDescription + ' PENDING WITH MESSAGE: ' + resultNode.result.pendingReason;
}
specListNode.appendChild(
createDom('li', {
className: resultNode.result.status,
@@ -224,7 +242,7 @@ jasmineRequire.HtmlReporter = function(j$) {
function clearPrior() {
// return the reporter
var oldReporter = find('');
if(oldReporter) {
getContainer().removeChild(oldReporter);
}
@@ -263,7 +281,11 @@ jasmineRequire.HtmlReporter = function(j$) {
}
function specHref(result) {
return '?spec=' + encodeURIComponent(result.fullName);
return addToExistingQueryString('spec', result.fullName);
}
function defaultQueryString(key, value) {
return '?' + key + '=' + value;
}
function setMenuModeTo(mode) {

Some files were not shown because too many files have changed in this diff Show More