diff --git a/lib/jasmine/files_list.rb b/lib/jasmine/files_list.rb index ce97cef..a55480d 100644 --- a/lib/jasmine/files_list.rb +++ b/lib/jasmine/files_list.rb @@ -11,7 +11,7 @@ end module Jasmine class FilesList - attr_reader :files, :filtered_files + attr_reader :files, :filtered_files, :spec_outside_scope DEFAULT_FILES = [ File.join(Jasmine.root, "lib/jasmine.js"), @@ -23,11 +23,16 @@ module Jasmine @options = options @files = DEFAULT_FILES.dup @filtered_files = @files.dup + @spec_outside_scope = false use_config! if config? @code_for_file = {} end + def has_spec_outside_scope? + @spec_outside_scope + end + def use_spec?(file) spec_filter.empty? || spec_filter.include?(file) end @@ -114,10 +119,12 @@ module Jasmine @files += found_files - if searches == 'spec_files' - found_files = found_files.find_all { |file| use_spec?(file) } - end - @filtered_files += found_files + @filtered_files += (if searches == 'spec_files' + @spec_outside_scope = ((spec_filter | found_files).sort != found_files.sort) + spec_filter || found_files + else + found_files + end) end end end diff --git a/lib/jasmine/headless/runner.rb b/lib/jasmine/headless/runner.rb index 1eae6b4..04f9965 100644 --- a/lib/jasmine/headless/runner.rb +++ b/lib/jasmine/headless/runner.rb @@ -58,7 +58,7 @@ module Jasmine targets = Jasmine::TemplateWriter.write!(files_list) run_targets = targets.dup - run_targets.pop if !@options[:full_run] && files_list.filtered? + run_targets.pop if (!@options[:full_run] && files_list.filtered?) || files_list.has_spec_outside_scope? system jasmine_command(run_targets) status = $?.exitstatus diff --git a/spec/bin/jasmine-headless-webkit_spec.rb b/spec/bin/jasmine-headless-webkit_spec.rb index 8d00b77..a13b0a4 100644 --- a/spec/bin/jasmine-headless-webkit_spec.rb +++ b/spec/bin/jasmine-headless-webkit_spec.rb @@ -26,7 +26,7 @@ describe "jasmine-headless-webkit" do system %{bin/jasmine-headless-webkit -j spec/jasmine/success_with_error/success_with_error.yml --report #{report}} $?.exitstatus.should == 1 - report.should be_a_report_containing(1, 0, false) + report.should be_a_report_containing(0, 0, false) end end @@ -65,6 +65,13 @@ describe "jasmine-headless-webkit" do report.should be_a_report_containing(1, 0, false) end + + it "should use a file outside the normal test run and only run one" do + system %{bin/jasmine-headless-webkit -j spec/jasmine/filtered_success/filtered_success.yml --report #{report} ./spec/jasmine/filtered_success/success_other_file.js} + $?.exitstatus.should == 0 + + report.should be_a_report_containing(1, 0, false) + end end context "do both runs" do diff --git a/spec/jasmine/filtered_success/success_other_file.js b/spec/jasmine/filtered_success/success_other_file.js new file mode 100644 index 0000000..e59c2ca --- /dev/null +++ b/spec/jasmine/filtered_success/success_other_file.js @@ -0,0 +1,7 @@ +describe('outside success', function() { + it('should succeed', function() { + expect(true).toEqual(true); + }); +}); + + diff --git a/spec/lib/jasmine/files_list_spec.rb b/spec/lib/jasmine/files_list_spec.rb index cf4027b..2df980a 100644 --- a/spec/lib/jasmine/files_list_spec.rb +++ b/spec/lib/jasmine/files_list_spec.rb @@ -99,15 +99,28 @@ describe Jasmine::FilesList do end end - let(:filter) { 'spec/one_spec.js' } + context 'filter with a file that is matchable' do + let(:filter) { [ File.expand_path('spec/one_spec.js') ] } - it 'should return all files for files' do - files_list.files.any? { |file| file['two_spec.js'] }.should be_true - files_list.filtered?.should be_true + it 'should return all files for files' do + files_list.files.any? { |file| file['two_spec.js'] }.should be_true + files_list.filtered?.should be_true + files_list.should_not have_spec_outside_scope + end + + it 'should return only filtered files for filtered_files' do + files_list.filtered_files.any? { |file| file['two_spec.js'] }.should be_false + files_list.should_not have_spec_outside_scope + end end - it 'should return only filtered files for filtered_files' do - files_list.filtered_files.any? { |file| file['two_spec.js'] }.should be_false + context 'filter with a file that is not even there' do + let(:filter) { [ File.expand_path('spec/whatever.js') ] } + + it 'should use the provided file' do + files_list.filtered_files.any? { |file| file['whatever.js'] }.should be_true + files_list.should have_spec_outside_scope + end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index fdb4dda..b138097 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -12,12 +12,20 @@ end RSpec::Matchers.define :be_a_report_containing do |total, fails, used_console| match do |filename| - parts = File.read(filename).strip.split('/') - parts.length.should == 4 + parts(filename).length.should == 4 parts[0].should == total.to_s parts[1].should == fails.to_s parts[2].should == (used_console ? "T" : "F") true end + + failure_message_for_should do |filename| + parts(filename) + "expected #{filename} to be a report containing (#{total}, #{fails}, #{used_console.inspect}), instead it contained (#{parts[0]}, #{parts[1]}, #{(parts[2] == "T").inspect})" + end + + def parts(filename = nil) + @parts ||= File.read(filename).strip.split('/') + end end