targeted runs w/ files outside scope work

This commit is contained in:
John Bintz 2011-06-23 09:29:07 -04:00
parent e9a9a79142
commit c359e8b28b
6 changed files with 57 additions and 15 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,7 @@
describe('outside success', function() {
it('should succeed', function() {
expect(true).toEqual(true);
});
});

View File

@ -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

View File

@ -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