Sha256: 11454c5f868283af635ec5c59d9f1c4906e0a30699870c702dd35c12587ac162

Contents?: true

Size: 1.56 KB

Versions: 34

Compression:

Stored size: 1.56 KB

Contents

require File.dirname(__FILE__) + '/spec_helper.rb'

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

34 entries across 34 versions & 5 rubygems

Version Path
indirect-metric_fu-0.9.0 spec/md5_tracker_spec.rb
jscruggs-metric_fu-0.8.9 spec/md5_tracker_spec.rb
jscruggs-metric_fu-0.9.0 spec/md5_tracker_spec.rb
leh-metric_fu-0.9.2 spec/md5_tracker_spec.rb
nielsm-metric_fu-0.9.0 spec/md5_tracker_spec.rb
nielsm-metric_fu-0.9.1 spec/md5_tracker_spec.rb
p8-metric_fu-0.8.0.16 spec/md5_tracker_spec.rb
p8-metric_fu-0.8.4.1 spec/md5_tracker_spec.rb
p8-metric_fu-0.8.4.10 spec/md5_tracker_spec.rb
p8-metric_fu-0.8.4.11 spec/md5_tracker_spec.rb
p8-metric_fu-0.8.4.12 spec/md5_tracker_spec.rb
p8-metric_fu-0.8.4.13 spec/md5_tracker_spec.rb
p8-metric_fu-0.8.4.14 spec/md5_tracker_spec.rb
p8-metric_fu-0.8.4.15 spec/md5_tracker_spec.rb
p8-metric_fu-0.8.4.16 spec/md5_tracker_spec.rb
p8-metric_fu-0.8.4.2 spec/md5_tracker_spec.rb
p8-metric_fu-0.8.4.3 spec/md5_tracker_spec.rb
p8-metric_fu-0.8.4.4 spec/md5_tracker_spec.rb
p8-metric_fu-0.8.4.5 spec/md5_tracker_spec.rb
p8-metric_fu-0.8.4.6 spec/md5_tracker_spec.rb