memfs 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
 - data/.DS_Store +0 -0
 - data/.gitignore +17 -0
 - data/.rspec +2 -0
 - data/.travis.yml +3 -0
 - data/Gemfile +4 -0
 - data/Guardfile +8 -0
 - data/LICENSE.txt +22 -0
 - data/README.md +128 -0
 - data/Rakefile +6 -0
 - data/lib/fileutils.rb +1738 -0
 - data/lib/memfs/dir.rb +33 -0
 - data/lib/memfs/fake/directory.rb +51 -0
 - data/lib/memfs/fake/entry.rb +73 -0
 - data/lib/memfs/fake/file/content.rb +47 -0
 - data/lib/memfs/fake/file.rb +36 -0
 - data/lib/memfs/fake/symlink.rb +32 -0
 - data/lib/memfs/file/stat.rb +48 -0
 - data/lib/memfs/file.rb +284 -0
 - data/lib/memfs/file_system.rb +157 -0
 - data/lib/memfs/filesystem_access.rb +7 -0
 - data/lib/memfs/version.rb +3 -0
 - data/lib/memfs.rb +100 -0
 - data/memfs.gemspec +29 -0
 - data/spec/fileutils_spec.rb +961 -0
 - data/spec/memfs/dir_spec.rb +104 -0
 - data/spec/memfs/fake/directory_spec.rb +115 -0
 - data/spec/memfs/fake/entry_spec.rb +140 -0
 - data/spec/memfs/fake/file/content_spec.rb +154 -0
 - data/spec/memfs/fake/file_spec.rb +37 -0
 - data/spec/memfs/fake/symlink_spec.rb +43 -0
 - data/spec/memfs/file/stat_spec.rb +209 -0
 - data/spec/memfs/file_spec.rb +928 -0
 - data/spec/memfs/file_system_spec.rb +393 -0
 - data/spec/memfs_spec.rb +54 -0
 - data/spec/spec_helper.rb +20 -0
 - metadata +203 -0
 
| 
         @@ -0,0 +1,209 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'spec_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module MemFs
         
     | 
| 
      
 4 
     | 
    
         
            +
              describe File::Stat do
         
     | 
| 
      
 5 
     | 
    
         
            +
                describe '.new' do
         
     | 
| 
      
 6 
     | 
    
         
            +
                  context "when optional follow_symlink argument is set to true" do
         
     | 
| 
      
 7 
     | 
    
         
            +
                    it "raises an error if the end-of-links-chain target doesn't exist" do
         
     | 
| 
      
 8 
     | 
    
         
            +
                      fs.symlink('/test-file', '/test-link')
         
     | 
| 
      
 9 
     | 
    
         
            +
                      expect { File::Stat.new('/test-link', true) }.to raise_error(Errno::ENOENT)
         
     | 
| 
      
 10 
     | 
    
         
            +
                    end
         
     | 
| 
      
 11 
     | 
    
         
            +
                  end
         
     | 
| 
      
 12 
     | 
    
         
            +
                end
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
                describe '#atime' do
         
     | 
| 
      
 15 
     | 
    
         
            +
                  let(:time) { Time.now - 500000 }
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                  it "returns the access time of the entry" do
         
     | 
| 
      
 18 
     | 
    
         
            +
                    fs.touch('/test-file')
         
     | 
| 
      
 19 
     | 
    
         
            +
                    entry = fs.find!('/test-file')
         
     | 
| 
      
 20 
     | 
    
         
            +
                    entry.atime = time
         
     | 
| 
      
 21 
     | 
    
         
            +
                    expect(File::Stat.new('/test-file').atime).to eq(time)
         
     | 
| 
      
 22 
     | 
    
         
            +
                  end
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                  context "when the entry is a symlink" do
         
     | 
| 
      
 25 
     | 
    
         
            +
                    context "and the optional follow_symlink argument is true" do
         
     | 
| 
      
 26 
     | 
    
         
            +
                      it "returns the access time of the last target of the link chain" do
         
     | 
| 
      
 27 
     | 
    
         
            +
                        fs.touch('/test-file')
         
     | 
| 
      
 28 
     | 
    
         
            +
                        entry = fs.find!('/test-file')
         
     | 
| 
      
 29 
     | 
    
         
            +
                        entry.atime = time
         
     | 
| 
      
 30 
     | 
    
         
            +
                        fs.symlink('/test-file', '/test-link')
         
     | 
| 
      
 31 
     | 
    
         
            +
                        expect(File::Stat.new('/test-link', true).atime).to eq(time)
         
     | 
| 
      
 32 
     | 
    
         
            +
                      end
         
     | 
| 
      
 33 
     | 
    
         
            +
                    end
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                    context "and the optional follow_symlink argument is false" do
         
     | 
| 
      
 36 
     | 
    
         
            +
                      it "returns the access time of the symlink itself" do
         
     | 
| 
      
 37 
     | 
    
         
            +
                        fs.touch('/test-file')
         
     | 
| 
      
 38 
     | 
    
         
            +
                        entry = fs.find!('/test-file')
         
     | 
| 
      
 39 
     | 
    
         
            +
                        entry.atime = time
         
     | 
| 
      
 40 
     | 
    
         
            +
                        fs.symlink('/test-file', '/test-link')
         
     | 
| 
      
 41 
     | 
    
         
            +
                        expect(File::Stat.new('/test-link').atime).not_to eq(time)
         
     | 
| 
      
 42 
     | 
    
         
            +
                      end
         
     | 
| 
      
 43 
     | 
    
         
            +
                    end
         
     | 
| 
      
 44 
     | 
    
         
            +
                  end
         
     | 
| 
      
 45 
     | 
    
         
            +
                end
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
                describe "#blksize" do
         
     | 
| 
      
 48 
     | 
    
         
            +
                  it "returns the block size of the file" do
         
     | 
| 
      
 49 
     | 
    
         
            +
                    fs.touch('/test-file')
         
     | 
| 
      
 50 
     | 
    
         
            +
                    expect(File::Stat.new('/test-file').blksize).to be(4096)
         
     | 
| 
      
 51 
     | 
    
         
            +
                  end
         
     | 
| 
      
 52 
     | 
    
         
            +
                end
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
                describe "#dev" do
         
     | 
| 
      
 55 
     | 
    
         
            +
                  it "returns an integer representing the device on which stat resides" do
         
     | 
| 
      
 56 
     | 
    
         
            +
                    fs.touch('/test-file')
         
     | 
| 
      
 57 
     | 
    
         
            +
                    expect(File::Stat.new('/test-file').dev).to be_a(Fixnum)
         
     | 
| 
      
 58 
     | 
    
         
            +
                  end
         
     | 
| 
      
 59 
     | 
    
         
            +
                end
         
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
      
 61 
     | 
    
         
            +
                describe '#directory?' do
         
     | 
| 
      
 62 
     | 
    
         
            +
                  before :each do
         
     | 
| 
      
 63 
     | 
    
         
            +
                    fs.mkdir('/test')
         
     | 
| 
      
 64 
     | 
    
         
            +
                    fs.touch('/test-file')
         
     | 
| 
      
 65 
     | 
    
         
            +
                    fs.symlink('/test', '/link-to-dir')
         
     | 
| 
      
 66 
     | 
    
         
            +
                    fs.symlink('/test-file', '/link-to-file')
         
     | 
| 
      
 67 
     | 
    
         
            +
                  end
         
     | 
| 
      
 68 
     | 
    
         
            +
             
     | 
| 
      
 69 
     | 
    
         
            +
                  it "returns true if the entry is a directory" do
         
     | 
| 
      
 70 
     | 
    
         
            +
                    expect(File::Stat.new('/test')).to be_directory
         
     | 
| 
      
 71 
     | 
    
         
            +
                  end
         
     | 
| 
      
 72 
     | 
    
         
            +
             
     | 
| 
      
 73 
     | 
    
         
            +
                  it "returns false if the entry is not a directory" do
         
     | 
| 
      
 74 
     | 
    
         
            +
                    expect(File::Stat.new('/test-file')).not_to be_directory
         
     | 
| 
      
 75 
     | 
    
         
            +
                  end
         
     | 
| 
      
 76 
     | 
    
         
            +
             
     | 
| 
      
 77 
     | 
    
         
            +
                  context "when the entry is a symlink" do
         
     | 
| 
      
 78 
     | 
    
         
            +
                    context "and the optional follow_symlink argument is true" do
         
     | 
| 
      
 79 
     | 
    
         
            +
                      it "returns true if the last target of the link chain is a directory" do
         
     | 
| 
      
 80 
     | 
    
         
            +
                        expect(File::Stat.new('/link-to-dir', true)).to be_directory
         
     | 
| 
      
 81 
     | 
    
         
            +
                      end
         
     | 
| 
      
 82 
     | 
    
         
            +
             
     | 
| 
      
 83 
     | 
    
         
            +
                      it "returns false if the last target of the link chain is not a directory" do
         
     | 
| 
      
 84 
     | 
    
         
            +
                        expect(File::Stat.new('/link-to-file', true)).not_to be_directory
         
     | 
| 
      
 85 
     | 
    
         
            +
                      end
         
     | 
| 
      
 86 
     | 
    
         
            +
                    end
         
     | 
| 
      
 87 
     | 
    
         
            +
             
     | 
| 
      
 88 
     | 
    
         
            +
                    context "and the optional follow_symlink argument is false" do
         
     | 
| 
      
 89 
     | 
    
         
            +
                      it "returns false if the last target of the link chain is a directory" do
         
     | 
| 
      
 90 
     | 
    
         
            +
                        expect(File::Stat.new('/link-to-dir', false)).not_to be_directory
         
     | 
| 
      
 91 
     | 
    
         
            +
                      end
         
     | 
| 
      
 92 
     | 
    
         
            +
             
     | 
| 
      
 93 
     | 
    
         
            +
                      it "returns false if the last target of the link chain is not a directory" do
         
     | 
| 
      
 94 
     | 
    
         
            +
                        expect(File::Stat.new('/link-to-file', false)).not_to be_directory
         
     | 
| 
      
 95 
     | 
    
         
            +
                      end
         
     | 
| 
      
 96 
     | 
    
         
            +
                    end
         
     | 
| 
      
 97 
     | 
    
         
            +
                  end
         
     | 
| 
      
 98 
     | 
    
         
            +
                end
         
     | 
| 
      
 99 
     | 
    
         
            +
             
     | 
| 
      
 100 
     | 
    
         
            +
                describe '#entry' do
         
     | 
| 
      
 101 
     | 
    
         
            +
                  it "returns the comcerned entry" do
         
     | 
| 
      
 102 
     | 
    
         
            +
                    entry = fs.touch('/test-file')
         
     | 
| 
      
 103 
     | 
    
         
            +
                    stat = File::Stat.new('/test-file')
         
     | 
| 
      
 104 
     | 
    
         
            +
                    expect(stat.entry).to be_a(Fake::File)
         
     | 
| 
      
 105 
     | 
    
         
            +
                  end
         
     | 
| 
      
 106 
     | 
    
         
            +
                end
         
     | 
| 
      
 107 
     | 
    
         
            +
             
     | 
| 
      
 108 
     | 
    
         
            +
                describe "#file?" do
         
     | 
| 
      
 109 
     | 
    
         
            +
                  it "returns true if the entry is a regular file" do
         
     | 
| 
      
 110 
     | 
    
         
            +
                    fs.touch('/test-file')
         
     | 
| 
      
 111 
     | 
    
         
            +
                    expect(File.stat('/test-file')).to be_file
         
     | 
| 
      
 112 
     | 
    
         
            +
                  end
         
     | 
| 
      
 113 
     | 
    
         
            +
             
     | 
| 
      
 114 
     | 
    
         
            +
                  it "returns false if the entry is not a regular file" do
         
     | 
| 
      
 115 
     | 
    
         
            +
                    fs.mkdir('/test-dir')
         
     | 
| 
      
 116 
     | 
    
         
            +
                    expect(File.stat('/test-dir')).not_to be_file
         
     | 
| 
      
 117 
     | 
    
         
            +
                  end
         
     | 
| 
      
 118 
     | 
    
         
            +
             
     | 
| 
      
 119 
     | 
    
         
            +
                  context "when the entry is a symlink" do
         
     | 
| 
      
 120 
     | 
    
         
            +
                    it "returns true if its target is a regular file" do
         
     | 
| 
      
 121 
     | 
    
         
            +
                      fs.touch('/test-file')
         
     | 
| 
      
 122 
     | 
    
         
            +
                      fs.symlink('/test-file', '/test-link')
         
     | 
| 
      
 123 
     | 
    
         
            +
                      expect(File.stat('/test-link')).to be_file
         
     | 
| 
      
 124 
     | 
    
         
            +
                    end
         
     | 
| 
      
 125 
     | 
    
         
            +
             
     | 
| 
      
 126 
     | 
    
         
            +
                    it "returns false if its target is not a regular file" do
         
     | 
| 
      
 127 
     | 
    
         
            +
                      fs.mkdir('/test-dir')
         
     | 
| 
      
 128 
     | 
    
         
            +
                      fs.symlink('/test-dir', '/test-link')
         
     | 
| 
      
 129 
     | 
    
         
            +
                      expect(File.stat('/test-link')).not_to be_file
         
     | 
| 
      
 130 
     | 
    
         
            +
                    end
         
     | 
| 
      
 131 
     | 
    
         
            +
                  end
         
     | 
| 
      
 132 
     | 
    
         
            +
                end
         
     | 
| 
      
 133 
     | 
    
         
            +
             
     | 
| 
      
 134 
     | 
    
         
            +
                describe "#gid" do
         
     | 
| 
      
 135 
     | 
    
         
            +
                  it "returns the group id of the named entry" do
         
     | 
| 
      
 136 
     | 
    
         
            +
                    fs.touch('/test-file')
         
     | 
| 
      
 137 
     | 
    
         
            +
                    fs.chown(nil, 42, '/test-file')
         
     | 
| 
      
 138 
     | 
    
         
            +
                    expect(File::Stat.new('/test-file').gid).to be(42)
         
     | 
| 
      
 139 
     | 
    
         
            +
                  end
         
     | 
| 
      
 140 
     | 
    
         
            +
                end
         
     | 
| 
      
 141 
     | 
    
         
            +
             
     | 
| 
      
 142 
     | 
    
         
            +
                describe "#ino" do
         
     | 
| 
      
 143 
     | 
    
         
            +
                  it "returns the inode number for stat." do
         
     | 
| 
      
 144 
     | 
    
         
            +
                    fs.touch('/test-file')
         
     | 
| 
      
 145 
     | 
    
         
            +
                    expect(File::Stat.new('/test-file').ino).to be_a(Fixnum)
         
     | 
| 
      
 146 
     | 
    
         
            +
                  end
         
     | 
| 
      
 147 
     | 
    
         
            +
                end
         
     | 
| 
      
 148 
     | 
    
         
            +
             
     | 
| 
      
 149 
     | 
    
         
            +
                describe '#mode' do
         
     | 
| 
      
 150 
     | 
    
         
            +
                  it "returns an integer representing the permission bits of stat" do
         
     | 
| 
      
 151 
     | 
    
         
            +
                    fs.touch('/test-file')
         
     | 
| 
      
 152 
     | 
    
         
            +
                    fs.chmod(0777, '/test-file')
         
     | 
| 
      
 153 
     | 
    
         
            +
                    expect(File::Stat.new('/test-file').mode).to be(0100777)
         
     | 
| 
      
 154 
     | 
    
         
            +
                  end
         
     | 
| 
      
 155 
     | 
    
         
            +
                end
         
     | 
| 
      
 156 
     | 
    
         
            +
             
     | 
| 
      
 157 
     | 
    
         
            +
                describe "#sticky?" do
         
     | 
| 
      
 158 
     | 
    
         
            +
                  it "returns true if the named file has the sticky bit set" do
         
     | 
| 
      
 159 
     | 
    
         
            +
                    fs.touch('/test-file')
         
     | 
| 
      
 160 
     | 
    
         
            +
                    fs.chmod(01777, '/test-file')
         
     | 
| 
      
 161 
     | 
    
         
            +
                    expect(File::Stat.new('/test-file')).to be_sticky
         
     | 
| 
      
 162 
     | 
    
         
            +
                  end
         
     | 
| 
      
 163 
     | 
    
         
            +
             
     | 
| 
      
 164 
     | 
    
         
            +
                  it "returns false if the named file hasn't' the sticky bit set" do
         
     | 
| 
      
 165 
     | 
    
         
            +
                    fs.touch('/test-file')
         
     | 
| 
      
 166 
     | 
    
         
            +
                    expect(File::Stat.new('/test-file')).not_to be_sticky
         
     | 
| 
      
 167 
     | 
    
         
            +
                  end
         
     | 
| 
      
 168 
     | 
    
         
            +
                end
         
     | 
| 
      
 169 
     | 
    
         
            +
             
     | 
| 
      
 170 
     | 
    
         
            +
                describe '#symlink?' do
         
     | 
| 
      
 171 
     | 
    
         
            +
                  it "returns true if the entry is a symlink" do
         
     | 
| 
      
 172 
     | 
    
         
            +
                    fs.touch('/test-file')
         
     | 
| 
      
 173 
     | 
    
         
            +
                    fs.symlink('/test-file', '/test-link')
         
     | 
| 
      
 174 
     | 
    
         
            +
                    expect(File::Stat.new('/test-link').symlink?).to be_true
         
     | 
| 
      
 175 
     | 
    
         
            +
                  end
         
     | 
| 
      
 176 
     | 
    
         
            +
             
     | 
| 
      
 177 
     | 
    
         
            +
                  it "returns false if the entry is not a symlink" do
         
     | 
| 
      
 178 
     | 
    
         
            +
                    fs.touch('/test-file')
         
     | 
| 
      
 179 
     | 
    
         
            +
                    expect(File::Stat.new('/test-file').symlink?).to be_false
         
     | 
| 
      
 180 
     | 
    
         
            +
                  end
         
     | 
| 
      
 181 
     | 
    
         
            +
                end
         
     | 
| 
      
 182 
     | 
    
         
            +
             
     | 
| 
      
 183 
     | 
    
         
            +
                describe "#uid" do
         
     | 
| 
      
 184 
     | 
    
         
            +
                  it "returns the user id of the named entry" do
         
     | 
| 
      
 185 
     | 
    
         
            +
                    fs.touch('/test-file')
         
     | 
| 
      
 186 
     | 
    
         
            +
                    fs.chown(42, nil, '/test-file')
         
     | 
| 
      
 187 
     | 
    
         
            +
                    expect(File::Stat.new('/test-file').uid).to be(42)
         
     | 
| 
      
 188 
     | 
    
         
            +
                  end
         
     | 
| 
      
 189 
     | 
    
         
            +
                end
         
     | 
| 
      
 190 
     | 
    
         
            +
             
     | 
| 
      
 191 
     | 
    
         
            +
                describe "#world_writable?" do
         
     | 
| 
      
 192 
     | 
    
         
            +
                  context "when +file_name+ is writable by others" do
         
     | 
| 
      
 193 
     | 
    
         
            +
                    it "returns an integer representing the file permission bits of +file_name+" do
         
     | 
| 
      
 194 
     | 
    
         
            +
                      fs.touch('/test-file')
         
     | 
| 
      
 195 
     | 
    
         
            +
                      fs.chmod(0777, '/test-file')
         
     | 
| 
      
 196 
     | 
    
         
            +
                      expect(File::Stat.new('/test-file')).to be_world_writable
         
     | 
| 
      
 197 
     | 
    
         
            +
                    end
         
     | 
| 
      
 198 
     | 
    
         
            +
                  end
         
     | 
| 
      
 199 
     | 
    
         
            +
             
     | 
| 
      
 200 
     | 
    
         
            +
                  context "when +file_name+ is not writable by others" do
         
     | 
| 
      
 201 
     | 
    
         
            +
                    it "returns nil" do
         
     | 
| 
      
 202 
     | 
    
         
            +
                      fs.touch('/test-file')
         
     | 
| 
      
 203 
     | 
    
         
            +
                      fs.chmod(0644, '/test-file')
         
     | 
| 
      
 204 
     | 
    
         
            +
                      expect(File::Stat.new('/test-file')).not_to be_world_writable
         
     | 
| 
      
 205 
     | 
    
         
            +
                    end
         
     | 
| 
      
 206 
     | 
    
         
            +
                  end
         
     | 
| 
      
 207 
     | 
    
         
            +
                end
         
     | 
| 
      
 208 
     | 
    
         
            +
              end
         
     | 
| 
      
 209 
     | 
    
         
            +
            end
         
     |