0
require File.dirname(__FILE__) + '/../../../spec_helper'
0
describe "File::Stat#<=>" do
0
- it "is able to compare files by the same modification times" do
0
- f1 = File.new(tmp("i_exist"), "w")
0
- f2 = File.new(tmp("i_exist_too"), "w")
0
+ @name1 = tmp("i_exist")
0
+ @name2 = tmp("i_exist_too")
0
+ @file1 = File.new @name1, "w"
0
+ @file2 = File.new @name2, "w"
0
- (f1.stat <=> f2.stat).should == 0
0
- File.delete(tmp("i_exist")) if File.exist?(tmp("i_exist"))
0
- File.delete(tmp("i_exist_too")) if File.exist?(tmp("i_exist_too"))
0
+ @file1.close unless @file1.closed?
0
+ @file2.close unless @file2.closed?
0
- it "is able to compare files by different modification times" do
0
- f1 = File.new(tmp("i_exist"), "w")
0
- f2 = File.new(tmp("i_exist_too"), "w")
0
+ it "is able to compare files by the same modification times" do
0
+ (@file1.stat <=> @file2.stat).should == 0
0
- File.utime(Time.now, Time.now + 100, tmp("i_exist_too"))
0
- (f1.stat <=> f2.stat).should == -1
0
+ it "is able to compare files by different modification times" do
0
+ File.utime(Time.now, Time.now + 100, @name2)
0
+ (@file1.stat <=> @file2.stat).should == -1
0
- File.utime(Time.now, Time.now - 100, tmp("i_exist_too"))
0
- (f1.stat <=> f2.stat).should == 1
0
- File.delete(tmp("i_exist")) if File.exist?(tmp("i_exist"))
0
- File.delete(tmp("i_exist_too")) if File.exist?(tmp("i_exist_too"))
0
+ File.utime(Time.now, Time.now - 100, @name2)
0
+ (@file1.stat <=> @file2.stat).should == 1
0
it "should also include Comparable and thus == shows mtime equality between two File::Stat objects" do
0
- f1 = File.new(tmp("i_exist"), "w")
0
- f2 = File.new(tmp("i_exist_too"), "w")
0
- (f1.stat == f2.stat).should == true
0
- (f1.stat == f1.stat).should == true
0
- (f2.stat == f2.stat).should == true
0
- File.utime(Time.now, Time.now + 100, tmp("i_exist_too"))
0
- (f1.stat == f2.stat).should == false
0
- (f1.stat == f1.stat).should == true
0
- (f2.stat == f2.stat).should == true
0
+ (@file1.stat == @file2.stat).should == true
0
+ (@file1.stat == @file1.stat).should == true
0
+ (@file2.stat == @file2.stat).should == true
0
+ File.utime(Time.now, Time.now + 100, @name2)
0
+ (@file1.stat == @file2.stat).should == false
0
+ (@file1.stat == @file1.stat).should == true
0
+ (@file2.stat == @file2.stat).should == true
Comments
No one has commented yet.