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/README.md b/README.md index 8e8d19a..314f26f 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,22 @@ 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` gem and compiles & injects all CoffeeScript into the +generated HTML page. All you need to do is configure your `jasmine.yml` file to look for .coffee files: + + src_files: + - app/assets/javascripts/**/*.coffee + spec_files: + - **/*[sS]pec.coffee + +*(This will probably make it difficult to test your code in an official Jasmine server for now. You can try +[a technique like this](https://github.com/jbaudanza/rack-asset-compiler/blob/master/examples/jasmine_config.rb) for compiling CoffeeScript when it's requested from the server +or use [this fork of jasmine-gem](https://github.com/johnbintz/jasmine-gem/tree/coffeescript-inline-support) which +is thoroughly untested.)* + + ### JavaScript Dialogs You can call `alert()` and `confirm()` in your code. `alert()` will print the message to the console, and diff --git a/bin/jasmine-headless-webkit b/bin/jasmine-headless-webkit index a0a75ce..65b5885 100755 --- a/bin/jasmine-headless-webkit +++ b/bin/jasmine-headless-webkit @@ -1,9 +1,23 @@ #!/usr/bin/env ruby +gem_dir = File.expand_path('../..', __FILE__) +$:.unshift(File.join(gem_dir, 'lib')) + require 'yaml' require 'fileutils' require 'getoptlong' +require 'rubygems' + +gem 'jasmine' +gem 'coffee-script' + +require 'jasmine' +require 'coffee-script' + +require 'jasmine/cli' +include Jasmine::CLI + opts = GetoptLong.new( [ '--colors', '-c', GetoptLong::NO_ARGUMENT ], [ '--no-colors', GetoptLong::NO_ARGUMENT ] @@ -28,7 +42,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." @@ -38,17 +51,10 @@ 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') ] -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] @@ -66,6 +72,8 @@ files = files.flatten.compact.collect { |file| case File.extname(file) when '.js' %{} + when '.coffee' + %{} when '.css' %{} end 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..da6959c 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' end diff --git a/lib/autotest/jasmine_mixin.rb b/lib/autotest/jasmine_mixin.rb index c4edea8..fb6d079 100644 --- a/lib/autotest/jasmine_mixin.rb +++ b/lib/autotest/jasmine_mixin.rb @@ -1,17 +1,18 @@ 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 ] end - attr_accessor :is_jasmine_running, :jasmine_to_run + attr_accessor :is_jasmine_running, :jasmine_to_run, :jasmine_ran_once def initialize super() setup_jasmine_project_mappings + jasmine_ran_once = false end def get_to_green @@ -20,6 +21,7 @@ module JasmineMixin super if find_files_to_test reset_jasmine(:yes) + self.last_mtime = Time.at(0) if !options[:no_full_after_start] && !jasmine_ran_once run_jasmine if find_files_to_test self.is_jasmine_running = :all @@ -29,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 @@ -50,6 +62,8 @@ module JasmineMixin end hook :ran_jasmine + + jasmine_ran_once = true end def all_jasmine_good @@ -77,12 +91,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(%r{spec/javascripts/#{m[1]}_spec\..*$}) + } + + add_mapping(%r{app/coffeescripts/(.*)\.coffee}) { |_, m| + files_matching(%r{spec/javascripts/#{m[1]}_spec\..*$}) } end diff --git a/lib/jasmine/cli.rb b/lib/jasmine/cli.rb new file mode 100644 index 0000000..1d38187 --- /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' => nil, + '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..4296b9e --- /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' => nil, + '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