Skip to content

Commit

Permalink
Merge pull request #35 from ruby/compati-3-1
Browse files Browse the repository at this point in the history
File.new(fileno, mode: mode, path: path) is provided from Ruby 3.2
  • Loading branch information
hsbt committed Aug 23, 2024
2 parents f677941 + 9d9eb93 commit cc72591
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@ jobs:
needs: ruby-versions
name: build (${{ matrix.ruby }} / ${{ matrix.os }})
strategy:
fail-fast: false
matrix:
ruby: ${{ fromJson(needs.ruby-versions.outputs.versions) }}
os: [ ubuntu-latest, macos-latest, windows-latest ]
exclude:
- { os: macos-latest, ruby: '2.5' }
include:
- { os: macos-13, ruby: '2.5' }
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion lib/tempfile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ def open(*args, **kw)
# Related: Tempfile.new.
#
def Tempfile.create(basename="", tmpdir=nil, mode: 0, anonymous: false, **options, &block)
if anonymous
if anonymous && RUBY_VERSION >= '3.2'
create_anonymous(basename, tmpdir, mode: mode, **options, &block)
else
create_with_filename(basename, tmpdir, mode: mode, **options, &block)
Expand Down
12 changes: 10 additions & 2 deletions test/test_tempfile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -488,15 +488,23 @@ def test_create_anonymous_removes_file
Dir.mktmpdir {|d|
t = Tempfile.create("", d, anonymous: true)
t.close
assert_equal([], Dir.children(d))
if RUBY_VERSION >= '3.2'
assert_equal([], Dir.children(d))
else
refute_equal([], Dir.children(d))
end
}
end

def test_create_anonymous_path
Dir.mktmpdir {|d|
begin
t = Tempfile.create("", d, anonymous: true)
assert_equal(File.join(d, ""), t.path)
if RUBY_VERSION >= '3.2'
assert_equal(File.join(d, ""), t.path)
else
refute_equal(File.join(d, ""), t.path)
end
ensure
t.close if t
end
Expand Down

0 comments on commit cc72591

Please sign in to comment.