File: kernel_test.rb

package info (click to toggle)
ruby-fakefs 1.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 496 kB
  • sloc: ruby: 6,810; makefile: 5
file content (57 lines) | stat: -rw-r--r-- 1,149 bytes parent folder | download | duplicates (2)
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
47
48
49
50
51
52
53
54
55
56
57
require_relative 'test_helper'

# Kernel test class
class KernelTest < Minitest::Test
  include FakeFS
  def setup
    FakeFS.deactivate!
  end

  def teardown
    FakeFS.activate!
  end

  def test_can_exec_normally
    out = open("|echo 'foo'")
    assert_equal "foo\n", out.gets
  end

  def test_fake_kernel_can_create_subprocesses
    FakeFS do
      out = open("|echo 'foo'")
      assert_equal "foo\n", out.gets
    end
  end

  def test_fake_kernel_can_create_new_file
    FakeFS do
      FileUtils.mkdir_p '/path/to/'
      open('/path/to/file', 'w') do |f|
        f << 'test'
      end
      assert_kind_of FakeFile, FileSystem.fs['path']['to']['file']
    end
  end

  def test_fake_kernel_can_do_stuff
    FakeFS do
      FileUtils.mkdir_p('/tmp')
      File.open('/tmp/a', 'w+') { |f| f.puts 'test' }

      begin
        open('/tmp/a').read
      rescue StandardError => e
        raise e
      end
    end
  end

  def test_kernel_open_remains_private
    refute 'foo'.respond_to?(:open), 'String#open should be private'
  end

  def test_can_exec_normally2
    out = open("|echo 'foo'")
    assert_equal "foo\n", out.gets
  end
end