From 59c85355fc311c76a56707dc0f1baa011c8219e2 Mon Sep 17 00:00:00 2001 From: Christian Williams Date: Mon, 28 Dec 2009 14:26:30 -0600 Subject: [PATCH] More changes, specs. --- lib/jasmine/config.rb | 16 ++++++++++++++++ lib/jasmine/run.html | 8 ++------ lib/jasmine/server.rb | 19 ++++++------------- spec/server_spec.rb | 7 ++++++- 4 files changed, 30 insertions(+), 20 deletions(-) diff --git a/lib/jasmine/config.rb b/lib/jasmine/config.rb index 3b64237..eb5bacc 100644 --- a/lib/jasmine/config.rb +++ b/lib/jasmine/config.rb @@ -70,5 +70,21 @@ module Jasmine def mappings raise "You need to declare a mappings method in #{self.class}!" end + + def stylesheets + [] + end + + def src_files + [] + end + + def spec_files + raise "You need to declare a spec_files method in #{self.class}!" + end + + def js_files + src_files + spec_files + end end end \ No newline at end of file diff --git a/lib/jasmine/run.html b/lib/jasmine/run.html index 9f0ecd0..80a200c 100644 --- a/lib/jasmine/run.html +++ b/lib/jasmine/run.html @@ -11,10 +11,6 @@ <% end %> - <% spec_helpers.each do |spec_helper| %> - - <% end %> - - <% spec_files.each do |spec_file| %> - + <% js_files.each do |js_file| %> + <% end %> diff --git a/lib/jasmine/server.rb b/lib/jasmine/server.rb index 3844d8a..3d79eb6 100644 --- a/lib/jasmine/server.rb +++ b/lib/jasmine/server.rb @@ -1,15 +1,14 @@ module Jasmine class RunAdapter - def initialize(spec_files_or_proc, options = {}) - @spec_files_or_proc = Jasmine.files(spec_files_or_proc) || [] - @jasmine_files = Jasmine.files(options[:jasmine_files]) || [ + def initialize(config) + @config = config + @jasmine_files = [ "/__JASMINE_ROOT__/lib/" + File.basename(Dir.glob("#{Jasmine.root}/lib/jasmine*.js").first), "/__JASMINE_ROOT__/lib/TrivialReporter.js", "/__JASMINE_ROOT__/lib/json2.js", "/__JASMINE_ROOT__/lib/consolex.js", ] - @stylesheets = ["/__JASMINE_ROOT__/lib/jasmine.css"] + (Jasmine.files(options[:stylesheets]) || []) - @spec_helpers = Jasmine.files(options[:spec_helpers]) || [] + @jasmine_stylesheets = ["/__JASMINE_ROOT__/lib/jasmine.css"] end def call(env) @@ -17,15 +16,9 @@ module Jasmine end def run - stylesheets = @stylesheets - spec_helpers = @spec_helpers - spec_files = @spec_files_or_proc - jasmine_files = @jasmine_files - jasmine_files = jasmine_files.call if jasmine_files.respond_to?(:call) - - css_files = @stylesheets - + css_files = @jasmine_stylesheets + (Jasmine.files(@config.stylesheets) || []) + js_files = Jasmine.files(@config.js_files) body = ERB.new(File.read(File.join(File.dirname(__FILE__), "run.html"))).result(binding) [ diff --git a/spec/server_spec.rb b/spec/server_spec.rb index 363feef..f022b0e 100644 --- a/spec/server_spec.rb +++ b/spec/server_spec.rb @@ -15,6 +15,8 @@ describe Jasmine::Server do "/spec" => File.join(Jasmine.root, "spec") }) + config.stub!(:js_files).and_return(["/src/file1.js", "/spec/file2.js"]) + @server = Jasmine::Server.new(0, config) @thin_app = @server.thin.app end @@ -45,7 +47,10 @@ describe Jasmine::Server do it "should serve /" do code, headers, body = @thin_app.call("PATH_INFO" => "/", "SCRIPT_NAME" => "xxx") + code.should == 200 body = read(body) - p body + body.should include("\"/src/file1.js") + body.should include("\"/spec/file2.js") + body.should satisfy {|s| s.index("/src/file1.js") < s.index("/spec/file2.js") } end end \ No newline at end of file