test/coverband/utils/result_test.rb in coverband-4.2.0 vs test/coverband/utils/result_test.rb in coverband-4.2.1.rc1

- old
+ new

@@ -14,10 +14,31 @@ source_fixture('app/models/user.rb') => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil], source_fixture('app/controllers/sample_controller.rb') => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil] } end + describe '#add_not_loaded_files' do + it 'Adds files not yet tracked' do + results = Coverband::Utils::Result.add_not_loaded_files({}, ['./test/dog.*']) + dog_file = results.keys.grep(/dog.rb/).first + assert dog_file + end + + it 'Does not overrwrite existing coverage' do + dog_file = File.expand_path('./test/dog.rb') + results = Coverband::Utils::Result.add_not_loaded_files({ dog_file => [0, 1] }, ['./test/dog.*']) + assert_equal({ dog_file => [0, 1] }, results) + end + + it 'Adds files not yet tracked from multiple file globs' do + dog_file = File.expand_path('./test/dog.rb') + test_helper_file = File.expand_path('./test/test_helper.rb') + results = Coverband::Utils::Result.add_not_loaded_files({}, ['./test/dog.*', './test/test_helper.rb']) + assert_equal [dog_file, test_helper_file].to_set, results.keys.to_set + end + end + describe 'a simple cov result initialized from that' do subject { Coverband::Utils::Result.new(original_result) } it 'has 3 filenames' do assert_equal 3, subject.filenames.count @@ -46,58 +67,17 @@ it 'has accurate covered percentages' do assert_equal [80.0, 80.0, 100.0], subject.covered_percentages end - it 'has accurate least covered file' do - assert subject.least_covered_file.match(/sample_controller.rb/) - end - - [:covered_percent, - :covered_percentages, - :least_covered_file, - :covered_strength, - :covered_lines, - :missed_lines, - :total_lines].each do |msg| + %i[covered_percent + covered_percentages + covered_strength + covered_lines + missed_lines + total_lines].each do |msg| it "responds to #{msg}" do assert(subject.respond_to?(msg)) - end - end - - describe 'dumped with to_hash' do - it 'is a hash' do - assert subject.to_hash.is_a?(Hash) - end - - describe 'loaded back with from_hash' do - let(:dumped_result) do - Coverband::Utils::Result.from_hash(subject.to_hash) - end - - it 'has 3 source files' do - assert_equal subject.source_files.count, dumped_result.source_files.count - end - - it 'has the same covered_percent' do - assert_equal subject.covered_percent, dumped_result.covered_percent - end - - it 'has the same covered_percentages' do - assert_equal subject.covered_percentages, dumped_result.covered_percentages - end - - it 'has the same timestamp' do - assert_equal subject.created_at.to_i, dumped_result.created_at.to_i - end - - it 'has the same command_name' do - assert_equal subject.command_name, dumped_result.command_name - end - - it 'has the same original_result' do - assert_equal subject.original_result, dumped_result.original_result - end end end end end end