File: io_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 (46 lines) | stat: -rw-r--r-- 1,029 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# frozen_string_literal: true

require_relative 'test_helper'

# Trivial IO test class
# Behavior is not really tested, as call is forwarded to File class
class IOTest < Minitest::Test
  def test_method_IO_read_works
    begin
      ::FakeFS.activate!(io_mocks: true)
      ::File.write('foo', 'bar')

      assert_equal 'bar', ::IO.read('foo')
    ensure
      ::FakeFS.deactivate!
      ::FakeFS::FileSystem.clear
    end
    refute ::File.exist?('foo')
  end

  def test_method_IO_write_works
    begin
      ::FakeFS.activate!(io_mocks: true)
      ::IO.write('foo', 'bar')

      assert_equal 'bar', ::File.read('foo')
    ensure
      ::FakeFS.deactivate!
      ::FakeFS::FileSystem.clear
    end
    refute ::File.exist?('foo')
  end

  def test_method_IO_binread_works
    begin
      ::FakeFS.activate!(io_mocks: true)
      ::File.write('foo', 'bar')

      assert_equal 'bar', ::IO.binread('foo')
    ensure
      ::FakeFS.deactivate!
      ::FakeFS::FileSystem.clear
    end
    refute ::File.exist?('foo')
  end
end