josephholsten-jasmine 1.1.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. data/.gitignore +11 -0
  2. data/.gitmodules +3 -0
  3. data/Gemfile +5 -0
  4. data/HOW_TO_TEST.markdown +9 -0
  5. data/MIT.LICENSE +20 -0
  6. data/README.markdown +71 -0
  7. data/RELEASE.markdown +22 -0
  8. data/Rakefile +76 -0
  9. data/bin/jasmine +6 -0
  10. data/generators/jasmine/jasmine_generator.rb +32 -0
  11. data/generators/jasmine/templates/INSTALL +9 -0
  12. data/generators/jasmine/templates/jasmine-example/SpecRunner.html +27 -0
  13. data/generators/jasmine/templates/jasmine-example/spec/PlayerSpec.js +58 -0
  14. data/generators/jasmine/templates/jasmine-example/spec/SpecHelper.js +9 -0
  15. data/generators/jasmine/templates/jasmine-example/src/Player.js +22 -0
  16. data/generators/jasmine/templates/jasmine-example/src/Song.js +7 -0
  17. data/generators/jasmine/templates/lib/tasks/jasmine.rake +8 -0
  18. data/generators/jasmine/templates/spec/javascripts/support/jasmine-rails.yml +81 -0
  19. data/generators/jasmine/templates/spec/javascripts/support/jasmine.yml +73 -0
  20. data/generators/jasmine/templates/spec/javascripts/support/jasmine_config.rb +23 -0
  21. data/generators/jasmine/templates/spec/javascripts/support/jasmine_runner.rb +32 -0
  22. data/jasmine/Gemfile +6 -0
  23. data/jasmine/Gemfile.lock +33 -0
  24. data/jasmine/HowToRelease.markdown +29 -0
  25. data/jasmine/MIT.LICENSE +20 -0
  26. data/jasmine/README.markdown +50 -0
  27. data/jasmine/Rakefile +166 -0
  28. data/jasmine/cruise_config.rb +21 -0
  29. data/jasmine/example/SpecRunner.html +27 -0
  30. data/jasmine/example/spec/PlayerSpec.js +58 -0
  31. data/jasmine/example/spec/SpecHelper.js +9 -0
  32. data/jasmine/example/src/Player.js +22 -0
  33. data/jasmine/example/src/Song.js +7 -0
  34. data/jasmine/images/jasmine_favicon.png +0 -0
  35. data/jasmine/jsdoc-template/allclasses.tmpl +17 -0
  36. data/jasmine/jsdoc-template/allfiles.tmpl +56 -0
  37. data/jasmine/jsdoc-template/class.tmpl +646 -0
  38. data/jasmine/jsdoc-template/index.tmpl +39 -0
  39. data/jasmine/jsdoc-template/publish.js +184 -0
  40. data/jasmine/jsdoc-template/static/default.css +162 -0
  41. data/jasmine/jsdoc-template/static/header.html +2 -0
  42. data/jasmine/jsdoc-template/static/index.html +19 -0
  43. data/jasmine/jsdoc-template/symbol.tmpl +35 -0
  44. data/jasmine/jshint/jshint.js +5919 -0
  45. data/jasmine/jshint/run.js +98 -0
  46. data/jasmine/lib/jasmine-html.js +190 -0
  47. data/jasmine/lib/jasmine.css +166 -0
  48. data/jasmine/lib/jasmine.js +2445 -0
  49. data/jasmine/lib/json2.js +478 -0
  50. data/jasmine/spec/node_suite.js +233 -0
  51. data/jasmine/spec/runner.html +82 -0
  52. data/jasmine/spec/suites/BaseSpec.js +27 -0
  53. data/jasmine/spec/suites/CustomMatchersSpec.js +97 -0
  54. data/jasmine/spec/suites/EnvSpec.js +158 -0
  55. data/jasmine/spec/suites/ExceptionsSpec.js +107 -0
  56. data/jasmine/spec/suites/JsApiReporterSpec.js +103 -0
  57. data/jasmine/spec/suites/MatchersSpec.js +795 -0
  58. data/jasmine/spec/suites/MockClockSpec.js +38 -0
  59. data/jasmine/spec/suites/MultiReporterSpec.js +45 -0
  60. data/jasmine/spec/suites/NestedResultsSpec.js +54 -0
  61. data/jasmine/spec/suites/PrettyPrintSpec.js +93 -0
  62. data/jasmine/spec/suites/QueueSpec.js +23 -0
  63. data/jasmine/spec/suites/ReporterSpec.js +56 -0
  64. data/jasmine/spec/suites/RunnerSpec.js +267 -0
  65. data/jasmine/spec/suites/SpecRunningSpec.js +1253 -0
  66. data/jasmine/spec/suites/SpecSpec.js +124 -0
  67. data/jasmine/spec/suites/SpySpec.js +201 -0
  68. data/jasmine/spec/suites/SuiteSpec.js +120 -0
  69. data/jasmine/spec/suites/TrivialConsoleReporterSpec.js +431 -0
  70. data/jasmine/spec/suites/TrivialReporterSpec.js +238 -0
  71. data/jasmine/spec/suites/UtilSpec.js +39 -0
  72. data/jasmine/spec/suites/WaitsForBlockSpec.js +118 -0
  73. data/jasmine/src/Block.js +22 -0
  74. data/jasmine/src/Env.js +264 -0
  75. data/jasmine/src/JsApiReporter.js +102 -0
  76. data/jasmine/src/Matchers.js +354 -0
  77. data/jasmine/src/MultiReporter.js +35 -0
  78. data/jasmine/src/NestedResults.js +80 -0
  79. data/jasmine/src/PrettyPrinter.js +123 -0
  80. data/jasmine/src/Queue.js +99 -0
  81. data/jasmine/src/Reporter.js +31 -0
  82. data/jasmine/src/Runner.js +77 -0
  83. data/jasmine/src/Spec.js +242 -0
  84. data/jasmine/src/Suite.js +82 -0
  85. data/jasmine/src/WaitsBlock.js +15 -0
  86. data/jasmine/src/WaitsForBlock.js +54 -0
  87. data/jasmine/src/base.js +608 -0
  88. data/jasmine/src/console/TrivialConsoleReporter.js +144 -0
  89. data/jasmine/src/html/TrivialReporter.js +190 -0
  90. data/jasmine/src/html/jasmine.css +166 -0
  91. data/jasmine/src/mock-timeout.js +183 -0
  92. data/jasmine/src/util.js +67 -0
  93. data/jasmine/src/version.json +5 -0
  94. data/jasmine.gemspec +52 -0
  95. data/lib/generators/jasmine/examples/USAGE +11 -0
  96. data/lib/generators/jasmine/examples/examples_generator.rb +19 -0
  97. data/lib/generators/jasmine/examples/templates/public/javascripts/jasmine_examples/Player.js +22 -0
  98. data/lib/generators/jasmine/examples/templates/public/javascripts/jasmine_examples/Song.js +7 -0
  99. data/lib/generators/jasmine/examples/templates/spec/javascripts/helpers/SpecHelper.js +9 -0
  100. data/lib/generators/jasmine/examples/templates/spec/javascripts/jasmine_examples/PlayerSpec.js +58 -0
  101. data/lib/generators/jasmine/install/USAGE +11 -0
  102. data/lib/generators/jasmine/install/install_generator.rb +18 -0
  103. data/lib/generators/jasmine/install/templates/spec/javascripts/helpers/.gitkeep +0 -0
  104. data/lib/generators/jasmine/install/templates/spec/javascripts/support/jasmine.yml +81 -0
  105. data/lib/generators/jasmine/install/templates/spec/javascripts/support/jasmine_config.rb +23 -0
  106. data/lib/generators/jasmine/install/templates/spec/javascripts/support/jasmine_runner.rb +20 -0
  107. data/lib/generators/jasmine/jasmine_generator.rb +32 -0
  108. data/lib/generators/jasmine/templates/INSTALL +9 -0
  109. data/lib/generators/jasmine/templates/lib/tasks/jasmine.rake +2 -0
  110. data/lib/generators/jasmine/templates/spec/javascripts/support/jasmine-rails.yml +81 -0
  111. data/lib/generators/jasmine/templates/spec/javascripts/support/jasmine.yml +73 -0
  112. data/lib/generators/jasmine/templates/spec/javascripts/support/jasmine_config.rb +23 -0
  113. data/lib/generators/jasmine/templates/spec/javascripts/support/jasmine_runner.rb +32 -0
  114. data/lib/jasmine/base.rb +66 -0
  115. data/lib/jasmine/command_line_tool.rb +72 -0
  116. data/lib/jasmine/config.rb +190 -0
  117. data/lib/jasmine/railtie.rb +20 -0
  118. data/lib/jasmine/run.html.erb +44 -0
  119. data/lib/jasmine/selenium_driver.rb +49 -0
  120. data/lib/jasmine/server.rb +106 -0
  121. data/lib/jasmine/spec_builder.rb +162 -0
  122. data/lib/jasmine/tasks/jasmine.rake +44 -0
  123. data/lib/jasmine/version.rb +3 -0
  124. data/lib/jasmine.rb +14 -0
  125. data/spec/config_spec.rb +308 -0
  126. data/spec/fixture/jasmine.erb.yml +4 -0
  127. data/spec/jasmine_command_line_tool_spec.rb +29 -0
  128. data/spec/jasmine_pojs_spec.rb +51 -0
  129. data/spec/jasmine_rails2_spec.rb +93 -0
  130. data/spec/jasmine_rails3_spec.rb +71 -0
  131. data/spec/jasmine_self_test_config.rb +15 -0
  132. data/spec/jasmine_self_test_spec.rb +24 -0
  133. data/spec/server_spec.rb +80 -0
  134. data/spec/spec_helper.rb +65 -0
  135. metadata +386 -0
@@ -0,0 +1,66 @@
1
+ require 'socket'
2
+ require 'erb'
3
+
4
+ module Jasmine
5
+ def self.root
6
+ ENV["JASMINE_ROOT"] || File.expand_path(File.join(File.dirname(__FILE__), '../../jasmine'))
7
+ end
8
+
9
+ # this seemingly-over-complex method is necessary to get an open port on at least some of our Macs
10
+ def self.open_socket_on_unused_port
11
+ infos = Socket::getaddrinfo("localhost", nil, Socket::AF_UNSPEC, Socket::SOCK_STREAM, 0, Socket::AI_PASSIVE)
12
+ families = Hash[*infos.collect { |af, *_| af }.uniq.zip([]).flatten]
13
+
14
+ return TCPServer.open('0.0.0.0', 0) if families.has_key?('AF_INET')
15
+ return TCPServer.open('::', 0) if families.has_key?('AF_INET6')
16
+ return TCPServer.open(0)
17
+ end
18
+
19
+ def self.find_unused_port
20
+ socket = open_socket_on_unused_port
21
+ port = socket.addr[1]
22
+ socket.close
23
+ port
24
+ end
25
+
26
+ def self.server_is_listening_on(hostname, port)
27
+ require 'socket'
28
+ begin
29
+ socket = TCPSocket.open(hostname, port)
30
+ rescue Errno::ECONNREFUSED
31
+ return false
32
+ end
33
+ socket.close
34
+ true
35
+ end
36
+
37
+ def self.wait_for_listener(port, name = "required process", seconds_to_wait = 10)
38
+ time_out_at = Time.now + seconds_to_wait
39
+ until server_is_listening_on "localhost", port
40
+ sleep 0.1
41
+ puts "Waiting for #{name} on #{port}..."
42
+ raise "#{name} didn't show up on port #{port} after #{seconds_to_wait} seconds." if Time.now > time_out_at
43
+ end
44
+ end
45
+
46
+ def self.cachebust(files, root_dir="", replace=nil, replace_with=nil)
47
+ require 'digest/md5'
48
+ files.collect do |file_name|
49
+ real_file_name = replace && replace_with ? file_name.sub(replace, replace_with) : file_name
50
+ begin
51
+ digest = Digest::MD5.hexdigest(File.read("#{root_dir}#{real_file_name}"))
52
+ rescue
53
+ digest = "MISSING-FILE"
54
+ end
55
+ "#{file_name}?cachebust=#{digest}"
56
+ end
57
+ end
58
+
59
+ def self.rspec2?
60
+ Gem.available? "rspec", ">= 2.0"
61
+ end
62
+
63
+ def self.rails3?
64
+ Gem.available? "rails", ">= 3.0"
65
+ end
66
+ end
@@ -0,0 +1,72 @@
1
+ module Jasmine
2
+ class CommandLineTool
3
+ def cwd
4
+ File.expand_path(File.join(File.dirname(__FILE__), '../..'))
5
+ end
6
+
7
+ def expand(*paths)
8
+ File.expand_path(File.join(*paths))
9
+ end
10
+
11
+ def template_path(filepath)
12
+ expand(cwd, File.join("generators/jasmine/templates", filepath))
13
+ end
14
+
15
+ def dest_path(filepath)
16
+ expand(Dir.pwd, filepath)
17
+ end
18
+
19
+ def copy_unless_exists(relative_path, dest_path = nil)
20
+ unless File.exist?(dest_path(relative_path))
21
+ FileUtils.copy(template_path(relative_path), dest_path(dest_path || relative_path))
22
+ end
23
+ end
24
+
25
+ def process(argv)
26
+ if argv[0] == 'init'
27
+ require 'fileutils'
28
+
29
+ FileUtils.makedirs('public/javascripts')
30
+ FileUtils.makedirs('spec/javascripts')
31
+ FileUtils.makedirs('spec/javascripts/support')
32
+ FileUtils.makedirs('spec/javascripts/helpers')
33
+
34
+ copy_unless_exists('jasmine-example/src/Player.js', 'public/javascripts/Player.js')
35
+ copy_unless_exists('jasmine-example/src/Song.js', 'public/javascripts/Song.js')
36
+ copy_unless_exists('jasmine-example/spec/PlayerSpec.js', 'spec/javascripts/PlayerSpec.js')
37
+ copy_unless_exists('jasmine-example/spec/SpecHelper.js', 'spec/javascripts/helpers/SpecHelper.js')
38
+ copy_unless_exists('spec/javascripts/support/jasmine_runner.rb')
39
+ copy_unless_exists('spec/javascripts/support/jasmine_config.rb')
40
+
41
+ rails_tasks_dir = dest_path('lib/tasks')
42
+ if File.exist?(rails_tasks_dir)
43
+ copy_unless_exists('lib/tasks/jasmine.rake')
44
+ copy_unless_exists('spec/javascripts/support/jasmine-rails.yml', 'spec/javascripts/support/jasmine.yml')
45
+ else
46
+ copy_unless_exists('spec/javascripts/support/jasmine.yml')
47
+ write_mode = 'w'
48
+ if File.exist?(dest_path('Rakefile'))
49
+ load dest_path('Rakefile')
50
+ write_mode = 'a'
51
+ end
52
+
53
+ require 'rake'
54
+ unless Rake::Task.task_defined?('jasmine')
55
+ File.open(dest_path('Rakefile'), write_mode) do |f|
56
+ f.write("\n" + File.read(template_path('lib/tasks/jasmine.rake')))
57
+ end
58
+ end
59
+ end
60
+ File.open(template_path('INSTALL'), 'r').each_line do |line|
61
+ puts line
62
+ end
63
+ elsif argv[0] == "license"
64
+ puts File.new(expand(cwd, "MIT.LICENSE")).read
65
+ else
66
+ puts "unknown command #{argv}"
67
+ puts "Usage: jasmine init"
68
+ puts " license"
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,190 @@
1
+ module Jasmine
2
+ class Config
3
+ require 'yaml'
4
+ require 'erb'
5
+
6
+ def browser
7
+ ENV["JASMINE_BROWSER"] || 'firefox'
8
+ end
9
+
10
+ def jasmine_host
11
+ ENV["JASMINE_HOST"] || 'http://localhost'
12
+ end
13
+
14
+ def jasmine_port
15
+ ENV["JASMINE_PORT"] || Jasmine::find_unused_port
16
+ end
17
+
18
+ def start_server(port = 8888)
19
+ server = Rack::Server.new(:Port => port, :AccessLog => [])
20
+ server.instance_variable_set(:@app, Jasmine.app(self)) # workaround for Rack bug, when Rack > 1.2.1 is released Rack::Server.start(:app => Jasmine.app(self)) will work
21
+ server.start
22
+ end
23
+
24
+ def start
25
+ start_jasmine_server
26
+ @client = Jasmine::SeleniumDriver.new(browser, "#{jasmine_host}:#{@jasmine_server_port}/")
27
+ @client.connect
28
+ end
29
+
30
+ def stop
31
+ @client.disconnect
32
+ end
33
+
34
+ def start_jasmine_server
35
+ @jasmine_server_port = jasmine_port
36
+ Thread.new do
37
+ start_server(@jasmine_server_port)
38
+ end
39
+ Jasmine::wait_for_listener(@jasmine_server_port, "jasmine server")
40
+ puts "jasmine server started."
41
+ end
42
+
43
+ def windows?
44
+ require 'rbconfig'
45
+ ::RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
46
+ end
47
+
48
+ def run
49
+ begin
50
+ start
51
+ puts "servers are listening on their ports -- running the test script..."
52
+ tests_passed = @client.run
53
+ ensure
54
+ stop
55
+ end
56
+ return tests_passed
57
+ end
58
+
59
+ def eval_js(script)
60
+ @client.eval_js(script)
61
+ end
62
+
63
+ def json_generate(obj)
64
+ @client.json_generate(obj)
65
+ end
66
+
67
+ def match_files(dir, patterns)
68
+ dir = File.expand_path(dir)
69
+ negative, positive = patterns.partition {|pattern| /^!/ =~ pattern}
70
+ chosen, negated = [positive, negative].collect do |patterns|
71
+ patterns.collect do |pattern|
72
+ matches = Dir.glob(File.join(dir, pattern.gsub(/^!/,'')))
73
+ matches.collect {|f| f.sub("#{dir}/", "")}.sort
74
+ end.flatten.uniq
75
+ end
76
+ chosen - negated
77
+ end
78
+
79
+ def simple_config
80
+ config = File.exist?(simple_config_file) ? YAML::load(ERB.new(File.read(simple_config_file)).result(binding)) : false
81
+ config || {}
82
+ end
83
+
84
+
85
+ def spec_path
86
+ "/__spec__"
87
+ end
88
+
89
+ def root_path
90
+ "/__root__"
91
+ end
92
+
93
+ def js_files(spec_filter = nil)
94
+ spec_files_to_include = spec_filter.nil? ? spec_files : match_files(spec_dir, [spec_filter])
95
+ src_files.collect {|f| "/" + f } + asset_files.collect {|f| asset_path + '/' + f} + helpers.collect {|f| File.join(spec_path, f) } + spec_files_to_include.collect {|f| File.join(spec_path, f) }
96
+ end
97
+
98
+ def css_files
99
+ stylesheets.collect {|f| "/" + f }
100
+ end
101
+
102
+ def spec_files_full_paths
103
+ spec_files.collect {|spec_file| File.join(spec_dir, spec_file) }
104
+ end
105
+
106
+ def project_root
107
+ Dir.pwd
108
+ end
109
+
110
+ def simple_config_file
111
+ File.join(project_root, 'spec/javascripts/support/jasmine.yml')
112
+ end
113
+
114
+ def src_dir
115
+ if simple_config['src_dir']
116
+ File.join(project_root, simple_config['src_dir'])
117
+ else
118
+ project_root
119
+ end
120
+ end
121
+
122
+ def spec_dir
123
+ if simple_config['spec_dir']
124
+ File.join(project_root, simple_config['spec_dir'])
125
+ else
126
+ File.join(project_root, 'spec/javascripts')
127
+ end
128
+ end
129
+
130
+ def helpers
131
+ if simple_config['helpers']
132
+ match_files(spec_dir, simple_config['helpers'])
133
+ else
134
+ match_files(spec_dir, ["helpers/**/*.js"])
135
+ end
136
+ end
137
+
138
+ def src_files
139
+ if simple_config['src_files']
140
+ match_files(src_dir, simple_config['src_files'])
141
+ else
142
+ []
143
+ end
144
+ end
145
+
146
+ def spec_files
147
+ if simple_config['spec_files']
148
+ match_files(spec_dir, simple_config['spec_files'])
149
+ else
150
+ match_files(spec_dir, ["**/*[sS]pec.js"])
151
+ end
152
+ end
153
+
154
+ def stylesheets
155
+ if simple_config['stylesheets']
156
+ match_files(src_dir, simple_config['stylesheets'])
157
+ else
158
+ []
159
+ end
160
+ end
161
+
162
+ def asset_path
163
+ '/__assets__'
164
+ end
165
+
166
+ def asset_dir
167
+ if simple_config['asset_dir']
168
+ File.join(project_root, simple_config['asset_dir'])
169
+ else
170
+ File.join(project_root, 'app/assets')
171
+ end
172
+ end
173
+
174
+ def asset_paths
175
+ if simple_config['asset_paths']
176
+ simple_config['asset_paths']
177
+ else
178
+ ['javascripts','stylesheets']
179
+ end
180
+ end
181
+
182
+ def asset_files
183
+ if simple_config['asset_files']
184
+ simple_config['asset_files']
185
+ else
186
+ []
187
+ end
188
+ end
189
+ end
190
+ end
@@ -0,0 +1,20 @@
1
+ require "rails/railtie"
2
+ module Jasmine
3
+ class Railtie < Rails::Railtie
4
+
5
+ config.before_configuration do
6
+ old_jasmine_rakefile = ::Rails.root.join('lib', 'tasks', 'jasmine.rake')
7
+ if old_jasmine_rakefile.exist? && !ENV["USE_JASMINE_RAKE"]
8
+ puts %Q{
9
+ You no longer need to have jasmine.rake in your project, as it is now automatically loaded
10
+ from the Jasmine gem. To silence this warning, set "USE_JASMINE_RAKE=true" in your environment
11
+ or remove jasmine.rake.
12
+ }
13
+ end
14
+ end
15
+
16
+ rake_tasks do
17
+ load "jasmine/tasks/jasmine.rake"
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,44 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
2
+ <html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
3
+ <head>
4
+ <meta content="text/html;charset=UTF-8" http-equiv="Content-Type"/>
5
+ <title>Jasmine suite</title>
6
+ <link rel="shortcut icon" type="image/png" href="/__JASMINE_ROOT__/images/jasmine_favicon.png">
7
+ <% css_files.each do |css_file| %>
8
+ <link rel="stylesheet" href="<%= css_file %>" type="text/css" media="screen"/>
9
+ <% end %>
10
+
11
+ <% jasmine_files.each do |jasmine_file| %>
12
+ <script src="<%= jasmine_file %>" type="text/javascript"></script>
13
+ <% end %>
14
+
15
+ <script type="text/javascript">
16
+ var jsApiReporter;
17
+ (function() {
18
+ var jasmineEnv = jasmine.getEnv();
19
+
20
+ jsApiReporter = new jasmine.JsApiReporter();
21
+ var trivialReporter = new jasmine.TrivialReporter();
22
+
23
+ jasmineEnv.addReporter(jsApiReporter);
24
+ jasmineEnv.addReporter(trivialReporter);
25
+
26
+ jasmineEnv.specFilter = function(spec) {
27
+ return trivialReporter.specFilter(spec);
28
+ };
29
+
30
+ window.onload = function() {
31
+ jasmineEnv.execute();
32
+ };
33
+ })();
34
+ </script>
35
+
36
+ <% js_files.each do |js_file| %>
37
+ <script src="<%= js_file %>" type="text/javascript"></script>
38
+ <% end %>
39
+
40
+ </head>
41
+ <body>
42
+ <div id="jasmine_content"></div>
43
+ </body>
44
+ </html>
@@ -0,0 +1,49 @@
1
+ module Jasmine
2
+ class SeleniumDriver
3
+ def initialize(browser, http_address)
4
+ require 'selenium-webdriver'
5
+ selenium_server = if ENV['SELENIUM_SERVER']
6
+ ENV['SELENIUM_SERVER']
7
+ elsif ENV['SELENIUM_SERVER_PORT']
8
+ "http://localhost:#{ENV['SELENIUM_SERVER_PORT']}/wd/hub"
9
+ end
10
+ @driver = if selenium_server
11
+ Selenium::WebDriver.for :remote, :url => selenium_server, :desired_capabilities => browser.to_sym
12
+ else
13
+ Selenium::WebDriver.for browser.to_sym
14
+ end
15
+ @http_address = http_address
16
+ end
17
+
18
+ def tests_have_finished?
19
+ @driver.execute_script("return window.jasmine.getEnv().currentRunner.finished") == "true"
20
+ end
21
+
22
+ def connect
23
+ @driver.navigate.to @http_address
24
+ end
25
+
26
+ def disconnect
27
+ @driver.quit
28
+ end
29
+
30
+ def run
31
+ until tests_have_finished? do
32
+ sleep 0.1
33
+ end
34
+
35
+ puts @driver.execute_script("return window.results()")
36
+ failed_count = @driver.execute_script("return window.jasmine.getEnv().currentRunner.results().failedCount").to_i
37
+ failed_count == 0
38
+ end
39
+
40
+ def eval_js(script)
41
+ result = @driver.execute_script(script)
42
+ JSON.parse("{\"result\":#{result}}")["result"]
43
+ end
44
+
45
+ def json_generate(obj)
46
+ JSON.generate(obj)
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,106 @@
1
+ require 'rack'
2
+ require 'sprockets'
3
+
4
+ module Jasmine
5
+ class RunAdapter
6
+ def initialize(config)
7
+ @config = config
8
+ @jasmine_files = [
9
+ "/__JASMINE_ROOT__/lib/jasmine.js",
10
+ "/__JASMINE_ROOT__/lib/jasmine-html.js",
11
+ "/__JASMINE_ROOT__/lib/json2.js",
12
+ ]
13
+ @jasmine_stylesheets = ["/__JASMINE_ROOT__/lib/jasmine.css"]
14
+ end
15
+
16
+ def call(env)
17
+ return not_found if env["PATH_INFO"] != "/"
18
+ run
19
+ end
20
+
21
+ def not_found
22
+ body = "File not found: #{@path_info}\n"
23
+ [404, {"Content-Type" => "text/plain",
24
+ "Content-Length" => body.size.to_s,
25
+ "X-Cascade" => "pass"},
26
+ [body]]
27
+ end
28
+
29
+ #noinspection RubyUnusedLocalVariable
30
+ def run(focused_suite = nil)
31
+ jasmine_files = @jasmine_files
32
+ css_files = @jasmine_stylesheets + (@config.css_files || [])
33
+ js_files = @config.js_files(focused_suite)
34
+ body = ERB.new(File.read(File.join(File.dirname(__FILE__), "run.html.erb"))).result(binding)
35
+ [
36
+ 200,
37
+ { 'Content-Type' => 'text/html' },
38
+ [body]
39
+ ]
40
+ end
41
+ end
42
+
43
+ class Redirect
44
+ def initialize(url)
45
+ @url = url
46
+ end
47
+
48
+ def call(env)
49
+ [
50
+ 302,
51
+ { 'Location' => @url },
52
+ []
53
+ ]
54
+ end
55
+ end
56
+
57
+ class JsAlert
58
+ def call(env)
59
+ [
60
+ 200,
61
+ { 'Content-Type' => 'application/javascript' },
62
+ ["document.write('<p>Couldn\\'t load #{env["PATH_INFO"]}!</p>');"]
63
+ ]
64
+ end
65
+ end
66
+
67
+ class FocusedSuite
68
+ def initialize(config)
69
+ @config = config
70
+ end
71
+
72
+ def call(env)
73
+ run_adapter = Jasmine::RunAdapter.new(@config)
74
+ run_adapter.run(env["PATH_INFO"])
75
+ end
76
+ end
77
+
78
+ def self.app(config)
79
+ Rack::Builder.app do
80
+ use Rack::Head
81
+
82
+ map('/run.html') { run Jasmine::Redirect.new('/') }
83
+ map('/__suite__') { run Jasmine::FocusedSuite.new(config) }
84
+
85
+ map('/__JASMINE_ROOT__') { run Rack::File.new(Jasmine.root) }
86
+ map(config.root_path) { run Rack::File.new(config.project_root) }
87
+ map(config.asset_path) do
88
+ assets_server = Sprockets::Environment.new config.asset_dir
89
+ config.asset_paths.each {|p| assets_server.paths << p }
90
+ run assets_server
91
+ end
92
+ map(config.spec_path) do
93
+ server = Sprockets::Environment.new config.spec_dir
94
+ server.paths << '.'
95
+ run server
96
+ end
97
+
98
+ map('/') do
99
+ run Rack::Cascade.new([
100
+ Rack::URLMap.new('/' => Rack::File.new(config.src_dir)),
101
+ Jasmine::RunAdapter.new(config)
102
+ ])
103
+ end
104
+ end
105
+ end
106
+ end