Sha256: 66a0667d8ab607d188349a2493c526fc0cd1368d5647633f9a57de8f25ad1dab

Contents?: true

Size: 1.58 KB

Versions: 59

Compression:

Stored size: 1.58 KB

Contents

require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")

describe MetricFu::MD5Tracker do
  before do
    @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

  after do
    FileUtils.rm_rf(@tmp_dir, :verbose => false)
  end

  it "identical files should match" do
    @file1.puts("Hello World")
    @file1.close
    file1_md5 = MD5Tracker.track(@file1.path, @tmp_dir)

    @file2.puts("Hello World")
    @file2.close
    file2_md5 = MD5Tracker.track(@file2.path, @tmp_dir)

    file2_md5.should == file1_md5
  end

  it "different files should not match" do
    @file1.puts("Hello World")
    @file1.close
    file1_md5 = MD5Tracker.track(@file1.path, @tmp_dir)

    @file2.puts("Goodbye World")
    @file2.close
    file2_md5 = MD5Tracker.track(@file2.path, @tmp_dir)

    file2_md5.should_not == file1_md5
  end

  it "file_changed? should detect a change" do
      @file2.close

      @file1.puts("Hello World")
      @file1.close
      file1_md5 = MD5Tracker.track(@file1.path, @tmp_dir)

      @file1 = File.new(File.join(@tmp_dir, 'file1.txt'), 'w')
      @file1.puts("Goodbye World")
      @file1.close
      MD5Tracker.file_changed?(@file1.path, @tmp_dir).should be_true
  end

  it "should detect a new file" do
    @file2.close
    MD5Tracker.file_changed?(@file1.path, @tmp_dir).should be_true
    File.exist?(MD5Tracker.md5_file(@file1.path, @tmp_dir)).should be_true
  end
end

Version data entries

59 entries across 59 versions & 21 rubygems

Version Path
IPGlider-metric_fu-1.1.5.1.1 spec/base/md5_tracker_spec.rb
IPGlider-metric_fu-1.1.5.1 spec/base/md5_tracker_spec.rb
cayblood-metric_fu-1.1.6 spec/base/md5_tracker_spec.rb
edouard-metric_fu-1.1.1 spec/base/md5_tracker_spec.rb
gforces-metric_fu-1.1.4 spec/base/md5_tracker_spec.rb
iain-metric_fu-0.1.0 spec/base/md5_tracker_spec.rb
iain-metric_fu-0.1.1 spec/base/md5_tracker_spec.rb
iain-metric_fu-0.1.2 spec/base/md5_tracker_spec.rb
jscruggs-metric_fu-1.1.0 spec/base/md5_tracker_spec.rb
jscruggs-metric_fu-1.1.1 spec/base/md5_tracker_spec.rb
jscruggs-metric_fu-1.1.2 spec/base/md5_tracker_spec.rb
jscruggs-metric_fu-1.1.3 spec/base/md5_tracker_spec.rb
jscruggs-metric_fu-1.1.4 spec/base/md5_tracker_spec.rb
jscruggs-metric_fu-1.1.5 spec/base/md5_tracker_spec.rb
kjeldahl-metric_fu-1.1.5.1 spec/base/md5_tracker_spec.rb
kjeldahl-metric_fu-1.1.5.2 spec/base/md5_tracker_spec.rb
kjeldahl-metric_fu-1.1.5.3 spec/base/md5_tracker_spec.rb
kjeldahl-metric_fu-1.1.5.4 spec/base/md5_tracker_spec.rb
kjeldahl-metric_fu-1.1.5 spec/base/md5_tracker_spec.rb
mattvanhorn-metric_fu-1.1.5.1 spec/base/md5_tracker_spec.rb