jazrb 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (184) hide show
  1. data/LICENSE +20 -0
  2. data/README.rdoc +134 -0
  3. data/bin/autojaz +4 -0
  4. data/bin/jazrb +230 -0
  5. data/doc/jasmine/files.html +460 -0
  6. data/doc/jasmine/index.html +322 -0
  7. data/doc/jasmine/symbols/_global_.html +1083 -0
  8. data/doc/jasmine/symbols/jasmine.Block.html +417 -0
  9. data/doc/jasmine/symbols/jasmine.Clock.html +678 -0
  10. data/doc/jasmine/symbols/jasmine.Env.html +1135 -0
  11. data/doc/jasmine/symbols/jasmine.EnvjsReporter.html +328 -0
  12. data/doc/jasmine/symbols/jasmine.JsApiReporter.html +822 -0
  13. data/doc/jasmine/symbols/jasmine.Matchers.html +1106 -0
  14. data/doc/jasmine/symbols/jasmine.MultiReporter.html +394 -0
  15. data/doc/jasmine/symbols/jasmine.NestedResults.html +710 -0
  16. data/doc/jasmine/symbols/jasmine.Reporter.html +574 -0
  17. data/doc/jasmine/symbols/jasmine.Runner.html +710 -0
  18. data/doc/jasmine/symbols/jasmine.Spec.html +1372 -0
  19. data/doc/jasmine/symbols/jasmine.Spy.html +855 -0
  20. data/doc/jasmine/symbols/jasmine.Suite.html +705 -0
  21. data/doc/jasmine/symbols/jasmine.XMLReporter.html +328 -0
  22. data/doc/jasmine/symbols/jasmine.html +1359 -0
  23. data/doc/jasmine/symbols/jasmine.util.html +535 -0
  24. data/doc/jasmine/symbols/src/lib_EnvjsReporter.js.html +149 -0
  25. data/doc/jasmine/symbols/src/lib_TrivialReporter.js.html +127 -0
  26. data/doc/jasmine/symbols/src/lib_XMLReporter.js.html +210 -0
  27. data/doc/jasmine/symbols/src/src_Block.js.html +35 -0
  28. data/doc/jasmine/symbols/src/src_Env.js.html +233 -0
  29. data/doc/jasmine/symbols/src/src_JsApiReporter.js.html +110 -0
  30. data/doc/jasmine/symbols/src/src_Matchers.js.html +399 -0
  31. data/doc/jasmine/symbols/src/src_MultiReporter.js.html +36 -0
  32. data/doc/jasmine/symbols/src/src_NestedResults.js.html +88 -0
  33. data/doc/jasmine/symbols/src/src_PrettyPrinter.js.html +128 -0
  34. data/doc/jasmine/symbols/src/src_Queue.js.html +119 -0
  35. data/doc/jasmine/symbols/src/src_Reporter.js.html +35 -0
  36. data/doc/jasmine/symbols/src/src_Reporters.js.html +51 -0
  37. data/doc/jasmine/symbols/src/src_Runner.js.html +75 -0
  38. data/doc/jasmine/symbols/src/src_Spec.js.html +228 -0
  39. data/doc/jasmine/symbols/src/src_Suite.js.html +77 -0
  40. data/doc/jasmine/symbols/src/src_WaitsBlock.js.html +21 -0
  41. data/doc/jasmine/symbols/src/src_WaitsForBlock.js.html +45 -0
  42. data/doc/jasmine/symbols/src/src_base.js.html +566 -0
  43. data/doc/jasmine/symbols/src/src_mock-timeout.js.html +185 -0
  44. data/doc/jasmine/symbols/src/src_util.js.html +75 -0
  45. data/lib/autotest/discover.rb +3 -0
  46. data/lib/autotest/jazrb.rb +55 -0
  47. data/lib/jazrb/intro.js +46 -0
  48. data/lib/jazrb/jasmine/EnvjsReporter.js +141 -0
  49. data/lib/jazrb/jasmine/TrivialReporter.js +155 -0
  50. data/lib/jazrb/jasmine/XMLReporter.js +241 -0
  51. data/lib/jazrb/jasmine/consolex.js +28 -0
  52. data/lib/jazrb/jasmine/jasmine-0.10.0.js +2526 -0
  53. data/lib/jazrb/jasmine/jasmine.js +2526 -0
  54. data/lib/jazrb/jasmine/json2.js +478 -0
  55. data/lib/jazrb/options.rb +26 -0
  56. data/lib/jazrb/outro.js +3 -0
  57. data/lib/jazrb/qintro.js +113 -0
  58. data/lib/jazrb/qoutro.js +3 -0
  59. data/lib/jazrb/qunit/qunit.css +17 -0
  60. data/lib/jazrb/qunit/qunit.js +1027 -0
  61. data/lib/jazrb.rb +0 -0
  62. data/spec/example/hello_world_spec.js +29 -0
  63. data/spec/example/nested/HelloWorldSpec.js +13 -0
  64. data/spec/example/nested/SpecHelper.js +1 -0
  65. data/spec/example/plain_spec.js +8 -0
  66. data/spec/example/spec_helper.js +1 -0
  67. data/spec/spec_helper.js +18 -0
  68. data/spec/spec_runner.js +143 -0
  69. data/test/jazrb_test.rb +7 -0
  70. data/test/test_helper.rb +10 -0
  71. data/vendor/jasmine/MIT.LICENSE +20 -0
  72. data/vendor/jasmine/README.markdown +479 -0
  73. data/vendor/jasmine/Rakefile +155 -0
  74. data/vendor/jasmine/contrib/ruby/jasmine_runner.rb +334 -0
  75. data/vendor/jasmine/contrib/ruby/jasmine_spec_builder.rb +153 -0
  76. data/vendor/jasmine/contrib/ruby/run.html +47 -0
  77. data/vendor/jasmine/contrib/ruby/spec/jasmine_runner_spec.rb +71 -0
  78. data/vendor/jasmine/doc/files.html +460 -0
  79. data/vendor/jasmine/doc/index.html +322 -0
  80. data/vendor/jasmine/doc/symbols/_global_.html +1083 -0
  81. data/vendor/jasmine/doc/symbols/jasmine.Block.html +417 -0
  82. data/vendor/jasmine/doc/symbols/jasmine.Clock.html +678 -0
  83. data/vendor/jasmine/doc/symbols/jasmine.Env.html +1135 -0
  84. data/vendor/jasmine/doc/symbols/jasmine.EnvjsReporter.html +328 -0
  85. data/vendor/jasmine/doc/symbols/jasmine.JsApiReporter.html +822 -0
  86. data/vendor/jasmine/doc/symbols/jasmine.Matchers.html +1106 -0
  87. data/vendor/jasmine/doc/symbols/jasmine.MultiReporter.html +394 -0
  88. data/vendor/jasmine/doc/symbols/jasmine.NestedResults.html +710 -0
  89. data/vendor/jasmine/doc/symbols/jasmine.Reporter.html +574 -0
  90. data/vendor/jasmine/doc/symbols/jasmine.Runner.html +710 -0
  91. data/vendor/jasmine/doc/symbols/jasmine.Spec.html +1372 -0
  92. data/vendor/jasmine/doc/symbols/jasmine.Spy.html +855 -0
  93. data/vendor/jasmine/doc/symbols/jasmine.Suite.html +705 -0
  94. data/vendor/jasmine/doc/symbols/jasmine.XMLReporter.html +328 -0
  95. data/vendor/jasmine/doc/symbols/jasmine.html +1359 -0
  96. data/vendor/jasmine/doc/symbols/jasmine.util.html +535 -0
  97. data/vendor/jasmine/doc/symbols/src/lib_EnvjsReporter.js.html +149 -0
  98. data/vendor/jasmine/doc/symbols/src/lib_TrivialReporter.js.html +127 -0
  99. data/vendor/jasmine/doc/symbols/src/lib_XMLReporter.js.html +210 -0
  100. data/vendor/jasmine/doc/symbols/src/src_Block.js.html +35 -0
  101. data/vendor/jasmine/doc/symbols/src/src_Env.js.html +233 -0
  102. data/vendor/jasmine/doc/symbols/src/src_JsApiReporter.js.html +110 -0
  103. data/vendor/jasmine/doc/symbols/src/src_Matchers.js.html +399 -0
  104. data/vendor/jasmine/doc/symbols/src/src_MultiReporter.js.html +36 -0
  105. data/vendor/jasmine/doc/symbols/src/src_NestedResults.js.html +88 -0
  106. data/vendor/jasmine/doc/symbols/src/src_PrettyPrinter.js.html +128 -0
  107. data/vendor/jasmine/doc/symbols/src/src_Queue.js.html +119 -0
  108. data/vendor/jasmine/doc/symbols/src/src_Reporter.js.html +35 -0
  109. data/vendor/jasmine/doc/symbols/src/src_Reporters.js.html +51 -0
  110. data/vendor/jasmine/doc/symbols/src/src_Runner.js.html +75 -0
  111. data/vendor/jasmine/doc/symbols/src/src_Spec.js.html +228 -0
  112. data/vendor/jasmine/doc/symbols/src/src_Suite.js.html +77 -0
  113. data/vendor/jasmine/doc/symbols/src/src_WaitsBlock.js.html +21 -0
  114. data/vendor/jasmine/doc/symbols/src/src_WaitsForBlock.js.html +45 -0
  115. data/vendor/jasmine/doc/symbols/src/src_base.js.html +566 -0
  116. data/vendor/jasmine/doc/symbols/src/src_mock-timeout.js.html +185 -0
  117. data/vendor/jasmine/doc/symbols/src/src_util.js.html +75 -0
  118. data/vendor/jasmine/examples/html/example_suite.html +27 -0
  119. data/vendor/jasmine/examples/html/spec/example_suite.js +11 -0
  120. data/vendor/jasmine/examples/ruby/Rakefile +33 -0
  121. data/vendor/jasmine/examples/ruby/spec/example/example_spec.js +11 -0
  122. data/vendor/jasmine/examples/ruby/spec/jasmine_helper.rb +41 -0
  123. data/vendor/jasmine/examples/ruby/spec/jasmine_spec.rb +31 -0
  124. data/vendor/jasmine/examples/ruby/spec/saucelabs.yml +24 -0
  125. data/vendor/jasmine/geminstaller.yml +23 -0
  126. data/vendor/jasmine/images/fail-16.png +0 -0
  127. data/vendor/jasmine/images/fail.png +0 -0
  128. data/vendor/jasmine/images/go-16.png +0 -0
  129. data/vendor/jasmine/images/go.png +0 -0
  130. data/vendor/jasmine/images/pending-16.png +0 -0
  131. data/vendor/jasmine/images/pending.png +0 -0
  132. data/vendor/jasmine/images/question-bk.png +0 -0
  133. data/vendor/jasmine/images/questionbk-16.png +0 -0
  134. data/vendor/jasmine/images/spinner.gif +0 -0
  135. data/vendor/jasmine/jasmine.watchr +70 -0
  136. data/vendor/jasmine/lib/EnvjsReporter.js +141 -0
  137. data/vendor/jasmine/lib/TrivialReporter.js +155 -0
  138. data/vendor/jasmine/lib/XMLReporter.js +241 -0
  139. data/vendor/jasmine/lib/consolex.js +28 -0
  140. data/vendor/jasmine/lib/jasmine-0.10.0.js +2526 -0
  141. data/vendor/jasmine/lib/jasmine.css +86 -0
  142. data/vendor/jasmine/lib/json2.js +478 -0
  143. data/vendor/jasmine/spec/jasmine_helper.rb +44 -0
  144. data/vendor/jasmine/spec/jasmine_spec.rb +31 -0
  145. data/vendor/jasmine/spec/runner.html +43 -0
  146. data/vendor/jasmine/spec/runner.js +78 -0
  147. data/vendor/jasmine/spec/saucelabs.yml +24 -0
  148. data/vendor/jasmine/spec/suites/EnvSpec.js +71 -0
  149. data/vendor/jasmine/spec/suites/ExceptionsSpec.js +107 -0
  150. data/vendor/jasmine/spec/suites/JsApiReporterSpec.js +82 -0
  151. data/vendor/jasmine/spec/suites/MatchersSpec.js +589 -0
  152. data/vendor/jasmine/spec/suites/MockClockSpec.js +34 -0
  153. data/vendor/jasmine/spec/suites/MultiReporterSpec.js +30 -0
  154. data/vendor/jasmine/spec/suites/NestedResultsSpec.js +54 -0
  155. data/vendor/jasmine/spec/suites/PrettyPrintSpec.js +93 -0
  156. data/vendor/jasmine/spec/suites/QueueSpec.js +23 -0
  157. data/vendor/jasmine/spec/suites/ReporterSpec.js +60 -0
  158. data/vendor/jasmine/spec/suites/RunnerSpec.js +258 -0
  159. data/vendor/jasmine/spec/suites/SpecRunningSpec.js +1117 -0
  160. data/vendor/jasmine/spec/suites/SpecSpec.js +110 -0
  161. data/vendor/jasmine/spec/suites/SpySpec.js +187 -0
  162. data/vendor/jasmine/spec/suites/SuiteSpec.js +101 -0
  163. data/vendor/jasmine/spec/suites/TrivialReporterSpec.js +140 -0
  164. data/vendor/jasmine/spec/suites/UtilSpec.js +23 -0
  165. data/vendor/jasmine/src/Block.js +34 -0
  166. data/vendor/jasmine/src/Env.js +236 -0
  167. data/vendor/jasmine/src/JsApiReporter.js +103 -0
  168. data/vendor/jasmine/src/Matchers.js +326 -0
  169. data/vendor/jasmine/src/MultiReporter.js +28 -0
  170. data/vendor/jasmine/src/NestedResults.js +99 -0
  171. data/vendor/jasmine/src/PrettyPrinter.js +122 -0
  172. data/vendor/jasmine/src/Queue.js +210 -0
  173. data/vendor/jasmine/src/Reporter.js +27 -0
  174. data/vendor/jasmine/src/Reporters.js +43 -0
  175. data/vendor/jasmine/src/Runner.js +68 -0
  176. data/vendor/jasmine/src/Spec.js +254 -0
  177. data/vendor/jasmine/src/Suite.js +70 -0
  178. data/vendor/jasmine/src/WaitsBlock.js +13 -0
  179. data/vendor/jasmine/src/WaitsForBlock.js +38 -0
  180. data/vendor/jasmine/src/base.js +604 -0
  181. data/vendor/jasmine/src/mock-timeout.js +177 -0
  182. data/vendor/jasmine/src/util.js +67 -0
  183. data/vendor/jasmine/src/version.json +5 -0
  184. metadata +279 -0
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Steven Parkes
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.
data/README.rdoc ADDED
@@ -0,0 +1,134 @@
1
+ = jazrb
2
+
3
+ Jazrb provides support for running JavaScript specs written using the
4
+ Jasmine JavaScript BDD framework under env.js. It includes support for
5
+ running via watchr and autotest.
6
+
7
+ Discussion at http://groups.google.com/group/jazrb.
8
+
9
+ == Install
10
+
11
+ You can install the gem via <tt>gem install smparkes-jazrb</tt>. If
12
+ you want to install from github (http://github.com/smparkes/jazrb),
13
+ you'll need to checkout the Jasmine submodule (<tt>git submodule
14
+ update --init</tt>) and also need to make sure you have the
15
+ prerequisites listed in the gemspec in the Rakefile. <tt>rake
16
+ gemspec</tt> will then build and copy the necessary parts of Jasmine.
17
+
18
+ If you want to run the examples/tests, you'll need jQuery. The <tt>git
19
+ submodule update --init</tt> command will have brought in jQuery, but
20
+ you'll need to build it: <tt>cd vendor/jquery && make</tt>.
21
+
22
+ Even if you install the gem, you may want to get the github files to
23
+ see and run the examples.
24
+
25
+ == Use
26
+
27
+ From the root of a project, i.e., the parent of the <tt>spec</tt>
28
+ directory, you can use the <tt>jazrb</tt> command as you would the
29
+ rspec <tt>spec</tt> command, e.g.,
30
+
31
+ jazrb spec/foo_spec.js spec/bar_spec.js
32
+
33
+ You can also execute HTML specs via jazrb:
34
+
35
+ jazrb spec/foo_spec.html
36
+
37
+ or even normal pages, that have the proper hooks to run as examples
38
+ (see below).
39
+
40
+ HTML files must be valid XML, i.e., XHTML, at this time.
41
+
42
+ The HTML fixture must load the necessary test files. Any number of
43
+ fixtures can be passed to the <tt>jazrb</tt> command.
44
+
45
+ jazrb uses env.js to run the tests, feeding it your HTML and
46
+ JavaScript, plus the necessary JavaScript and controls to make the tests
47
+ run correctly. You can see the entire <tt>envjsrb</tt> command by
48
+ passing <tt>jazrb</tt> the <tt>-v</tt> flag.
49
+
50
+ The Jasmine tests are configured to report results in streaming XML
51
+ (JUnit format, more or less), which <tt>jazrb</tt> turns into the
52
+ familiar rspec format. The <tt>--xml</tt> flag
53
+ causes <tt>jazrb</tt> to display the raw XML output.
54
+
55
+ To run all the tests in the <tt>spec</tt> directory repeatedly you can
56
+ use watchr:
57
+
58
+ rake test
59
+
60
+ or
61
+
62
+ watchr jazrb.watchr
63
+
64
+ or even
65
+
66
+ ./jazrb.watchr
67
+
68
+ See jazrb's own <tt>jazrb.watchr</tt> file and the
69
+ discussion on examples below.
70
+
71
+ You can also try using <tt>autojaz</tt> as
72
+ you would use <tt>autospec</tt>:
73
+
74
+ autojaz
75
+
76
+ You'll need to install the ZenTest gem if you don't have it installed;
77
+ <tt>jazrb</tt> can be used without ZenTest installed, but
78
+ <tt>autojaz</tt> cannot be. Note that <tt>autojaz</tt> may be
79
+ deprecated in favor of <tt>watchr</tt>.
80
+
81
+ Screen shot at http://www.scrnshots.com/users/smparkes/screenshots/206033
82
+
83
+ == Examples
84
+
85
+ There are examples in <tt>examples/*</tt> and <tt>spec/examples/*</tt>. You can run the
86
+ tests with <tt>rake test</tt> which will run the watchr control file,
87
+ <tt>jazrb.watchr</tt>. (Watchr as a runner will probably replace
88
+ autojaz.) You'll need the smparkes-watchr gem.
89
+
90
+ Running <tt>jazrb.watchr</tt> (either with <tt>watchr jazrb.watchr</tt>
91
+ or as <tt>./jazrb.watchr</tt> will run all the
92
+ tests and then watch the file system for changes. When it sees a change,
93
+ it reruns the test. It knows how to find the HTML fixtures for specs
94
+ where they exist in the right place, or it just runs the JavaScript
95
+ spec itself. An example of the former is the pair
96
+ <tt>example/hello_world.html</tt> and
97
+ <tt>spec/example/hello_world_spec.js</tt>: jazrb will reload the HTML if either file is changed.
98
+ An example of the latter
99
+ is <tt>spec/example/plain_spec.js</tt>.
100
+
101
+ You can also load the individual HTML files in the browser to run the
102
+ tests there. For example, on a Mac, <tt>open
103
+ example/hello_world.html</tt>. (The idea is that for production, the
104
+ spec helper files are changed to not load the tests: that should be
105
+ the only change necessary. Or the <tt><script></tt> tag could be
106
+ ripped out.) Note that to run the tests from the filesystem in Firefox, you'll
107
+ need to set the <tt>security.fileuri.strict_origin_policy</tt> option
108
+ to true.
109
+
110
+ == Recent Changes
111
+
112
+ 1. Pass dependence flag to envjsrb to support watchr dependences
113
+
114
+ 1. Add watchr support
115
+
116
+ 1. Add example
117
+
118
+ 1. Support multiple fixtures on the <tt>jazrb</tt> command. (Actually, this is entirely due to <tt>envjsrb</tt> supporting multiple fixtures. You need a recent build from github or an smparkes-envjs gem version of at least 0.0.5.)
119
+
120
+ == Things to do
121
+
122
+ 1. Complete and test support for loading against an HTTP server.
123
+
124
+ 1. Focus on failing tests until fixed, a la autotest.
125
+
126
+ 1. Extend to more frameworks, e.g., qunit. There's little here that's actually Jasmine-specific.
127
+
128
+ 1. Including a missing script should be an error
129
+
130
+ 1. Make work in interactive mode (requires intro/outro/out:blank intergration with envjsrb)
131
+
132
+ == Copyright
133
+
134
+ Copyright (c) 2009 Steven Parkes. See LICENSE for details.
data/bin/autojaz ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['JAZRB'] = 'true' # allows autotest to discover jazrb
3
+ ENV['AUTOTEST'] = 'true' # allows autotest to run w/ color on linux
4
+ system (RUBY_PLATFORM =~ /mswin|mingw/ ? 'autotest.bat' : 'autotest'), *ARGV
data/bin/jazrb ADDED
@@ -0,0 +1,230 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $VERBOSE = true
4
+
5
+ require 'jazrb/options'
6
+
7
+ ENV["JAZRB_JS_PATH"] =
8
+ JAZ_DIR = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'jazrb'))
9
+
10
+ intro = File.join(JAZ_DIR, "intro.js")
11
+ outro = File.join(JAZ_DIR, "outro.js")
12
+
13
+ if $jazrb_qunit
14
+ intro = File.join(JAZ_DIR, "qintro.js")
15
+ outro = File.join(JAZ_DIR, "qoutro.js")
16
+ end
17
+
18
+ args = [ "envjsrb" ]
19
+ if $jazrb_deps
20
+ args += [ "--deps", $jazrb_deps ]
21
+ end
22
+ args << intro
23
+
24
+ introd = true
25
+ outrod = true
26
+
27
+ ARGV.each do |f|
28
+
29
+ if f =~ /\.x?html?$/ || f =~ %r(^https?://)
30
+ if introd && !outrod
31
+ args << outro
32
+ args << "about:blank"
33
+ outrod = true
34
+ introd = false
35
+ end
36
+ if !introd
37
+ args << intro
38
+ end
39
+ args << f
40
+ introd = true
41
+ outrod = false
42
+ elsif f == "about:blank"
43
+ if introd && !outrod
44
+ args << outro
45
+ outrod = true
46
+ introd = false
47
+ end
48
+ args << f
49
+ else
50
+ args << f
51
+ end
52
+
53
+ end
54
+
55
+ args << outro
56
+
57
+ cmd = args.join(" ")
58
+
59
+ puts cmd if $jazrb_verbose
60
+
61
+ require 'eventmachine'
62
+ require 'nokogiri'
63
+
64
+ class Restart < Exception; end
65
+
66
+ def colour(text, colour_code)
67
+ # return text unless ENV['RSPEC_COLOR'] || (colour? & (autospec? || output_to_tty?))
68
+ "#{colour_code}#{text}\e[0m"
69
+ end
70
+
71
+ def green(text); colour(text, "\e[32m"); end
72
+ def red(text); colour(text, "\e[31m"); end
73
+ def yellow(text); colour(text, "\e[33m"); end
74
+ def blue(text); colour(text, "\e[34m"); end
75
+
76
+ $spec_info = {}
77
+ $spec_info[:specs] = []
78
+ $spec_info[:failures] = []
79
+ $spec_info[:pending] = []
80
+
81
+ class SAX < Nokogiri::XML::SAX::Document
82
+
83
+ def start_element name, attrs
84
+ # p attrs
85
+ attrs = Hash[*attrs]
86
+ # p attrs
87
+ case name
88
+ when "testsuites";
89
+ when "testsuite";
90
+ @testsuite_name = attrs["name"]
91
+ if @testsuite_pending = ( attrs["skipped"] == "true" )
92
+ $spec_info[:specs] << (tc = {})
93
+ tc[:name] = @testsuite_name
94
+ $spec_info[:pending] << $spec_info[:specs].last
95
+ end
96
+ when "testcase";
97
+ $spec_info[:specs] << (tc = {})
98
+ tc[:name] = @testsuite_name + " : " + attrs["name"]
99
+ @testcase_failed = false
100
+ when "failure";
101
+ $spec_info[:failures] << (tc = $spec_info[:specs].last)
102
+ tc[:message] = attrs["message"]
103
+ @testcase_failed = true
104
+ else; raise "hell: #{name}"
105
+ end
106
+ end
107
+
108
+ def cdata_block string
109
+ if @testcase_failed
110
+ $spec_info[:failures].last[:stack] ||= ""
111
+ $spec_info[:failures].last[:stack] << string
112
+ end
113
+ end
114
+
115
+ def end_element name
116
+ case name
117
+ when "testsuites";
118
+ raise Restart
119
+ when "testsuite";
120
+ if !$jazrb_xml
121
+ if @testsuite_pending
122
+ char = yellow("*")
123
+ print char
124
+ $stdout.flush
125
+ end
126
+ end
127
+ when "testcase";
128
+ if !$jazrb_xml
129
+ char = nil
130
+ if @testcase_failed
131
+ char = red("F")
132
+ else
133
+ char = green(".")
134
+ end
135
+ print char
136
+ $stdout.flush
137
+ end
138
+ when "failure";
139
+ else; raise "hell: #{name}"
140
+ end
141
+ end
142
+ end
143
+
144
+ $failed_processes = 0
145
+
146
+ module WriteToNokogiri
147
+ def post_init
148
+ @parser = Nokogiri::XML::SAX::PushParser.new( SAX.new )
149
+ end
150
+ def receive_data data
151
+ begin
152
+ if $jazrb_xml
153
+ # $stderr.print data
154
+ puts data
155
+ $stdout.flush
156
+ end
157
+ @parser << data
158
+ rescue Restart
159
+ @parser = Nokogiri::XML::SAX::PushParser.new( SAX.new )
160
+ rescue Exception => e
161
+ $stderr.puts "Parser raised #{e} on #{data}"
162
+ exit 1
163
+ end
164
+ end
165
+ def unbind
166
+ $failed_processes += 1 if get_status.exitstatus &&
167
+ get_status.exitstatus > 0
168
+ EM.stop
169
+ end
170
+ end
171
+
172
+ date = Time.now
173
+ failures = nil
174
+ examples = nil
175
+ pending = nil
176
+
177
+ EM.run do
178
+ EM.popen cmd, WriteToNokogiri
179
+ end
180
+
181
+ puts
182
+ puts
183
+
184
+ if !$jazrb_xml
185
+ if $spec_info[:pending].length > 0
186
+ puts "Pending:"
187
+ $spec_info[:pending].each do |pending|
188
+ puts
189
+ puts yellow(pending[:name])
190
+ end
191
+ puts "\n"
192
+ end
193
+ $spec_info[:failures].each_with_index do |failure,i|
194
+ print i+1,")\n"
195
+ print red("#{failure[:name]} FAILED\n")
196
+ print red(failure[:message]),"\n"
197
+ # double check, but is there really anything in the jaz stack that's useful?
198
+ stack = failure[:stack]
199
+ stack and ( stack = stack.split "\n" )
200
+ stack and stack.each do |line|
201
+ if line =~ %r(/jasmine.js:\d+) || line =~ %r(/jasmine/src/.*\.js:\d+)
202
+ break
203
+ end
204
+ print line, "\n"
205
+ end
206
+ # p stack
207
+ # print failure[:stack],"\n"
208
+ end
209
+ puts "Finished in #{Time.now - date} seconds"
210
+ puts
211
+ examples = $spec_info[:specs].length
212
+ # require 'pp'
213
+ # pp $spec_info[:specs]
214
+ failures = $spec_info[:failures].length
215
+ pending = $spec_info[:pending].length
216
+ if $failed_processes > 0
217
+ examples += $failed_processes
218
+ failures += $failed_processes
219
+ end
220
+ msg = "#{examples} examples, #{failures} failures, #{pending} pending"
221
+ if failures > 0
222
+ msg = red(msg)
223
+ elsif pending > 0
224
+ msg = yellow(msg)
225
+ else
226
+ msg = green(msg)
227
+ end
228
+ puts msg
229
+ end
230
+ exit ( !failures.nil? && failures > 0 ) ? 1 : 0