Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions core/file/atime_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@
File.atime(@file).should be_kind_of(Time)
end

platform_is :linux do
it "returns the last access time for the named file with microseconds" do
3.times do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cost of doing this repeatedly is pretty low, so this might as well be 10 or 100. But I support the idea in general; this was my stumbling block as well when I started to think about a spec.

The alternative would be to create a temporary file and forcibly modify these times, but I don't know if that's even possible for atime.

Note also that some Linux systems disable atime (e.g. via mount params) for better filesystem speed. I don't know if that will ever affect specs, though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is already only 1/1000 chance per iteration to get 0 (assuming millisecond granularity), so I think it's fine.
The second iteration will be even more unlikely to get 0 as the work in between will not take exactly one second.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cost of doing this repeatedly is pretty low, so this might as well be 10 or 100.

Increased to 100.

The alternative would be to create a temporary file and forcibly modify these times, but I don't know if that's even possible for atime.

That's possible for atime and mtime via FileUtils#touch.

This alternative was used.

Note also that some Linux systems disable atime (e.g. via mount params) for better filesystem speed. I don't know if that will ever affect specs, though.

This comment added to code, if you don't mind.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, it's already merged… What can I do?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's OK as it is (that's why I merged it), but if you want to change please feel free to open another Pull Request.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, thank you!

@atime = File.atime(@file)
break if @atime.usec > 0
sleep 0.001
end
@atime.usec.should > 0
end
end

it "raises an Errno::ENOENT exception if the file is not found" do
lambda { File.atime('a_fake_file') }.should raise_error(Errno::ENOENT)
end
Expand Down
15 changes: 15 additions & 0 deletions core/file/ctime_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@
File.ctime(@file).should be_kind_of(Time)
end

platform_is :linux do
it "Returns the change time for the named file (the time at which directory information about the file was changed, not the file itself) with microseconds." do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small typo, specs descriptions should start with a lowercase letter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy-pasted from previous it :(

What can I do with some fixes if that PR was merged? New PR?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed it along with a few other cases in c5de600

file = tmp('ctime')
3.times do
touch file
@ctime = File.ctime(file)
break if @ctime.usec > 0
rm_r file
sleep 0.001
end
rm_r file
@ctime.usec.should > 0
end
end

it "accepts an object that has a #to_path method" do
File.ctime(mock_to_path(@file))
end
Expand Down
12 changes: 12 additions & 0 deletions core/file/mtime_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@
File.mtime(@filename).should be_close(@mtime, 2.0)
end

platform_is :linux do
it "returns the modification Time of the file with microseconds" do
3.times do
touch(@filename)
@mtime = File.mtime(@filename)
break if @mtime.usec > 0
sleep 0.001
end
@mtime.usec.should > 0
end
end

it "raises an Errno::ENOENT exception if the file is not found" do
lambda { File.mtime('bogus') }.should raise_error(Errno::ENOENT)
end
Expand Down