File: tempfile_test.rb

package info (click to toggle)
ruby-fakefs 3.0.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 544 kB
  • sloc: ruby: 7,606; makefile: 5
file content (31 lines) | stat: -rw-r--r-- 599 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# frozen_string_literal: true

require_relative '../test_helper'
require 'tempfile'

# Tempfile test class
class TempfileTest < Minitest::Test
  include FakeFS

  def test_open_should_not_raise_error
    FakeFS do
      # nothing raised
      FileUtils.mkdir_p(Dir.tmpdir)
      Tempfile.open('test')
    end
  end

  def test_create_block
    FakeFS do
      # Ruby 2.3 requires a basename
      Tempfile.create('') do |f|
        assert_equal FakeFS::File, f.class

        f.write 'Hello World!'
        f.flush

        assert_equal 'Hello World!', File.read(f.path)
      end
    end
  end
end