diff --git a/config/cucumber.yml b/config/cucumber.yml deleted file mode 100644 index a061551..0000000 --- a/config/cucumber.yml +++ /dev/null @@ -1,2 +0,0 @@ -default: -r features - diff --git a/ext/jasmine-webkit-specrunner/Runner.cpp b/ext/jasmine-webkit-specrunner/Runner.cpp index 66943a5..39941d8 100644 --- a/ext/jasmine-webkit-specrunner/Runner.cpp +++ b/ext/jasmine-webkit-specrunner/Runner.cpp @@ -71,9 +71,7 @@ void Runner::loadSpec() outputFiles.enqueue(outputFile); } - QString runnerFile = runnerFiles.dequeue(); - - page.mainFrame()->load(runnerFile); + page.mainFrame()->load(QUrl::fromLocalFile(runnerFiles.dequeue())); ticker.start(); } diff --git a/ext/jasmine-webkit-specrunner/Runner.h b/ext/jasmine-webkit-specrunner/Runner.h index 3f1f01b..8d7269e 100644 --- a/ext/jasmine-webkit-specrunner/Runner.h +++ b/ext/jasmine-webkit-specrunner/Runner.h @@ -7,9 +7,7 @@ #include #include #include -#include #include -#include #include "Page.h" diff --git a/ext/jasmine-webkit-specrunner/jasmine-webkit-specrunner.pro b/ext/jasmine-webkit-specrunner/jasmine-webkit-specrunner.pro new file mode 100644 index 0000000..e6710d1 --- /dev/null +++ b/ext/jasmine-webkit-specrunner/jasmine-webkit-specrunner.pro @@ -0,0 +1,19 @@ +###################################################################### +# Automatically generated by qmake (2.01a) Tue Aug 2 10:37:48 2011 +###################################################################### + +TEMPLATE = app +TARGET = +DEPENDPATH += . HeadlessSpecRunner Test +INCLUDEPATH += . HeadlessSpecRunner Test + +# Input +HEADERS += HeadlessSpecRunner/ConsoleOutput.h \ + HeadlessSpecRunner/Page.h \ + HeadlessSpecRunner/Runner.h \ + Test/Page_test.h +SOURCES += specrunner.cpp \ + HeadlessSpecRunner/ConsoleOutput.cpp \ + HeadlessSpecRunner/Page.cpp \ + HeadlessSpecRunner/Runner.cpp \ + Test/Page_test.cpp diff --git a/features/bin/with_server.feature b/features/bin/with_server.feature deleted file mode 100644 index 6e9fa03..0000000 --- a/features/bin/with_server.feature +++ /dev/null @@ -1,7 +0,0 @@ -Feature: Bin - With Server - Scenario: Run using an HTTP server - Given there is no existing "spec/report.txt" file - When I run `bin/jasmine-headless-webkit --use-server -j spec/jasmine/success/success.yml -f File:spec/report.txt` - Then the exit status should be 0 - And the report file "spec/report.txt" should have 1 total, 0 failures, no console usage - diff --git a/lib/jasmine/headless/files_list.rb b/lib/jasmine/headless/files_list.rb index eef115a..7844c7f 100644 --- a/lib/jasmine/headless/files_list.rb +++ b/lib/jasmine/headless/files_list.rb @@ -38,6 +38,7 @@ module Jasmine::Headless def reset! @asset_paths = nil + @registered_engines = {} # register haml-sprockets and handlebars_assets if it's available... %w{haml-sprockets handlebars_assets}.each do |library| @@ -67,6 +68,21 @@ module Jasmine::Headless register_engine '.css', Jasmine::Headless::CSSTemplate register_engine '.jst', Jasmine::Headless::JSTTemplate end + + end + + def registered_engines + @registered_engines ||= {} + end + + def register_engine(file_extension, template_class) + registered_engines[file_extension] = template_class + end + + def register_engines! + registered_engines.each do |file_extension, template_class| + Sprockets.register_engine file_extension, template_class + end end def default_files @@ -95,11 +111,21 @@ module Jasmine::Headless @required_files = UniqueAssetList.new @potential_files_to_filter = [] + register_engines! + load_initial_assets use_config if config? end + def register_engines! + begin + require spec_helper + rescue LoadError + end + self.class.register_engines! + end + def load_initial_assets self.class.default_files.each do |file| begin @@ -301,5 +327,17 @@ module Jasmine::Headless end end end + + def spec_helper + File.join(spec_dir, "helpers", "spec_helper") + end end end + +module Jasmine::Headless + extend self + + def register_engine(file_extension, template_class) + Jasmine::Headless::FilesList.register_engine(file_extension, template_class) + end +end \ No newline at end of file diff --git a/lib/jasmine/headless/options.rb b/lib/jasmine/headless/options.rb index 53719c0..49e8202 100644 --- a/lib/jasmine/headless/options.rb +++ b/lib/jasmine/headless/options.rb @@ -18,9 +18,7 @@ module Jasmine :enable_cache => true, :files => [], :reporters => [ [ 'Console' ] ], - :quiet => false, - :use_server => false, - :server_port => nil + :quiet => false } DEFAULTS_FILE = File.join(Dir.pwd, '.jasmine-headless-webkit') @@ -77,10 +75,6 @@ module Jasmine @options[:seed] = arg.to_i when '--format', '-f' add_reporter(arg) - when '--use-server' - @options[:use_server] = true - when '--server-port' - @options[:server_port] = arg.to_i when '--out' add_reporter_file(arg) when '-h', '--help' @@ -113,8 +107,6 @@ module Jasmine [ '--seed', GetoptLong::REQUIRED_ARGUMENT ], [ '--format', '-f', GetoptLong::REQUIRED_ARGUMENT ], [ '--out', GetoptLong::REQUIRED_ARGUMENT ], - [ '--use-server', GetoptLong::NO_ARGUMENT ], - [ '--server-port', GetoptLong::REQUIRED_ARGUMENT ], [ '-h', '--help', GetoptLong::NO_ARGUMENT ], [ '-q', '--quiet', GetoptLong::NO_ARGUMENT ] ) @@ -173,9 +165,8 @@ module Jasmine [ '--runner-out ', 'Write runner to specified filename' ], [ '-j, --jasmine-config ', 'Jasmine Yaml config to use' ], [ '--no-full-run', 'Do not perform a full spec run after a successful targeted spec run' ], - [ '--use-server', 'Load tests from an HTTP server instead of from filesystem' ], [ '-l, --list', 'List files in the order they will be required' ], - [ '--seed ', 'Random order seed for spec file ordering' ], + [ '--seed', 'Random order seed for spec file ordering' ], [ '-f, --format >', 'Specify an output reporter and possibly output filename' ], [ '--out ', 'Specify output filename for last defined reporter' ], [ '-q, --quiet', "Silence most non-test related warnings" ], diff --git a/lib/jasmine/headless/runner.rb b/lib/jasmine/headless/runner.rb index 3ce7247..fdb4b5f 100644 --- a/lib/jasmine/headless/runner.rb +++ b/lib/jasmine/headless/runner.rb @@ -7,26 +7,9 @@ require 'yaml' require 'erb' require 'sprockets' + module Jasmine module Headless - class IndexHandler - class << self - attr_accessor :index - end - - def initialize(app) - @app = app - end - - def call(env) - if env['PATH_INFO'] == '/' - return [ 302, { 'Location' => self.class.index }, [ 'Redirecting...' ] ] - end - - @app.call(env) - end - end - class Runner JASMINE_DEFAULTS = { 'spec_files' => [ '**/*[sS]pec.js' ], @@ -43,103 +26,9 @@ module Jasmine attr_reader :options - def self.run(options = {}) - new(options).run - end - - def self.server_port - return @server_port if @server_port - - require 'socket' - - count = 100 - begin - port = select_server_port - - socket = TCPSocket.new(server_interface, port) - socket.close - - count -= 1 - - raise "Could not create server port after 100 attempts!" if count == 0 - rescue Errno::ECONNREFUSED - @server_port = port - - break - ensure - begin - socket.close if socket - rescue IOError - end - end while true - - @server_port - end - - def self.server_port=(port) - @server_port = port - end - - def self.select_server_port - 21000 + rand(10000) - end - - def self.server_interface - '127.0.0.1' - end - - def self.server_uri - "http://#{server_interface}:#{server_port}" - end - - def self.server_spec_path - self.server_uri + '/__JHW__/' - end - - def self.ensure_server(options) - return if @server - - require 'webrick' - require 'thread' - require 'rack' - require 'net/http' - - port = server_port - - @server = Thread.new do - Jasmine::Headless.warn "Powering up!" - - app = Rack::Builder.new do - use IndexHandler - - map '/__JHW__' do - run Rack::File.new(Dir.pwd) - end - - map '/' do - run Rack::File.new('/') - end - end - - Rack::Handler::WEBrick.run( - app, - :Port => port, - :Logger => Logger.new(StringIO.new), - :AccessLog => [ - [ StringIO.new, WEBrick::AccessLog::COMMON_LOG_FORMAT ], - [ StringIO.new, WEBrick::AccessLog::REFERER_LOG_FORMAT ] - ] - ) - end - - while true do - begin - Net::HTTP.get(URI(server_uri)) - break - rescue Errno::ECONNREFUSED => e - end - - sleep 0.1 + class << self + def run(options = {}) + new(options).run end end @@ -174,7 +63,8 @@ module Jasmine command << "-r #{file}" end - command += targets + command += targets.flatten.collect { |target| File.expand_path(target) } + command.compact.join(' ') end @@ -183,11 +73,9 @@ module Jasmine Jasmine::Headless.show_warnings = !@options[:quiet] FilesList.reset! - self.class.server_port = options[:server_port] - @_targets = template_writer.write - run_targets = absolute_run_targets(@_targets.dup) + run_targets = @_targets.dup if run_targets.length == 2 if (!@options[:full_run] && files_list.filtered?) || files_list.has_spec_outside_scope? @@ -195,13 +83,7 @@ module Jasmine end end - runner = lambda { system jasmine_command(run_targets) } - - if options[:use_server] - wrap_in_server(run_targets, &runner) - else - runner.call - end + system jasmine_command(run_targets) @_status = $?.exitstatus ensure @@ -210,17 +92,6 @@ module Jasmine end end - def absolute_run_targets(targets) - targets.flatten.collect do |target| - if options[:use_server] - target = self.class.server_spec_path + target - else - target = "file://" + File.expand_path(target) - end - target - end - end - def runner_filename options[:runner_output_filename] || begin if (runner_output = jasmine_config['runner_output']) && !runner_output.empty? @@ -240,15 +111,6 @@ module Jasmine ) end - def wrap_in_server(run_targets) - self.class.ensure_server(options) - IndexHandler.index = run_targets.last - - Jasmine::Headless.warn "HTTP powered specs! Located at #{run_targets.join(' ')}" - - yield - end - private def jasmine_config_data raise JasmineConfigNotFound.new("Jasmine config not found. I tried #{@options[:jasmine_config]}.") if !File.file?(@options[:jasmine_config]) diff --git a/lib/jasmine/headless/template_writer.rb b/lib/jasmine/headless/template_writer.rb index 81562a5..cbc5ac4 100644 --- a/lib/jasmine/headless/template_writer.rb +++ b/lib/jasmine/headless/template_writer.rb @@ -24,9 +24,7 @@ module Jasmine::Headless output.unshift([filtered_tests_filename, files_list.filtered_files_to_html ]) if files_list.filtered? output.each do |name, files| - template = template_for(files) - - File.open(name, 'wb') { |fh| fh.print template } + File.open(name, 'w') { |fh| fh.print template_for(files) } end output.collect(&:first) diff --git a/skel/template.html.erb b/skel/template.html.erb index e3ba9ff..c02247b 100644 --- a/skel/template.html.erb +++ b/skel/template.html.erb @@ -34,35 +34,6 @@ break; } } - - var getLastModified = function(callback) { - var http = new XMLHttpRequest(); - var header; - - http.open('HEAD', window.location.href, false); - - http.onreadystatechange = function() { - callback(http.getResponseHeader('Last-Modified')); - }; - http.send(); - } - - getLastModified(function(currentLastModified) { - var checker; - checker = function() { - setTimeout(function() { - getLastModified(function(newLastModified) { - if (currentLastModified != newLastModified) { - setTimeout(function() { window.location.reload(); }, 1000); - } else { - checker(); - } - }); - }, 3000); - }; - - checker(); - }); } jasmine.getEnv().execute(); diff --git a/spec/lib/jasmine/headless/files_list_spec.rb b/spec/lib/jasmine/headless/files_list_spec.rb index bd24076..6bddb71 100644 --- a/spec/lib/jasmine/headless/files_list_spec.rb +++ b/spec/lib/jasmine/headless/files_list_spec.rb @@ -218,6 +218,21 @@ describe Jasmine::Headless::FilesList do files_list.files.any? { |file| file['.erb'] }.should be_false end end + + describe "#register_engine!" do + + before(:each) do + Jasmine::Headless::FilesList.reset! + end + + it "should register code added via configure blocks" do + template_class = mock() + described_class.register_engine ".foo", template_class + Sprockets.expects(:register_engine).with(".foo", template_class) + described_class.new + end + + end end end diff --git a/spec/lib/jasmine/headless/runner_spec.rb b/spec/lib/jasmine/headless/runner_spec.rb index b042d95..dcd4650 100644 --- a/spec/lib/jasmine/headless/runner_spec.rb +++ b/spec/lib/jasmine/headless/runner_spec.rb @@ -194,54 +194,4 @@ describe Jasmine::Headless::Runner do subject.options[:reporters].should == reporters end end - - describe '.server_port' do - before do - described_class.instance_variable_set(:@server_port, nil) - end - - context 'port in use' do - require 'socket' - - before do - described_class.stubs(:select_server_port).returns(5000, 5001) - end - - it 'should try another port' do - server = TCPServer.new(described_class.server_interface, 5000) - - described_class.server_port.should == 5001 - end - end - end - - describe '#absolute_run_targets' do - let(:opts) { {} } - - subject { runner.absolute_run_targets(targets) } - - let(:targets) { [ target ] } - let(:target) { 'target' } - - before do - runner.stubs(:options).returns(:use_server => use_server) - end - - context 'server' do - let(:use_server) { true } - let(:server_spec_path) { 'server spec path' } - - before do - described_class.stubs(:server_spec_path).returns(server_spec_path) - end - - it { should == [ server_spec_path + target ] } - end - - context 'no server' do - let(:use_server) { false } - - it { should == [ 'file://' + File.expand_path(target) ] } - end - end end diff --git a/vendor/assets/coffeescripts/prolog.coffee b/vendor/assets/coffeescripts/prolog.coffee index a1fcd2e..078be7c 100644 --- a/vendor/assets/coffeescripts/prolog.coffee +++ b/vendor/assets/coffeescripts/prolog.coffee @@ -80,18 +80,15 @@ if window.JHW puts msg JHW.createCoffeeScriptFileException = (e) -> - if e and e.sourceURL + if e and e.sourceURL and window.CoffeeScriptToFilename filename = e.sourceURL.split('/').pop() - - e = - name: e.name - message: e.message - sourceURL: e.sourceURL - lineNumber: e.line - - if window.CoffeeScriptToFilename and realFilename = window.CoffeeScriptToFilename[filename] - e.sourceURL = realFilename - e.lineNumber = "~" + String(e.line) + if realFilename = window.CoffeeScriptToFilename[filename] + e = { + name: e.name, + message: e.message, + lineNumber: "~" + String(e.line), + sourceURL: realFilename + } e diff --git a/vendor/assets/javascripts/jasmine.HeadlessReporter.Verbose.coffee b/vendor/assets/javascripts/jasmine.HeadlessReporter.Verbose.coffee index 591796f..1d1d0b0 100644 --- a/vendor/assets/javascripts/jasmine.HeadlessReporter.Verbose.coffee +++ b/vendor/assets/javascripts/jasmine.HeadlessReporter.Verbose.coffee @@ -1,8 +1,6 @@ #= require jasmine.HeadlessReporter.ConsoleBase # class jasmine.HeadlessReporter.Verbose extends jasmine.HeadlessReporter.ConsoleBase - @prereport = false - displaySuccess: (spec) => this.displaySpec(spec, 'green') @@ -48,17 +46,12 @@ class jasmine.HeadlessReporter.Verbose extends jasmine.HeadlessReporter.ConsoleB colorLine: (line, color) => line.foreground(color) - reportSpecStarting: (spec) => - if jasmine.HeadlessReporter.Verbose.prereport - this.puts(spec.getSpecSplitName().join(' ')) - reportException: (e) => e = JHW.createCoffeeScriptFileException(e) - + + output = e.message if e.sourceURL && e.lineNumber - output = "#{e.sourceURL}:#{e.lineNumber} #{e.message}" - else - output = e.message ? e + output = "#{e.sourceURL}:~#{e.lineNumber} #{output}" this.puts(output.foreground('yellow')) diff --git a/vendor/assets/javascripts/prolog.js b/vendor/assets/javascripts/prolog.js index e977e42..3ada0bb 100644 --- a/vendor/assets/javascripts/prolog.js +++ b/vendor/assets/javascripts/prolog.js @@ -84,17 +84,15 @@ }; JHW.createCoffeeScriptFileException = function(e) { var filename, realFilename; - if (e && e.sourceURL) { + if (e && e.sourceURL && window.CoffeeScriptToFilename) { filename = e.sourceURL.split('/').pop(); - e = { - name: e.name, - message: e.message, - sourceURL: e.sourceURL, - lineNumber: e.line - }; - if (window.CoffeeScriptToFilename && (realFilename = window.CoffeeScriptToFilename[filename])) { - e.sourceURL = realFilename; - e.lineNumber = "~" + String(e.line); + if (realFilename = window.CoffeeScriptToFilename[filename]) { + e = { + name: e.name, + message: e.message, + lineNumber: "~" + String(e.line), + sourceURL: realFilename + }; } } return e;