Pass a Proc to SimpleServer.start instead of an array to defer spec file finding.
This commit is contained in:
parent
bf3e3c60e5
commit
6e9cd25150
|
@ -20,14 +20,14 @@ module Jasmine
|
|||
end
|
||||
|
||||
class RunAdapter
|
||||
def initialize(spec_files)
|
||||
p "spec_files: #{spec_files}"
|
||||
|
||||
@spec_files = spec_files
|
||||
def initialize(spec_files_or_proc)
|
||||
@spec_files_or_proc = spec_files_or_proc
|
||||
end
|
||||
|
||||
def call(env)
|
||||
spec_files = @spec_files
|
||||
spec_files = @spec_files_or_proc
|
||||
spec_files = spec_files.call if spec_files.respond_to?(:call)
|
||||
|
||||
body = ERB.new(File.read(File.join(File.dirname(__FILE__), "run.html"))).result(binding)
|
||||
[
|
||||
200,
|
||||
|
@ -38,11 +38,11 @@ module Jasmine
|
|||
end
|
||||
|
||||
class SimpleServer
|
||||
def self.start(port, spec_dir, mappings)
|
||||
def self.start(port, spec_files_or_proc, mappings)
|
||||
require 'thin'
|
||||
|
||||
config = {
|
||||
'/run.html' => Jasmine::RunAdapter.new(spec_dir)
|
||||
'/run.html' => Jasmine::RunAdapter.new(spec_files_or_proc)
|
||||
}
|
||||
mappings.each do |from, to|
|
||||
config[from] = Rack::File.new(to)
|
||||
|
@ -50,7 +50,6 @@ module Jasmine
|
|||
|
||||
app = Rack::URLMap.new(config)
|
||||
|
||||
server_port = Jasmine::find_unused_port
|
||||
Thin::Server.start('0.0.0.0', port, app)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
require 'spec'
|
||||
require 'open-uri'
|
||||
require File.dirname(__FILE__) + '/jasmine_runner'
|
||||
|
||||
describe Jasmine::SimpleServer do
|
||||
before do
|
||||
@port = Jasmine::find_unused_port
|
||||
end
|
||||
|
||||
after do
|
||||
Process.kill "TERM", -@jasmine_server_pid if @jasmine_server_pid
|
||||
end
|
||||
|
||||
it "should start and print script tags" do
|
||||
@jasmine_server_pid = fork do
|
||||
Process.setpgrp
|
||||
Jasmine::SimpleServer.start(@port, ["file1", "file2"], {})
|
||||
exit! 0
|
||||
end
|
||||
|
||||
Jasmine::Runner.new(nil, nil, nil).wait_for_listener(@port)
|
||||
|
||||
run_html = open("http://localhost:#{@port}/run.html").read
|
||||
run_html.should =~ /<script src="file1"/
|
||||
run_html.should =~ /<script src="file2"/
|
||||
end
|
||||
|
||||
it "should take a proc that returns a list of spec files" do
|
||||
spec_fileses = [["file1", "file2"], ["file1", "file2", "file3"]]
|
||||
spec_files_proc = lambda do
|
||||
spec_fileses.shift
|
||||
end
|
||||
|
||||
@jasmine_server_pid = fork do
|
||||
Process.setpgrp
|
||||
Jasmine::SimpleServer.start(@port, spec_files_proc, {})
|
||||
exit! 0
|
||||
end
|
||||
|
||||
Jasmine::Runner.new(nil, nil, nil).wait_for_listener(@port)
|
||||
|
||||
run_html = open("http://localhost:#{@port}/run.html").read
|
||||
run_html.should =~ /<script src="file1"/
|
||||
run_html.should =~ /<script src="file2"/
|
||||
|
||||
run_html = open("http://localhost:#{@port}/run.html").read
|
||||
run_html.should =~ /<script src="file1"/
|
||||
run_html.should =~ /<script src="file2"/
|
||||
run_html.should =~ /<script src="file3"/
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue