Sha256: dda58b60d98cfe57b0ba373269eddadca3c7cdf9e8f0b86341ef5d5ae44ef49d

Contents?: true

Size: 1.68 KB

Versions: 5

Compression:

Stored size: 1.68 KB

Contents

require File.join(File.dirname(__FILE__), 'test_helper')

class TestMD5Tracker < Test::Unit::TestCase

  def setup
    @tmp_dir = File.join(File.dirname(__FILE__), 'tmp')
    FileUtils.mkdir_p(@tmp_dir, :verbose => false) unless File.directory?(@tmp_dir)
    @file1 = File.new(File.join(@tmp_dir, 'file1.txt'), 'w')
    @file2 = File.new(File.join(@tmp_dir, 'file2.txt'), 'w')
  end
  
  def teardown
    FileUtils.rm_rf(@tmp_dir, :verbose => false)
  end
  
  def test_identical_files_match
    @file1.puts("Hello World")
    @file1.close
    file1_md5 = MetricFu::MD5Tracker.track(@file1.path, @tmp_dir)
    
    @file2.puts("Hello World")
    @file2.close
    file2_md5 = MetricFu::MD5Tracker.track(@file2.path, @tmp_dir)
    
    assert file1_md5 == file2_md5
  end
  
  def test_different_files_dont_match
    @file1.puts("Hello World")
    @file1.close
    file1_md5 = MetricFu::MD5Tracker.track(@file1.path, @tmp_dir)

    @file2.puts("Goodbye World")
    @file2.close
    file2_md5 = MetricFu::MD5Tracker.track(@file2.path, @tmp_dir)
    
    assert file1_md5 != file2_md5
  end
  
  def test_file_changed
    @file2.close
    
    @file1.puts("Hello World")
    @file1.close
    file1_md5 = MetricFu::MD5Tracker.track(@file1.path, @tmp_dir)

    @file1 = File.new(File.join(@tmp_dir, 'file1.txt'), 'w')
    @file1.puts("Goodbye World")
    @file1.close
    assert MetricFu::MD5Tracker.file_changed?(@file1.path, @tmp_dir)
  end
  
  def test_file_changed_if_not_tracking
    @file2.close
    
    assert MetricFu::MD5Tracker.file_changed?(@file1.path, @tmp_dir)
    assert File.exist?(MetricFu::MD5Tracker.md5_file(@file1.path, @tmp_dir))
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
jscruggs-metric_fu-0.7.0 test/test_md5_tracker.rb
jscruggs-metric_fu-0.7.1 test/test_md5_tracker.rb
jscruggs-metric_fu-0.7.5 test/test_md5_tracker.rb
jscruggs-metric_fu-0.7.6 test/test_md5_tracker.rb
jscruggs-metric_fu-0.8.0 test/test_md5_tracker.rb