From 603ba69f773115b8a01284ed4525e3e0f2d0215d Mon Sep 17 00:00:00 2001 From: John Bintz Date: Fri, 6 May 2011 14:05:15 -0400 Subject: [PATCH 01/10] start factoring out some things --- bin/jasmine-headless-webkit | 14 ++++++------ lib/jasmine/cli.rb | 17 ++++++++++++++ spec/lib/jasmine/cli_spec.rb | 44 ++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 7 deletions(-) create mode 100644 lib/jasmine/cli.rb create mode 100644 spec/lib/jasmine/cli_spec.rb diff --git a/bin/jasmine-headless-webkit b/bin/jasmine-headless-webkit index a0a75ce..2107c55 100755 --- a/bin/jasmine-headless-webkit +++ b/bin/jasmine-headless-webkit @@ -1,9 +1,16 @@ #!/usr/bin/env ruby +gem_dir = File.expand_path('../..', __FILE__) +$:.unshift(File.join(gem_dir, 'lib')) + require 'yaml' require 'fileutils' require 'getoptlong' +require 'jasmine/cli' + +include Jasmine::CLI + opts = GetoptLong.new( [ '--colors', '-c', GetoptLong::NO_ARGUMENT ], [ '--no-colors', GetoptLong::NO_ARGUMENT ] @@ -28,7 +35,6 @@ end opts.each(&process_options) data = YAML.load_file(ARGV.shift || 'spec/javascripts/support/jasmine.yml') -gem_dir = File.expand_path('../..', __FILE__) if !File.file?(File.join(gem_dir, 'ext/jasmine-webkit-specrunner/jasmine-webkit-specrunner')) puts "The Qt WebKit widget is not compiled! Try re-installing this gem." @@ -43,12 +49,6 @@ files = [ 'file://' + File.join(gem_dir, 'jasmine/lib/jasmine.css') ] -DEFAULTS = { - 'spec_files' => [ '**/*[sS]pec.js' ], - 'helpers' => [ 'helpers/**/*.js' ], - 'spec_dir' => 'spec/javascripts' -} - files += [ [ 'src_files', 'src_dir' ], [ 'stylesheets', 'src_dir' ], [ 'helpers', 'spec_dir' ], [ 'spec_files', 'spec_dir' ] ].collect do |searches, root| data[searches] ||= DEFAULTS[searches] data[root] ||= DEFAULTS[root] diff --git a/lib/jasmine/cli.rb b/lib/jasmine/cli.rb new file mode 100644 index 0000000..dd5d761 --- /dev/null +++ b/lib/jasmine/cli.rb @@ -0,0 +1,17 @@ +module Jasmine + module CLI + DEFAULTS = { + 'spec_files' => [ '**/*[sS]pec.js' ], + 'helpers' => [ 'helpers/**/*.js' ], + 'spec_dir' => 'spec/javascripts', + 'src_dir' => '', + 'stylesheets' => [], + 'src_files' => [] + } + + def process_jasmine_config(overrides = {}) + DEFAULTS.merge(overrides) + end + end +end + diff --git a/spec/lib/jasmine/cli_spec.rb b/spec/lib/jasmine/cli_spec.rb new file mode 100644 index 0000000..62322c9 --- /dev/null +++ b/spec/lib/jasmine/cli_spec.rb @@ -0,0 +1,44 @@ +require 'spec_helper' +require 'jasmine/cli' + +describe Jasmine::CLI do + include Jasmine::CLI + + describe '#process_jasmine_config' do + context 'without overrides' do + let(:config) { {} } + + it "should just return the defaults" do + process_jasmine_config(config).should == { + 'src_files' => [], + 'stylesheets' => [], + 'helpers' => [ 'helpers/**/*.js' ], + 'spec_files' => [ '**/*[sS]pec.js' ], + 'src_dir' => '', + 'spec_dir' => 'spec/javascripts' + } + end + end + + context 'with overrides' do + let(:config) { + { + 'src_files' => [ 'one', 'two' ], + 'src_dir' => 'this-dir', + 'stylesheets' => [ 'three', 'four' ], + 'helpers' => [ 'five', 'six' ], + 'spec_files' => [ 'seven', 'eight' ], + 'spec_dir' => 'that-dir' + } + } + + it "should return the merged data" do + process_jasmine_config(config).should == config + end + end + end + + describe '#get_files' do + + end +end From d24e41198c3b741d302a07050eafa8f5fb7e55bf Mon Sep 17 00:00:00 2001 From: John Bintz Date: Fri, 6 May 2011 14:16:25 -0400 Subject: [PATCH 02/10] remove our distribution of jasmine and use the gem --- .gitmodules | 3 --- bin/jasmine-headless-webkit | 10 +++++++--- jasmine | 1 - jasmine-headless-webkit.gemspec | 1 + lib/jasmine/cli.rb | 2 +- spec/lib/jasmine/cli_spec.rb | 2 +- 6 files changed, 10 insertions(+), 9 deletions(-) delete mode 100644 .gitmodules delete mode 160000 jasmine diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 71ef4f1..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "jasmine"] - path = jasmine - url = https://github.com/pivotal/jasmine.git diff --git a/bin/jasmine-headless-webkit b/bin/jasmine-headless-webkit index 2107c55..edcad4e 100755 --- a/bin/jasmine-headless-webkit +++ b/bin/jasmine-headless-webkit @@ -7,6 +7,8 @@ require 'yaml' require 'fileutils' require 'getoptlong' +require 'rubygems' +require 'jasmine' require 'jasmine/cli' include Jasmine::CLI @@ -44,9 +46,8 @@ end puts "Running Jasmine specs..." files = [ - 'file://' + File.join(gem_dir, 'jasmine/lib/jasmine.js'), - 'file://' + File.join(gem_dir, 'jasmine/lib/jasmine-html.js'), - 'file://' + File.join(gem_dir, 'jasmine/lib/jasmine.css') + 'file://' + File.join(Jasmine.root, 'lib/jasmine.js'), + 'file://' + File.join(Jasmine.root, 'lib/jasmine-html.js'), ] files += [ [ 'src_files', 'src_dir' ], [ 'stylesheets', 'src_dir' ], [ 'helpers', 'spec_dir' ], [ 'spec_files', 'spec_dir' ] ].collect do |searches, root| @@ -57,11 +58,14 @@ files += [ [ 'src_files', 'src_dir' ], [ 'stylesheets', 'src_dir' ], [ 'helpers' data[searches].collect do |search| path = search path = File.join(data[root], path) if data[root] + p path Dir[path] end end end +p files + files = files.flatten.compact.collect { |file| case File.extname(file) when '.js' diff --git a/jasmine b/jasmine deleted file mode 160000 index e826fbb..0000000 --- a/jasmine +++ /dev/null @@ -1 +0,0 @@ -Subproject commit e826fbb17088f9e31a570ac4e09a738592af7b30 diff --git a/jasmine-headless-webkit.gemspec b/jasmine-headless-webkit.gemspec index ced024c..47020bd 100644 --- a/jasmine-headless-webkit.gemspec +++ b/jasmine-headless-webkit.gemspec @@ -21,4 +21,5 @@ Gem::Specification.new do |s| s.require_paths = ["lib"] s.add_dependency 'jasmine' + s.add_dependency 'coffee-script-source' end diff --git a/lib/jasmine/cli.rb b/lib/jasmine/cli.rb index dd5d761..1d38187 100644 --- a/lib/jasmine/cli.rb +++ b/lib/jasmine/cli.rb @@ -4,7 +4,7 @@ module Jasmine 'spec_files' => [ '**/*[sS]pec.js' ], 'helpers' => [ 'helpers/**/*.js' ], 'spec_dir' => 'spec/javascripts', - 'src_dir' => '', + 'src_dir' => nil, 'stylesheets' => [], 'src_files' => [] } diff --git a/spec/lib/jasmine/cli_spec.rb b/spec/lib/jasmine/cli_spec.rb index 62322c9..4296b9e 100644 --- a/spec/lib/jasmine/cli_spec.rb +++ b/spec/lib/jasmine/cli_spec.rb @@ -14,7 +14,7 @@ describe Jasmine::CLI do 'stylesheets' => [], 'helpers' => [ 'helpers/**/*.js' ], 'spec_files' => [ '**/*[sS]pec.js' ], - 'src_dir' => '', + 'src_dir' => nil, 'spec_dir' => 'spec/javascripts' } end From 4b92891cc7f4854bd1058178c00faddff5175ea2 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Fri, 6 May 2011 14:18:14 -0400 Subject: [PATCH 03/10] remove debugging info --- bin/jasmine-headless-webkit | 3 --- 1 file changed, 3 deletions(-) diff --git a/bin/jasmine-headless-webkit b/bin/jasmine-headless-webkit index edcad4e..72f7c05 100755 --- a/bin/jasmine-headless-webkit +++ b/bin/jasmine-headless-webkit @@ -58,14 +58,11 @@ files += [ [ 'src_files', 'src_dir' ], [ 'stylesheets', 'src_dir' ], [ 'helpers' data[searches].collect do |search| path = search path = File.join(data[root], path) if data[root] - p path Dir[path] end end end -p files - files = files.flatten.compact.collect { |file| case File.extname(file) when '.js' From 8d029883811b3b6c8f16c32a20fdf738e1cfa0b8 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Fri, 6 May 2011 14:24:46 -0400 Subject: [PATCH 04/10] inline coffeescript support via coffee-script-source --- bin/jasmine-headless-webkit | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/bin/jasmine-headless-webkit b/bin/jasmine-headless-webkit index 72f7c05..48b4885 100755 --- a/bin/jasmine-headless-webkit +++ b/bin/jasmine-headless-webkit @@ -8,7 +8,13 @@ require 'fileutils' require 'getoptlong' require 'rubygems' + +gem 'jasmine' +gem 'coffee-script-source' + require 'jasmine' +require 'coffee_script/source' + require 'jasmine/cli' include Jasmine::CLI @@ -48,6 +54,7 @@ puts "Running Jasmine specs..." files = [ 'file://' + File.join(Jasmine.root, 'lib/jasmine.js'), 'file://' + File.join(Jasmine.root, 'lib/jasmine-html.js'), + 'file://' + CoffeeScript::Source.bundled_path, ] files += [ [ 'src_files', 'src_dir' ], [ 'stylesheets', 'src_dir' ], [ 'helpers', 'spec_dir' ], [ 'spec_files', 'spec_dir' ] ].collect do |searches, root| @@ -67,6 +74,8 @@ files = files.flatten.compact.collect { |file| case File.extname(file) when '.js' %{} + when '.coffee' + %{} when '.css' %{} end From 37862f096a8017361812e61e0137f8b37a5843d7 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Fri, 6 May 2011 15:34:12 -0400 Subject: [PATCH 05/10] update readme for coffeescript info --- README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/README.md b/README.md index 8e8d19a..182415e 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,23 @@ Current supported options: These options can also be placed into a `.jasmine-headless-webkit` file in your project root. +### CoffeeScript Support + +`jasmine-headless-webkit` brings in the `coffee-script-source` gem and allows you to run CoffeeScript +files without needing compilation. It uses [the `} when '.coffee' - %{} + %{} when '.css' %{} end diff --git a/jasmine-headless-webkit.gemspec b/jasmine-headless-webkit.gemspec index 47020bd..da6959c 100644 --- a/jasmine-headless-webkit.gemspec +++ b/jasmine-headless-webkit.gemspec @@ -21,5 +21,5 @@ Gem::Specification.new do |s| s.require_paths = ["lib"] s.add_dependency 'jasmine' - s.add_dependency 'coffee-script-source' + s.add_dependency 'coffee-script' end diff --git a/lib/autotest/jasmine_mixin.rb b/lib/autotest/jasmine_mixin.rb index 64f8fb8..71e73b5 100644 --- a/lib/autotest/jasmine_mixin.rb +++ b/lib/autotest/jasmine_mixin.rb @@ -1,7 +1,7 @@ module JasmineMixin JASMINE_PROGRAM = File.expand_path('../../../bin/jasmine-headless-webkit', __FILE__) - JAVASCRIPT_EXTENSIONS = %w{js} + JAVASCRIPT_EXTENSIONS = %w{js coffee} def self.included(klass) klass::ALL_HOOKS << [ :run_jasmine, :ran_jasmine ] @@ -81,12 +81,16 @@ module JasmineMixin end def setup_jasmine_project_mappings - add_mapping(%r{spec/javascripts/.*_spec\.js}) { |filename, _| + add_mapping(%r{spec/javascripts/.*_spec\.(js|coffee)}) { |filename, _| filename } add_mapping(%r{public/javascripts/(.*)\.js}) { |_, m| - [ "spec/javascripts/#{m[1]}_spec.js" ] + files_matching(%{spec/javascripts/#{m[1]}_spec\..*$}) + } + + add_mapping(%r{app/coffeescripts/(.*)\.coffee}) { |_, m| + files_matching(%{spec/javascripts/#{m[1]}_spec\..*$}) } end From c1beb74a9f79a5d4bdf1950b5ffa91b7ca15cf9e Mon Sep 17 00:00:00 2001 From: John Bintz Date: Sat, 7 May 2011 09:16:23 -0400 Subject: [PATCH 09/10] autotest fixes --- lib/autotest/jasmine_mixin.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/autotest/jasmine_mixin.rb b/lib/autotest/jasmine_mixin.rb index 71e73b5..b501924 100644 --- a/lib/autotest/jasmine_mixin.rb +++ b/lib/autotest/jasmine_mixin.rb @@ -86,11 +86,11 @@ module JasmineMixin } add_mapping(%r{public/javascripts/(.*)\.js}) { |_, m| - files_matching(%{spec/javascripts/#{m[1]}_spec\..*$}) + files_matching(%r{spec/javascripts/#{m[1]}_spec\..*$}) } add_mapping(%r{app/coffeescripts/(.*)\.coffee}) { |_, m| - files_matching(%{spec/javascripts/#{m[1]}_spec\..*$}) + files_matching(%r{spec/javascripts/#{m[1]}_spec\..*$}) } end From 8bfd8f8bd0bb0b904077c55c0b210178138a5b36 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Sat, 7 May 2011 09:17:26 -0400 Subject: [PATCH 10/10] remove debug code --- lib/autotest/jasmine_mixin.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/autotest/jasmine_mixin.rb b/lib/autotest/jasmine_mixin.rb index b501924..fb6d079 100644 --- a/lib/autotest/jasmine_mixin.rb +++ b/lib/autotest/jasmine_mixin.rb @@ -31,6 +31,16 @@ module JasmineMixin reset_jasmine(:all) end + def rerun_all_tests + reset_jasmine(:no) + super + + reset_jasmine(:yes) + run_jasmine + + reset_jasmine(:all) + end + def reset_jasmine(method) self.files_to_test = new_hash_of_arrays self.is_jasmine_running = method