jazz 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (181) hide show
  1. data/LICENSE +20 -0
  2. data/README.rdoc +129 -0
  3. data/bin/jazz +230 -0
  4. data/doc/jasmine/files.html +460 -0
  5. data/doc/jasmine/index.html +322 -0
  6. data/doc/jasmine/symbols/_global_.html +1083 -0
  7. data/doc/jasmine/symbols/jasmine.Block.html +417 -0
  8. data/doc/jasmine/symbols/jasmine.Clock.html +678 -0
  9. data/doc/jasmine/symbols/jasmine.Env.html +1135 -0
  10. data/doc/jasmine/symbols/jasmine.EnvjsReporter.html +328 -0
  11. data/doc/jasmine/symbols/jasmine.JsApiReporter.html +822 -0
  12. data/doc/jasmine/symbols/jasmine.Matchers.html +1106 -0
  13. data/doc/jasmine/symbols/jasmine.MultiReporter.html +394 -0
  14. data/doc/jasmine/symbols/jasmine.NestedResults.html +710 -0
  15. data/doc/jasmine/symbols/jasmine.Reporter.html +574 -0
  16. data/doc/jasmine/symbols/jasmine.Runner.html +710 -0
  17. data/doc/jasmine/symbols/jasmine.Spec.html +1372 -0
  18. data/doc/jasmine/symbols/jasmine.Spy.html +855 -0
  19. data/doc/jasmine/symbols/jasmine.Suite.html +705 -0
  20. data/doc/jasmine/symbols/jasmine.XMLReporter.html +328 -0
  21. data/doc/jasmine/symbols/jasmine.html +1359 -0
  22. data/doc/jasmine/symbols/jasmine.util.html +535 -0
  23. data/doc/jasmine/symbols/src/lib_EnvjsReporter.js.html +149 -0
  24. data/doc/jasmine/symbols/src/lib_TrivialReporter.js.html +127 -0
  25. data/doc/jasmine/symbols/src/lib_XMLReporter.js.html +210 -0
  26. data/doc/jasmine/symbols/src/src_Block.js.html +35 -0
  27. data/doc/jasmine/symbols/src/src_Env.js.html +233 -0
  28. data/doc/jasmine/symbols/src/src_JsApiReporter.js.html +110 -0
  29. data/doc/jasmine/symbols/src/src_Matchers.js.html +399 -0
  30. data/doc/jasmine/symbols/src/src_MultiReporter.js.html +36 -0
  31. data/doc/jasmine/symbols/src/src_NestedResults.js.html +88 -0
  32. data/doc/jasmine/symbols/src/src_PrettyPrinter.js.html +128 -0
  33. data/doc/jasmine/symbols/src/src_Queue.js.html +119 -0
  34. data/doc/jasmine/symbols/src/src_Reporter.js.html +35 -0
  35. data/doc/jasmine/symbols/src/src_Reporters.js.html +51 -0
  36. data/doc/jasmine/symbols/src/src_Runner.js.html +75 -0
  37. data/doc/jasmine/symbols/src/src_Spec.js.html +228 -0
  38. data/doc/jasmine/symbols/src/src_Suite.js.html +77 -0
  39. data/doc/jasmine/symbols/src/src_WaitsBlock.js.html +21 -0
  40. data/doc/jasmine/symbols/src/src_WaitsForBlock.js.html +45 -0
  41. data/doc/jasmine/symbols/src/src_base.js.html +566 -0
  42. data/doc/jasmine/symbols/src/src_mock-timeout.js.html +185 -0
  43. data/doc/jasmine/symbols/src/src_util.js.html +75 -0
  44. data/lib/jazz.rb +0 -0
  45. data/lib/jazz/intro.js +46 -0
  46. data/lib/jazz/jasmine/EnvjsReporter.js +141 -0
  47. data/lib/jazz/jasmine/TrivialReporter.js +155 -0
  48. data/lib/jazz/jasmine/XMLReporter.js +241 -0
  49. data/lib/jazz/jasmine/consolex.js +28 -0
  50. data/lib/jazz/jasmine/jasmine-0.10.0.js +2526 -0
  51. data/lib/jazz/jasmine/jasmine.js +2526 -0
  52. data/lib/jazz/jasmine/json2.js +478 -0
  53. data/lib/jazz/options.rb +26 -0
  54. data/lib/jazz/outro.js +3 -0
  55. data/lib/jazz/qintro.js +113 -0
  56. data/lib/jazz/qoutro.js +3 -0
  57. data/lib/jazz/qunit/qunit.css +17 -0
  58. data/lib/jazz/qunit/qunit.js +1027 -0
  59. data/spec/example/hello_world_spec.js +29 -0
  60. data/spec/example/nested/HelloWorldSpec.js +13 -0
  61. data/spec/example/nested/SpecHelper.js +1 -0
  62. data/spec/example/plain_spec.js +8 -0
  63. data/spec/example/spec_helper.js +1 -0
  64. data/spec/spec_helper.js +18 -0
  65. data/spec/spec_runner.js +143 -0
  66. data/test/jazz_test.rb +7 -0
  67. data/test/test_helper.rb +10 -0
  68. data/vendor/jasmine/MIT.LICENSE +20 -0
  69. data/vendor/jasmine/README.markdown +479 -0
  70. data/vendor/jasmine/Rakefile +155 -0
  71. data/vendor/jasmine/Wakefile +68 -0
  72. data/vendor/jasmine/contrib/ruby/jasmine_runner.rb +334 -0
  73. data/vendor/jasmine/contrib/ruby/jasmine_spec_builder.rb +153 -0
  74. data/vendor/jasmine/contrib/ruby/run.html +47 -0
  75. data/vendor/jasmine/contrib/ruby/spec/jasmine_runner_spec.rb +71 -0
  76. data/vendor/jasmine/doc/files.html +460 -0
  77. data/vendor/jasmine/doc/index.html +322 -0
  78. data/vendor/jasmine/doc/symbols/_global_.html +1083 -0
  79. data/vendor/jasmine/doc/symbols/jasmine.Block.html +417 -0
  80. data/vendor/jasmine/doc/symbols/jasmine.Clock.html +678 -0
  81. data/vendor/jasmine/doc/symbols/jasmine.Env.html +1135 -0
  82. data/vendor/jasmine/doc/symbols/jasmine.EnvjsReporter.html +328 -0
  83. data/vendor/jasmine/doc/symbols/jasmine.JsApiReporter.html +822 -0
  84. data/vendor/jasmine/doc/symbols/jasmine.Matchers.html +1106 -0
  85. data/vendor/jasmine/doc/symbols/jasmine.MultiReporter.html +394 -0
  86. data/vendor/jasmine/doc/symbols/jasmine.NestedResults.html +710 -0
  87. data/vendor/jasmine/doc/symbols/jasmine.Reporter.html +574 -0
  88. data/vendor/jasmine/doc/symbols/jasmine.Runner.html +710 -0
  89. data/vendor/jasmine/doc/symbols/jasmine.Spec.html +1372 -0
  90. data/vendor/jasmine/doc/symbols/jasmine.Spy.html +855 -0
  91. data/vendor/jasmine/doc/symbols/jasmine.Suite.html +705 -0
  92. data/vendor/jasmine/doc/symbols/jasmine.XMLReporter.html +328 -0
  93. data/vendor/jasmine/doc/symbols/jasmine.html +1359 -0
  94. data/vendor/jasmine/doc/symbols/jasmine.util.html +535 -0
  95. data/vendor/jasmine/doc/symbols/src/lib_EnvjsReporter.js.html +149 -0
  96. data/vendor/jasmine/doc/symbols/src/lib_TrivialReporter.js.html +127 -0
  97. data/vendor/jasmine/doc/symbols/src/lib_XMLReporter.js.html +210 -0
  98. data/vendor/jasmine/doc/symbols/src/src_Block.js.html +35 -0
  99. data/vendor/jasmine/doc/symbols/src/src_Env.js.html +233 -0
  100. data/vendor/jasmine/doc/symbols/src/src_JsApiReporter.js.html +110 -0
  101. data/vendor/jasmine/doc/symbols/src/src_Matchers.js.html +399 -0
  102. data/vendor/jasmine/doc/symbols/src/src_MultiReporter.js.html +36 -0
  103. data/vendor/jasmine/doc/symbols/src/src_NestedResults.js.html +88 -0
  104. data/vendor/jasmine/doc/symbols/src/src_PrettyPrinter.js.html +128 -0
  105. data/vendor/jasmine/doc/symbols/src/src_Queue.js.html +119 -0
  106. data/vendor/jasmine/doc/symbols/src/src_Reporter.js.html +35 -0
  107. data/vendor/jasmine/doc/symbols/src/src_Reporters.js.html +51 -0
  108. data/vendor/jasmine/doc/symbols/src/src_Runner.js.html +75 -0
  109. data/vendor/jasmine/doc/symbols/src/src_Spec.js.html +228 -0
  110. data/vendor/jasmine/doc/symbols/src/src_Suite.js.html +77 -0
  111. data/vendor/jasmine/doc/symbols/src/src_WaitsBlock.js.html +21 -0
  112. data/vendor/jasmine/doc/symbols/src/src_WaitsForBlock.js.html +45 -0
  113. data/vendor/jasmine/doc/symbols/src/src_base.js.html +566 -0
  114. data/vendor/jasmine/doc/symbols/src/src_mock-timeout.js.html +185 -0
  115. data/vendor/jasmine/doc/symbols/src/src_util.js.html +75 -0
  116. data/vendor/jasmine/examples/html/example_suite.html +27 -0
  117. data/vendor/jasmine/examples/html/spec/example_suite.js +11 -0
  118. data/vendor/jasmine/examples/ruby/Rakefile +33 -0
  119. data/vendor/jasmine/examples/ruby/spec/example/example_spec.js +11 -0
  120. data/vendor/jasmine/examples/ruby/spec/jasmine_helper.rb +41 -0
  121. data/vendor/jasmine/examples/ruby/spec/jasmine_spec.rb +31 -0
  122. data/vendor/jasmine/examples/ruby/spec/saucelabs.yml +24 -0
  123. data/vendor/jasmine/geminstaller.yml +23 -0
  124. data/vendor/jasmine/images/fail-16.png +0 -0
  125. data/vendor/jasmine/images/fail.png +0 -0
  126. data/vendor/jasmine/images/go-16.png +0 -0
  127. data/vendor/jasmine/images/go.png +0 -0
  128. data/vendor/jasmine/images/pending-16.png +0 -0
  129. data/vendor/jasmine/images/pending.png +0 -0
  130. data/vendor/jasmine/images/question-bk.png +0 -0
  131. data/vendor/jasmine/images/questionbk-16.png +0 -0
  132. data/vendor/jasmine/images/spinner.gif +0 -0
  133. data/vendor/jasmine/lib/EnvjsReporter.js +141 -0
  134. data/vendor/jasmine/lib/TrivialReporter.js +155 -0
  135. data/vendor/jasmine/lib/XMLReporter.js +241 -0
  136. data/vendor/jasmine/lib/consolex.js +28 -0
  137. data/vendor/jasmine/lib/jasmine-0.10.0.js +2526 -0
  138. data/vendor/jasmine/lib/jasmine.css +86 -0
  139. data/vendor/jasmine/lib/json2.js +478 -0
  140. data/vendor/jasmine/spec/jasmine_helper.rb +44 -0
  141. data/vendor/jasmine/spec/jasmine_spec.rb +31 -0
  142. data/vendor/jasmine/spec/runner.html +43 -0
  143. data/vendor/jasmine/spec/runner.js +78 -0
  144. data/vendor/jasmine/spec/saucelabs.yml +24 -0
  145. data/vendor/jasmine/spec/suites/EnvSpec.js +71 -0
  146. data/vendor/jasmine/spec/suites/ExceptionsSpec.js +107 -0
  147. data/vendor/jasmine/spec/suites/JsApiReporterSpec.js +82 -0
  148. data/vendor/jasmine/spec/suites/MatchersSpec.js +589 -0
  149. data/vendor/jasmine/spec/suites/MockClockSpec.js +34 -0
  150. data/vendor/jasmine/spec/suites/MultiReporterSpec.js +30 -0
  151. data/vendor/jasmine/spec/suites/NestedResultsSpec.js +54 -0
  152. data/vendor/jasmine/spec/suites/PrettyPrintSpec.js +93 -0
  153. data/vendor/jasmine/spec/suites/QueueSpec.js +23 -0
  154. data/vendor/jasmine/spec/suites/ReporterSpec.js +60 -0
  155. data/vendor/jasmine/spec/suites/RunnerSpec.js +258 -0
  156. data/vendor/jasmine/spec/suites/SpecRunningSpec.js +1117 -0
  157. data/vendor/jasmine/spec/suites/SpecSpec.js +110 -0
  158. data/vendor/jasmine/spec/suites/SpySpec.js +187 -0
  159. data/vendor/jasmine/spec/suites/SuiteSpec.js +101 -0
  160. data/vendor/jasmine/spec/suites/TrivialReporterSpec.js +140 -0
  161. data/vendor/jasmine/spec/suites/UtilSpec.js +23 -0
  162. data/vendor/jasmine/src/Block.js +34 -0
  163. data/vendor/jasmine/src/Env.js +236 -0
  164. data/vendor/jasmine/src/JsApiReporter.js +103 -0
  165. data/vendor/jasmine/src/Matchers.js +326 -0
  166. data/vendor/jasmine/src/MultiReporter.js +28 -0
  167. data/vendor/jasmine/src/NestedResults.js +99 -0
  168. data/vendor/jasmine/src/PrettyPrinter.js +122 -0
  169. data/vendor/jasmine/src/Queue.js +210 -0
  170. data/vendor/jasmine/src/Reporter.js +27 -0
  171. data/vendor/jasmine/src/Reporters.js +43 -0
  172. data/vendor/jasmine/src/Runner.js +68 -0
  173. data/vendor/jasmine/src/Spec.js +254 -0
  174. data/vendor/jasmine/src/Suite.js +70 -0
  175. data/vendor/jasmine/src/WaitsBlock.js +13 -0
  176. data/vendor/jasmine/src/WaitsForBlock.js +38 -0
  177. data/vendor/jasmine/src/base.js +604 -0
  178. data/vendor/jasmine/src/mock-timeout.js +177 -0
  179. data/vendor/jasmine/src/util.js +67 -0
  180. data/vendor/jasmine/src/version.json +5 -0
  181. metadata +292 -0
@@ -0,0 +1,29 @@
1
+ jasmine.include(jazz_root + "/spec/example/spec_helper.js");
2
+
3
+ (function($){
4
+
5
+ describe("hello_world",function(){
6
+
7
+ describe("contents",function(){
8
+
9
+ var loops = 500000;
10
+
11
+ for(var i = 0; i < 10; i++ ) {
12
+
13
+ it("should contain the text 'Hello, World'",function(){
14
+ expect($("div:contains('Hello, World')").size()).toBeGreaterThan(0);
15
+ for(var j = 0; j<loops; j++);
16
+ });
17
+
18
+ it("should contain the text 'Hello, World'",function(){
19
+ expect($("div:contains('Hello, World')").size()).toBeGreaterThan(0);
20
+ for(var j = 0; j<loops; j++);
21
+ });
22
+
23
+ }
24
+
25
+ });
26
+
27
+ });
28
+
29
+ })(jQuery);
@@ -0,0 +1,13 @@
1
+ jasmine.include(jazz_root + "/spec/example/nested/SpecHelper.js");
2
+
3
+ (function($){
4
+
5
+ describe("hello_world",function(){
6
+
7
+ it("should contain the text 'Hello, World'",function(){
8
+ expect($("div:contains('Hello, World')").size()).toBeGreaterThan(0);
9
+ });
10
+
11
+ });
12
+
13
+ })(jQuery);
@@ -0,0 +1,8 @@
1
+ describe("truthy",function(){
2
+
3
+ it("true should be truthy'",function(){
4
+ expect(!!true).toBe(true);
5
+ });
6
+
7
+ });
8
+
@@ -0,0 +1,18 @@
1
+ if(!this.jasmine){
2
+ document.write("<script type='text/javascript' src='" + jazz_root + "/lib/jazz/jasmine/jasmine.js'></script>");
3
+ document.write("<script type='text/javascript' src='" + jazz_root + "/lib/jazz/jasmine/TrivialReporter.js'></script>");
4
+ if(this.Envjs){
5
+ document.write("<script type='text/javascript' src='" + jazz_root + "/lib/jazz/jasmine/EnvjsReporter.js'></script>");
6
+ }
7
+ (function(){
8
+ var headID = document.getElementsByTagName("head")[0];
9
+ var cssNode = document.createElement('link');
10
+ cssNode.type = 'text/css';
11
+ cssNode.rel = 'stylesheet';
12
+ cssNode.href = jazz_root + "/vendor/jasmine/lib/jasmine.css";
13
+ cssNode.media = 'screen';
14
+ headID.appendChild(cssNode);
15
+ })();
16
+ };
17
+ document.write("<script type='text/javascript' src='" + jazz_root + "/vendor/jquery/dist/jquery.js'></script>");
18
+ document.write("<script type='text/javascript' src='" + jazz_root + "/spec/spec_runner.js'></script>");
@@ -0,0 +1,143 @@
1
+ (function($){
2
+
3
+ var print = ( this.Envjs && this.print ) || ( this.console && this.console.debug ) || function(){};
4
+
5
+ var construct_path = function( source, result ) {
6
+ var levels = 0;
7
+ while( source.slice( source.length - 3 ) == "/.." ) {
8
+ levels++;
9
+ source = source.slice( 0, source.length - 3 );
10
+ }
11
+ var prefixes = [];
12
+ while(levels-->0) {
13
+ var slash = source.lastIndexOf("/");
14
+ if (slash<0) {
15
+ return "";
16
+ }
17
+ prefixes.unshift(source.slice(slash+1));
18
+ source = source.slice(0,slash);
19
+ }
20
+ return result+prefixes.join("/");
21
+ };
22
+
23
+ var spec_filename = function() {
24
+ var window = this;
25
+ path = window.location.toString();
26
+ var q = path.lastIndexOf("?");
27
+ if ( q >= 0 ) {
28
+ path = path.slice(0,q);
29
+ // print(path);
30
+ }
31
+ var slash = path.lastIndexOf("/");
32
+ if ( slash < 0 ) {
33
+ return path;
34
+ }
35
+ path = path.slice(slash+1);
36
+ var dot = path.lastIndexOf(".");
37
+ if ( dot > 0 ) {
38
+ path = path.slice(0,dot);
39
+ }
40
+ return path;
41
+ };
42
+
43
+ var find_specs = function() {
44
+ var path = window.location.toString();
45
+ var slash = path.lastIndexOf("/");
46
+ if ( slash < 0 ) {
47
+ return "";
48
+ }
49
+ var filename = path.slice(slash+1);
50
+ path = path.slice(0,slash);
51
+ path = construct_path( path + "/" + jazz_root, jazz_root + "/spec/" );
52
+ return [ path, spec_filename() ];
53
+ };
54
+
55
+ var load_file = function(filename) {
56
+ var contents = undefined;
57
+ $.ajax({ url: filename,
58
+ dataType: "text",
59
+ async: false,
60
+ error: function( xhr ) {
61
+ if(xhr.status != 404) {
62
+ throw "error on load_file xhr for " + filename + ": " + xhr.status;
63
+ }
64
+ },
65
+ success: function(data) { contents = data; } });
66
+ if ( contents ) {
67
+ return contents;
68
+ }
69
+
70
+ };
71
+
72
+ var load_first = function( fn, endings ) {
73
+ for (var i=0; i<endings.length; i++) {
74
+ var filename = fn + endings[i] + ".js";
75
+ if ( window.Envjs ) {
76
+ var root = window.location.toString();
77
+ var slash = root.lastIndexOf("/");
78
+ root = root.slice(0,slash+1);
79
+ root = root.replace(/^file:\/\//,"");
80
+ window.load(root + filename);
81
+ return;
82
+ } else {
83
+ var contents = load_file( filename );
84
+ if ( contents ) {
85
+ try {
86
+ eval(contents);
87
+ } catch(e) {
88
+ print("could not eval spec: ",e);
89
+ }
90
+ return;
91
+ }
92
+ }
93
+ }
94
+ };
95
+
96
+ var load_specs = function(specs) {
97
+ var path = specs[0], filename = specs[1];
98
+ var endings = [ "_spec", "Spec" ];
99
+ // Guess ending ... FIX: allow spec'ing of default order ...
100
+ if (filename.lastIndexOf("_") >= 0) {
101
+ endings = [ "_spec", "Spec" ];
102
+ } else if (filename.match(/[A-Z]/)) {
103
+ endings = [ "Spec", "_spec" ];
104
+ }
105
+ load_first( path+"/"+filename, endings );
106
+ };
107
+
108
+ var run_specs = function(){
109
+ if(!this.jazz_root) {
110
+ return;
111
+ }
112
+ var specs = find_specs();
113
+ if (specs) {
114
+ load_specs(specs);
115
+ }
116
+ };
117
+
118
+ run_specs();
119
+
120
+ if(this.jasmine && !this.Envjs) {
121
+ var embedded = window.location != "about:blank";
122
+
123
+ var jasmineEnv = jasmine.getEnv();
124
+ jasmineEnv.updateInterval = 1000;
125
+
126
+ if(embedded) {
127
+ var trivialReporter = new jasmine.TrivialReporter();
128
+ jasmineEnv.addReporter(trivialReporter);
129
+ jasmineEnv.specFilter = function(spec) {
130
+ return trivialReporter.specFilter(spec);
131
+ };
132
+ }
133
+
134
+ if(window.Envjs && jasmine.EnvjsReporter){
135
+ jasmineEnv.addReporter(new jasmine.EnvjsReporter());
136
+ }
137
+
138
+ $(function() {
139
+ jasmineEnv.execute();
140
+ });
141
+ }
142
+
143
+ })(jQuery);
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class AutojazTest < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'jazz'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Pivotal Labs
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,479 @@
1
+ Jasmine
2
+ =======
3
+ **YET ANOTHER JavaScript testing framework**
4
+
5
+ Quick Start
6
+ ----------
7
+
8
+ ### Ruby Suite Running
9
+
10
+ sudo gem sources -a http://gems.github.com
11
+ sudo gem install geminstaller
12
+ git clone git://github.com/pivotal/jasmine.git
13
+ cd jasmine
14
+ sudo geminstaller
15
+ cd examples/ruby
16
+ rake jasmine_server
17
+
18
+ open `http://localhost:8888/` in your favorite browser.
19
+
20
+ ### HTML Suite Running
21
+
22
+ git clone git://github.com/pivotal/jasmine.git
23
+
24
+ open `examples/test/html/example_suite.html` in your favorite browser.
25
+
26
+ ### Automatic Suite Running (w/ Selenium)
27
+
28
+ sudo gem sources -a http://gems.github.com
29
+ sudo gem install geminstaller
30
+ git clone git://github.com/pivotal/jasmine.git
31
+ cd jasmine
32
+ sudo geminstaller
33
+ cd examples/ruby
34
+ rake test:ci
35
+
36
+ Releases
37
+ ----------
38
+ 0.10.0 [[download]](http://github.com/pivotal/jasmine/zipball/master)
39
+ `git clone git://github.com/pivotal/jasmine.git`
40
+
41
+ 0.9.0 [[download]](http://github.com/pivotal/jasmine/zipball/0.9.0)
42
+
43
+ 0.8.0 [[download]](http://github.com/pivotal/jasmine/zipball/0.8.0)
44
+
45
+ ### Which Release Should I Use?
46
+
47
+ Please use the latest version unless you have a good reason not to. Some of this documentation may not be applicable to older versions.
48
+
49
+ Pull Requests
50
+ ----------
51
+ We welcome your contributions! Jasmine is currently maintained by Davis Frank ([infews](http://github.com/infews)), Rajan Agaskar ([ragaskar](http://github.com/ragaskar)), and Christian Williams ([Xian](http://github.com/Xian)). You can help us by removing all other recipients from your pull request.
52
+
53
+
54
+ Why Another Frickin' JS TDD/BDD Framework?
55
+ -----------
56
+
57
+ There are some situations when you want to test-drive JavaScript, but you don't want to be bothered with or even have an explicit document. You have no DOM to work with and thus lack HTML elements on which to hang event handlers. You may need to make asynchronous calls (say, to an AJAX API) and cannot mock/stub them.
58
+
59
+ But you still need to write tests.
60
+
61
+ What's an Agile Engineer to do?
62
+
63
+ Enter Jasmine
64
+ ------------
65
+
66
+ Jasmine is yet another JavaScript testing framework. It's *heavily* influenced by JSSpec, ScrewUnit & [JSpec](http://github.com/visionmedia/jspec/tree/master), which are all influenced by RSpec. But each of those was lacking in some way: JSSpec & ScrewUnit require a DOM. JSpec's DOM-less assumption was a great start, but it needed asynchronous support.
67
+
68
+ So we started over. And TDD'd a whole new framework. Enjoy.
69
+
70
+ How To
71
+ ------
72
+
73
+ There is a nice example of how to use Jasmine in the /example directory. But here's more information.
74
+
75
+ Exciting changes are afoot and many syntax changes have been made to make Jasmine more usable. Please read the examples below for updates.
76
+
77
+ ### Specs
78
+
79
+ Each spec is, naturally, a JavaScript function. You tell Jasmine about this spec with a call to `it()` with a string and the function. The string is a description that will be helpful to you when reading a report.
80
+
81
+ it('should be a test', function () {
82
+ var foo = 0
83
+ foo++;
84
+ });
85
+
86
+ ### Expectations
87
+
88
+ Within your spec you will want/need to make expectations. These are made with the `expect()` funciton and expectation matchers. like this:
89
+
90
+ it('should be a test', function () {
91
+ var foo = 0
92
+ foo++;
93
+
94
+ expect(foo).toEqual(1);
95
+ });
96
+
97
+ Results of the expectations are logged for later for reporting.
98
+
99
+ #### Expectation Matchers
100
+
101
+ Jasmine has several built-in matchers. Here are a few:
102
+
103
+ `toEqual()` compares objects or primitives and returns true if they are equal
104
+
105
+ `toNotEqual()` compares objects or primitives and returns true if they are not equal
106
+
107
+ `toMatch()` takes a regex or a string and returns true if it matches
108
+
109
+ `toNotMatch()` takes a regex or a string and returns true if it does not match
110
+
111
+ `toBeDefined()` returns true if the object or primitive is not `undefined`
112
+
113
+ `toBeNull()` returns true if the object or primitive is not `null`
114
+
115
+ `toBeTruthy()` returns true if the object or primitive evaluates to true
116
+
117
+ `toBeFalsy()` returns true if the object or primitive evaluates to false
118
+
119
+ `toContain()` returns true if an array or string contains the passed variable.
120
+
121
+ `toNotContain()` returns true if an array or string does not contain the passed variable.
122
+
123
+ #### Writing New Matchers
124
+
125
+ A Matcher has a method name, takes an expected value as it's only parameter, has access to the actual value in this, and then makes a call to this.report with true/false with a failure message. Here's the definition of `toEqual()`:
126
+
127
+ jasmine.Matchers.prototype.toEqual = function (expected) {
128
+ return this.report((this.actual === expected),
129
+ 'Expected ' + expected + ' but got ' + this.actual + '.');
130
+ };
131
+
132
+ Feel free to define your own matcher as needed in your code. If you'd like to add Matchers to Jasmine, please write tests.
133
+
134
+ ### Asynchronous Specs
135
+
136
+ You may be thinking, "That's all well and good, but you mentioned something about asynchronous tests."
137
+
138
+ Well, say you need to make a call that is asynchronous - an AJAX API, or some other JavaScript library. That is, the call returns immediately, yet you want to make expectations 'at some point in the future' after some magic happens in the background.
139
+
140
+ Jasmine allows you to do this with `runs()` and `waits()` blocks.
141
+
142
+ `runs()` blocks by themselves simply run as if they were called directly. The following snippets of code should provide similar results:
143
+
144
+ it('should be a test', function () {
145
+ var foo = 0
146
+ foo++;
147
+
148
+ expect(foo).toEqual(1);
149
+ });
150
+
151
+ and
152
+
153
+ it('should be a test', function () {
154
+ runs( function () {
155
+ var foo = 0
156
+ foo++;
157
+
158
+ expect(foo).toEqual(1);
159
+ });
160
+ });
161
+
162
+ multiple `runs()` blocks in a spec will run serially. For example,
163
+
164
+ it('should be a test', function () {
165
+ runs( function () {
166
+ var foo = 0
167
+ foo++;
168
+
169
+ expect(foo).toEqual(1);
170
+ });
171
+ runs( function () {
172
+ var bar = 0
173
+ bar++;
174
+
175
+ expect(bar).toEqual(1);
176
+ });
177
+ });
178
+
179
+ `runs()` blocks share functional scope -- `this` properties will be common to all blocks, but declared `var`'s will not!
180
+
181
+ it('should be a test', function () {
182
+ runs( function () {
183
+ this.foo = 0
184
+ this.foo++;
185
+ var bar = 0;
186
+ bar++;
187
+
188
+ expect(this.foo).toEqual(1);
189
+ expect(bar).toEqual(1);
190
+ });
191
+ runs( function () {
192
+ this.foo++;
193
+ var bar = 0
194
+ bar++;
195
+
196
+ expect(foo).toEqual(2);
197
+ expect(bar).toEqual(1);
198
+ });
199
+ });
200
+
201
+ `runs()` blocks exist so you can test asynchronous processes. The function `waits()` works with `runs()` to provide a naive
202
+ timeout before the next block is run. You supply a time to wait before the next `runs()` function is executed. For example:
203
+
204
+ it('should be a test', function () {
205
+ runs(function () {
206
+ this.foo = 0;
207
+ var that = this;
208
+ setTimeout(function () {
209
+ that.foo++;
210
+ }, 250);
211
+ });
212
+
213
+ runs(function () {
214
+ this.expects(this.foo).toEqual(0);
215
+ });
216
+
217
+ waits(500);
218
+
219
+ runs(function () {
220
+ this.expects(this.foo).toEqual(1);
221
+ });
222
+ });
223
+
224
+ What's happening here?
225
+
226
+ * The first call to `runs()` sets call for 1/4 of a second in the future that increments `this.foo`.
227
+ * The second `runs()` is executed immediately and then verifies that `this.foo` was indeed initialized to zero in the previous `runs()`.
228
+ * Then we wait for half a second.
229
+ * Then the last call to `runs()` expects that `this.foo` was incremented by the `setTimeout`.
230
+
231
+
232
+ ### Suites
233
+
234
+ Specs are grouped in Suites. Suites are defined using the global `describe()` function:
235
+
236
+ describe('One suite', function () {
237
+ it('has a test', function () {
238
+ ...
239
+ });
240
+
241
+ it('has another test', function () {
242
+ ...
243
+ });
244
+ });
245
+
246
+ The Suite name is so that reporting is more descriptive.
247
+
248
+ Suites are executed in the order in which `describe()` calls are made, usually in the order in which their script files are included. Additionally, specs within a suite share a functional scope. So you may declare variables inside a describe block and they are accessible from within your specs. For example:
249
+
250
+ describe('A suite with some variables', function () {
251
+ var bar = 0
252
+
253
+ it('has a test', function () {
254
+ bar++;
255
+ expect(bar).toEqual(1);
256
+ });
257
+
258
+ it('has another test', function () {
259
+ bar++;
260
+ expect(bar).toEqual(2);
261
+ });
262
+ });
263
+
264
+ #### beforeEach
265
+
266
+ A suite can have a beforeEach declaration. It takes a function that is run before each spec. For example:
267
+
268
+ describe('some suite', function () {
269
+
270
+ var suiteWideFoo;
271
+
272
+ beforeEach(function () {
273
+ suiteWideFoo = 1;
274
+ });
275
+
276
+ it('should equal bar', function () {
277
+ expect(suiteWideFoo).toEqual(1);
278
+ });
279
+ });
280
+
281
+ A runner can also have beforeEach declarations. Runner beforeEach functions are executed before every spec in all suites, and execute BEFORE suite beforeEach functions. For example:
282
+
283
+ var runnerWideFoo = [];
284
+
285
+ beforeEach(function () {
286
+ runnerWideFoo.push('runner');
287
+ });
288
+
289
+ describe('some suite', function () {
290
+
291
+ beforeEach(function () {
292
+ runnerWideFoo.push('suite');
293
+ });
294
+
295
+ it('should equal bar', function () {
296
+ expect(runnerWideFoo).toEqual(['runner', 'suite']);
297
+ });
298
+ });
299
+
300
+ #### afterEach
301
+
302
+ Similarly, there is an afterEach declaration. It takes a function that is run after each spec. For example:
303
+
304
+ describe('some suite', function () {
305
+
306
+ var suiteWideFoo;
307
+ afterEach(function () {
308
+ suiteWideFoo = 0;
309
+ });
310
+
311
+ it('should equal 1', function () {
312
+ expect(suiteWideFoo).toEqual(1);
313
+ });
314
+
315
+ it('should equal 0 after', function () {
316
+ expect(suiteWideFoo).toEqual(0);
317
+ };
318
+ });
319
+
320
+ A runner can also have an afterEach declarations. Runner afterEach functions are executed after every spec in all suites, and execute AFTER suite afterEach functions. For example:
321
+
322
+ var runnerWideFoo = [];
323
+
324
+ afterEach(function () {
325
+ runnerWideFoo.push('runner');
326
+ });
327
+
328
+ describe('some suite', function () {
329
+
330
+ afterEach(function () {
331
+ runnerWideFoo.push('suite');
332
+ });
333
+
334
+ it('should be empty', function () {
335
+ expect(runnerWideFoo).toEqual([]);
336
+ });
337
+
338
+ it('should be populated after', function () {
339
+ expect(runnerWideFoo).toEqual(['suite', 'runner']);
340
+ };
341
+ });
342
+
343
+ ### Nested Describes
344
+ Jasmine supports nested describes. An example:
345
+
346
+ describe('some suite', function () {
347
+
348
+ var suiteWideFoo;
349
+
350
+ beforeEach(function () {
351
+ suiteWideFoo = 0;
352
+ });
353
+
354
+ describe('some nested suite', function() {
355
+ var nestedSuiteBar;
356
+ beforeEach(function() {
357
+ nestedSuiteBar=1;
358
+ });
359
+
360
+ it('nested expectation', function () {
361
+ expect(suiteWideFoo).toEqual(0);
362
+ expect(nestedSuiteBar).toEqual(1);
363
+ });
364
+
365
+ });
366
+
367
+ it('top-level describe', function () {
368
+ expect(suiteWideFoo).toEqual(0);
369
+ expect(nestedSuiteBar).toEqual(undefined);
370
+ });
371
+ });
372
+
373
+ ### Spies
374
+
375
+ Jasmine integrates 'spies' that permit many spying, mocking, and faking behaviors.
376
+
377
+ Here are a few examples:
378
+
379
+ var Klass = function () {
380
+ };
381
+
382
+ var Klass.prototype.method = function (arg) {
383
+ return arg;
384
+ };
385
+
386
+ var Klass.prototype.methodWithCallback = function (callback) {
387
+ return callback('foo');
388
+ };
389
+
390
+ ...
391
+
392
+ it('should spy on Klass#method') {
393
+ spyOn(Klass, 'method');
394
+ Klass.method('foo argument');
395
+
396
+ expect(Klass.method).wasCalledWith('foo argument');
397
+ });
398
+
399
+ it('should spy on Klass#methodWithCallback') {
400
+ var callback = Jasmine.createSpy();
401
+ Klass.method(callback);
402
+
403
+ expect(callback).wasCalledWith('foo');
404
+ });
405
+
406
+
407
+ Spies can be very useful for testing AJAX or other asynchronous behaviors that take callbacks by faking the method firing an async call.
408
+
409
+ var Klass = function () {
410
+ };
411
+
412
+ var Klass.prototype.asyncMethod = function (callback) {
413
+ someAsyncCall(callback);
414
+ };
415
+
416
+ ...
417
+
418
+ it('should test async call') {
419
+ spyOn(Klass, 'asyncMethod');
420
+ var callback = Jasmine.createSpy();
421
+
422
+ Klass.asyncMethod(callback);
423
+ expect(callback).wasNotCalled();
424
+
425
+ var someResponseData = 'foo';
426
+ Klass.asyncMethod.mostRecentCall.args[0](someResponseData);
427
+ expect(callback).wasCalledWith(someResponseData);
428
+
429
+ });
430
+
431
+ There are spy-specfic matchers that are very handy.
432
+
433
+ `wasCalled()` returns true if the object is a spy and was called
434
+
435
+ `wasCalledWith(arguments)` returns true if the object is a spy and was called with the passed arguments
436
+
437
+ `wasNotCalled()` returns true if the object is a spy and was not called
438
+
439
+ `wasNotCalledWith(arguments)` returns true if the object is a spy and was not called with the passed arguments
440
+
441
+ Spies can be trained to respond in a variety of ways when invoked:
442
+
443
+ `andCallThrough()`: spies on AND calls the original function spied on
444
+
445
+ `andReturn(arguments)`: returns passed arguments when spy is called
446
+
447
+ `andThrow(exception)`: throws passed exception when spy is called
448
+
449
+ `andCallFake(function)`: calls passed function when spy is called
450
+
451
+ Spies have some useful properties:
452
+
453
+ `callCount`: returns number of times spy was called
454
+
455
+ `mostRecentCall.args`: returns argument array from last call to spy.
456
+
457
+ `argsForCall[i]` returns arguments array for call `i` to spy.
458
+
459
+ Spies are automatically removed after each spec. They may be set in the beforeEach function.
460
+
461
+ ### Disabling Tests & Suites
462
+
463
+ Specs may be disabled by calling `xit()` instead of `it()`. Suites may be disabled by calling `xdescribe()` instead of `describe()`. A simple find/replace in your editor of choice will allow you to run a subset of your specs.
464
+
465
+ ## Support
466
+ We now have a Google Group for support & discussion.
467
+
468
+ * Homepage: [http://groups.google.com/group/jasmine-js](http://groups.google.com/group/jasmine-js)
469
+ * Group email: [jasmine-js@googlegroups.com](jasmine-js@googlegroups.com)
470
+
471
+ ## Maintainers
472
+
473
+ * [Davis W. Frank](mailto:dwfrank@pivotallabs.com), Pivotal Labs
474
+ * [Rajan Agaskar](mailto:rajan@pivotallabs.com), Pivotal Labs
475
+
476
+ ## Acknowledgments
477
+ * A big shout out to the various JavaScript test framework authors, especially TJ for [JSpec](http://github.com/visionmedia/jspec/tree/master) - we played with it a bit before deciding that we really needed to roll our own.
478
+ * Thanks to Pivot [Jessica Miller](http://www.jessicamillerworks.com/) for our fancy pass/fail/pending icons
479
+ * Huge contributions have been made by [Christian Williams](mailto:xian@pivotallabs.com) (the master "spy" coder), [Erik Hanson](mailto:erik@pivotallabs.com), [Adam Abrons](mailto:adam@pivotallabs.com) and [Carl Jackson](mailto:carl@pivotallabs.com), and many other Pivots.