From b2571b4e3e8363e66a0cbc2d911199931c3caf41 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Wed, 11 May 2011 10:29:02 -0400 Subject: [PATCH] only run the provided specs --- README.md | 4 +++- bin/jasmine-headless-webkit | 8 +++++++- lib/jasmine/cli.rb | 4 ++++ spec/lib/jasmine/cli_spec.rb | 28 ++++++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index abbe71c..9b2d9c6 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ Let me know via a message or in the Issues section if it works on your setup and ## Usage - jasmine-headless-webkit [options] + jasmine-headless-webkit [options] [list of spec files to run] Current supported options: @@ -42,6 +42,8 @@ Current supported options: * `--keep` preserves the temporary HTML document if an error occurs in testing * `-j`/`--jasmine-config` sets the `jasmine.yml` file to load *(defaults to `spec/javascripts/support/jasmine.yml`)* +If provided, only the requested spec files will be executed. Otherwise, all matching specs will be run. + These options can also be placed into a `.jasmine-headless-webkit` file in your project root. ### CoffeeScript Support diff --git a/bin/jasmine-headless-webkit b/bin/jasmine-headless-webkit index 9e7bf80..6e7d154 100755 --- a/bin/jasmine-headless-webkit +++ b/bin/jasmine-headless-webkit @@ -51,6 +51,8 @@ options = { read_defaults_file if defaults_file? opts.each(&@process_options) +@spec_filter = ARGV.dup + data = YAML.load_file(options[:jasmine_config]) if !File.file?(File.join(gem_dir, RUNNER)) @@ -70,7 +72,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] - Dir[path] + files = Dir[path] + if searches == 'spec_files' + files = files.find_all { |file| use_spec?(file) } + end + files end end end diff --git a/lib/jasmine/cli.rb b/lib/jasmine/cli.rb index 4f4e3c6..95d688d 100644 --- a/lib/jasmine/cli.rb +++ b/lib/jasmine/cli.rb @@ -24,6 +24,10 @@ module Jasmine File.file?(DEFAULTS_FILE) end + def use_spec?(file) + @spec_filter.empty? || @spec_filter.include?(file) + end + def jasmine_html_template(files) <<-HTML diff --git a/spec/lib/jasmine/cli_spec.rb b/spec/lib/jasmine/cli_spec.rb index 5c4e340..0898f29 100644 --- a/spec/lib/jasmine/cli_spec.rb +++ b/spec/lib/jasmine/cli_spec.rb @@ -59,4 +59,32 @@ describe Jasmine::CLI do found.should be_true end end + + describe '#use_spec?' do + let(:spec_file) { 'my/spec.js' } + + context 'no filter provided' do + before do + @spec_filter = [] + end + + it "should allow the spec" do + use_spec?(spec_file).should be_true + end + end + + context 'filter provided' do + before do + @spec_filter = [ spec_file ] + end + + it "should use the spec" do + use_spec?(spec_file).should be_true + end + + it "should not use the spec" do + use_spec?('other/file').should be_false + end + end + end end