update jasmine runner to take focus spec

This commit is contained in:
Rajan Agaskar & Ryan Dy 2009-10-14 10:28:23 -07:00
parent a907301dcb
commit beddbaf5c7
2 changed files with 56 additions and 15 deletions

View File

@ -61,25 +61,32 @@ module Jasmine
end end
class RunAdapter class RunAdapter
def initialize(spec_files_or_proc, jasmine_files = nil, stylesheets = []) def initialize(spec_files_or_proc, options = {})
@spec_files_or_proc = spec_files_or_proc @spec_files_or_proc = Jasmine.files(spec_files_or_proc)
@jasmine_files = jasmine_files || [ @jasmine_files = options[:jasmine_files] || [
"/__JASMINE_ROOT__/lib/" + File.basename(Dir.glob("#{Jasmine.root}/lib/jasmine*.js").first), "/__JASMINE_ROOT__/lib/" + File.basename(Dir.glob("#{Jasmine.root}/lib/jasmine*.js").first),
"/__JASMINE_ROOT__/lib/TrivialReporter.js", "/__JASMINE_ROOT__/lib/TrivialReporter.js",
"/__JASMINE_ROOT__/lib/json2.js" "/__JASMINE_ROOT__/lib/json2.js"
] ]
@stylesheets = ["/__JASMINE_ROOT__/lib/jasmine.css"] + stylesheets @stylesheets = ["/__JASMINE_ROOT__/lib/jasmine.css"] + (Jasmine.files(options[:stylesheets]))
@spec_helpers = Jasmine.files(options[:spec_helpers])
end end
def call(env) def call(env)
run
end
def run
stylesheets = @stylesheets
spec_helpers = @spec_helpers
spec_files = @spec_files_or_proc spec_files = @spec_files_or_proc
spec_files = spec_files.call if spec_files.respond_to?(:call)
jasmine_files = @jasmine_files jasmine_files = @jasmine_files
jasmine_files = jasmine_files.call if jasmine_files.respond_to?(:call) jasmine_files = jasmine_files.call if jasmine_files.respond_to?(:call)
css_files = @stylesheets css_files = @stylesheets
body = ERB.new(File.read(File.join(File.dirname(__FILE__), "run.html"))).result(binding) body = ERB.new(File.read(File.join(File.dirname(__FILE__), "run.html"))).result(binding)
[ [
200, 200,
@ -87,6 +94,8 @@ module Jasmine
body body
] ]
end end
end end
class Redirect class Redirect
@ -113,13 +122,36 @@ module Jasmine
end end
end end
class SimpleServer class FocusedSuite
def self.start(port, spec_files_or_proc, mappings, jasmine_files = nil, stylesheets = []) def initialize(spec_files_or_proc, options)
require 'thin' @spec_files_or_proc = Jasmine.files(spec_files_or_proc)
@options = options
end
def call(env)
spec_files = @spec_files_or_proc
matching_specs = spec_files.select {|spec_file| spec_file =~ /#{Regexp.escape(env["PATH_INFO"])}/ }.compact
if !matching_specs.empty?
run_adapter = Jasmine::RunAdapter.new(matching_specs, @options)
run_adapter.run
else
[
200,
{ 'Content-Type' => 'application/javascript' },
"document.write('<p>Couldn\\'t find any specs matching #{env["PATH_INFO"]}!</p>');"
]
end
end
end
class SimpleServer
def self.start(port, spec_files_or_proc, mappings, options)
require 'thin'
config = { config = {
'/suites' => Jasmine::FocusedSuite.new(spec_files_or_proc, options),
'/run.html' => Jasmine::Redirect.new('/'), '/run.html' => Jasmine::Redirect.new('/'),
'/' => Jasmine::RunAdapter.new(spec_files_or_proc, jasmine_files, stylesheets) '/' => Jasmine::RunAdapter.new(spec_files_or_proc, options)
} }
mappings.each do |from, to| mappings.each do |from, to|
config[from] = Rack::File.new(to) config[from] = Rack::File.new(to)
@ -180,15 +212,13 @@ module Jasmine
end end
class Runner class Runner
def initialize(selenium_jar_path, spec_files, dir_mappings, jasmine_files = nil, options={}) def initialize(selenium_jar_path, spec_files, dir_mappings, options={})
@selenium_jar_path = selenium_jar_path @selenium_jar_path = selenium_jar_path
@spec_files = spec_files @spec_files = spec_files
@dir_mappings = dir_mappings @dir_mappings = dir_mappings
@jasmine_files = jasmine_files @options = options
@browser = options[:browser] || 'firefox'
@stylesheets = options[:stylesheets] || []
@browser = options[:browser] ? options[:browser].delete(:browser) : 'firefox'
@selenium_pid = nil @selenium_pid = nil
@jasmine_server_pid = nil @jasmine_server_pid = nil
end end
@ -216,7 +246,7 @@ module Jasmine
@jasmine_server_pid = fork do @jasmine_server_pid = fork do
Process.setpgrp Process.setpgrp
Jasmine::SimpleServer.start(@jasmine_server_port, @spec_files, @dir_mappings, @jasmine_files, @stylesheets) Jasmine::SimpleServer.start(@jasmine_server_port, @spec_files, @dir_mappings, @options)
exit! 0 exit! 0
end end
puts "jasmine server started. pid is #{@jasmine_server_pid}" puts "jasmine server started. pid is #{@jasmine_server_pid}"
@ -246,4 +276,11 @@ module Jasmine
@client.eval_js(script) @client.eval_js(script)
end end
end end
def self.files(f)
result = f
result = result.call if result.respond_to?(:call)
result || []
end
end end

View File

@ -11,6 +11,10 @@
<script src="<%= jasmine_file %>" type="text/javascript"></script> <script src="<%= jasmine_file %>" type="text/javascript"></script>
<% end %> <% end %>
<% spec_helpers.each do |spec_helper| %>
<script src="<%= spec_helper %>" type="text/javascript"></script>
<% end %>
<script type="text/javascript"> <script type="text/javascript">
var jsApiReporter; var jsApiReporter;
(function() { (function() {