require File.dirname(__FILE__) + '/../../spec_helper'

describe "File.utime" do
  before :each do
    @filename = 'i_exist.txt'
    File.open(@filename, 'w') { }
  end

  after :each do
    File.delete(@filename) if File.exist?(@filename)
  end

  it "returns the modification Time of the file" do
    changeTime = Time.now
    File.utime(changeTime, changeTime,@filename)
    File.mtime(@filename).should == changeTime
	File.atime(@filename).should == changeTime
  end

  it "returns the modification Time of the file and 0 for access time" do
    changeTime = Time.now
	accessTime = changeTime + 10
    File.utime(accessTime, changeTime,@filename)
    File.mtime(@filename).should == changeTime
	File.atime(@filename).should == accessTime
  end

  it "throws exception on NIL values" do
	should_raise(ArgumentError){ File.utime(0, Time.now, @file) }
	should_raise(ArgumentError){ File.utime(Time.now, 0, @file) }
	should_raise(ArgumentError){ File.utime(0, 0, @file) }
  end

  it "raises an Errno::ENOENT exception if the file is not found" do
    should_raise(Errno::ENOENT) { File.utime(Time.now, Time.now, 'bogus') }
  end
end