Fix up birthtime specs

There are two different possible messages: unsupported OS/version, and
unsupported filesystem on a supported system.
This commit is contained in:
Nobuyoshi Nakada 2025-06-10 15:05:09 +09:00
parent 6184793ea9
commit 20adae4ad6
No known key found for this signature in database
GPG Key ID: 3582D74E1FEE4465
2 changed files with 15 additions and 5 deletions

View File

@ -1,6 +1,11 @@
require_relative '../../spec_helper' require_relative '../../spec_helper'
platform_is :windows, :darwin, :freebsd, :netbsd, :linux do platform_is :windows, :darwin, :freebsd, :netbsd, :linux do
not_implemented_messages = [
"birthtime() function is unimplemented", # unsupported OS/version
"birthtime is unimplemented", # unsupported filesystem
]
describe "File.birthtime" do describe "File.birthtime" do
before :each do before :each do
@file = __FILE__ @file = __FILE__
@ -14,20 +19,20 @@ platform_is :windows, :darwin, :freebsd, :netbsd, :linux do
File.birthtime(@file) File.birthtime(@file)
File.birthtime(@file).should be_kind_of(Time) File.birthtime(@file).should be_kind_of(Time)
rescue NotImplementedError => e rescue NotImplementedError => e
skip e.message if e.message.start_with?("birthtime() function") e.message.should.start_with?(*not_implemented_messages)
end end
it "accepts an object that has a #to_path method" do it "accepts an object that has a #to_path method" do
File.birthtime(@file) # Avoid to failure of mock object with old Kernel and glibc File.birthtime(@file) # Avoid to failure of mock object with old Kernel and glibc
File.birthtime(mock_to_path(@file)) File.birthtime(mock_to_path(@file))
rescue NotImplementedError => e rescue NotImplementedError => e
e.message.should.start_with?("birthtime() function") e.message.should.start_with?(*not_implemented_messages)
end end
it "raises an Errno::ENOENT exception if the file is not found" do it "raises an Errno::ENOENT exception if the file is not found" do
-> { File.birthtime('bogus') }.should raise_error(Errno::ENOENT) -> { File.birthtime('bogus') }.should raise_error(Errno::ENOENT)
rescue NotImplementedError => e rescue NotImplementedError => e
e.message.should.start_with?("birthtime() function") e.message.should.start_with?(*not_implemented_messages)
end end
end end
@ -45,7 +50,7 @@ platform_is :windows, :darwin, :freebsd, :netbsd, :linux do
@file.birthtime @file.birthtime
@file.birthtime.should be_kind_of(Time) @file.birthtime.should be_kind_of(Time)
rescue NotImplementedError => e rescue NotImplementedError => e
e.message.should.start_with?("birthtime() function") e.message.should.start_with?(*not_implemented_messages)
end end
end end
end end

View File

@ -3,6 +3,11 @@ require_relative '../../../spec_helper'
platform_is(:windows, :darwin, :freebsd, :netbsd, platform_is(:windows, :darwin, :freebsd, :netbsd,
*ruby_version_is("3.5") { :linux }, *ruby_version_is("3.5") { :linux },
) do ) do
not_implemented_messages = [
"birthtime() function is unimplemented", # unsupported OS/version
"birthtime is unimplemented", # unsupported filesystem
]
describe "File::Stat#birthtime" do describe "File::Stat#birthtime" do
before :each do before :each do
@file = tmp('i_exist') @file = tmp('i_exist')
@ -18,7 +23,7 @@ platform_is(:windows, :darwin, :freebsd, :netbsd,
st.birthtime.should be_kind_of(Time) st.birthtime.should be_kind_of(Time)
st.birthtime.should <= Time.now st.birthtime.should <= Time.now
rescue NotImplementedError => e rescue NotImplementedError => e
e.message.should.start_with?("birthtime() function") e.message.should.start_with?(*not_implemented_messages)
end end
end end
end end