memfs 0.4.2 → 0.4.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 70a8628ef207a62b0e968c52b562a999eb9b17eb
4
- data.tar.gz: da534038352ee4290851b8dc4f2f7aef7bed7cf5
3
+ metadata.gz: 71cd9903100239967550a02a2f803264604c076d
4
+ data.tar.gz: 65c68e74aab6519b99841afa80c8bf8ec22a4907
5
5
  SHA512:
6
- metadata.gz: c47dc6fe5eb179d3ee6d4e1e439e714d19920af0d474fa6166c1c8d75eb0c6a9c37d5115cf9db627e1801e0318dcb077620f05c87387428698061282610541a5
7
- data.tar.gz: 218c397cacf5071ea1f83cfa06b12b8420bfef293390c652066f5548f6f9b7e9fba78e6d19af76f6d73a59bf0939a3ffdbcb66f7b649a9073ce9406c04fd5da0
6
+ metadata.gz: 4b5b2d13af10abc53b81c33fef8dcabe4998da21faebcabeb7f50a2ca01334fef69054d2e1c22804aaf6d7202f75b80465be6db1d3d0d3f7513707635ed05950
7
+ data.tar.gz: 3c9ee2c3e9435c03c53c1777814cd42183774c914e78d2e30d2b51605df89db3a174d79a3c177cd4c911a0ea2e5e07355785f65c375d9c992986196376dbebb7
@@ -2,6 +2,11 @@
2
2
 
3
3
  ## HEAD
4
4
 
5
+ ## 0.4.3
6
+
7
+ * ADD: `File::SEPARATOR` and `File::ALT_SEPARATOR`
8
+ * FIX: Support `YAML.load_file` by handling `r:bom|utf-8` open mode
9
+
5
10
  ## 0.4.2
6
11
 
7
12
  * ADD: `File#external_encoding`
data/README.md CHANGED
@@ -43,6 +43,22 @@ end
43
43
  File.exists?('/test-file') #=> false
44
44
  ```
45
45
 
46
+ ## Why you may prefer MemFs over FakeFS?
47
+
48
+ While FakeFS is pretty cool it overrides classes like `FileUtils`. This kind of override is problematic when you rely on real behavior from this kind of tool.
49
+
50
+ For instance, trying to test the following with FakeFS will not work, the `noop` option will be ignored:
51
+
52
+ ``` ruby
53
+ FileUtils.touch('somefile.txt', noop: true)
54
+ ```
55
+
56
+ MemFs tries to be **compliant with the Ruby API** by overriding only the low level classes (C classes) like File, Dir or File::Stat leaving the stdlib classes untouched and still working, being less intrusive that way.
57
+
58
+ Some stdlib classes may be overriden at some point if they don't use `File` or `Dir`, like `Pathname`, etc.
59
+
60
+ Another key point is that MemFs **aims to implement every single method provided by Ruby classes** (when possible) and to behave and return **exactly** the same way as the original classes.
61
+
46
62
  ## Installation
47
63
 
48
64
  Add this line to your application's Gemfile:
@@ -13,6 +13,8 @@ module MemFs
13
13
  include OriginalFile::Constants
14
14
  include IO::InstanceMethods
15
15
 
16
+ ALT_SEPARATOR = nil
17
+
16
18
  MODE_MAP = {
17
19
  'r' => RDONLY,
18
20
  'r+' => RDWR,
@@ -22,6 +24,7 @@ module MemFs
22
24
  'a+' => CREAT | APPEND | RDWR
23
25
  }
24
26
 
27
+ SEPARATOR = '/'
25
28
  SUCCESS = 0
26
29
 
27
30
  @umask = nil
@@ -129,6 +129,9 @@ module MemFs
129
129
  end
130
130
 
131
131
  def read(length = nil, buffer = '')
132
+ unless entry
133
+ fail(Errno::ENOENT, path)
134
+ end
132
135
  default = length ? nil : ''
133
136
  content.read(length, buffer) || default
134
137
  end
@@ -180,7 +183,7 @@ module MemFs
180
183
  def str_to_mode_int(mode)
181
184
  return mode unless mode.is_a?(String)
182
185
 
183
- unless mode =~ /\A([rwa]\+?)([bt])?\z/
186
+ unless mode =~ /\A([rwa]\+?)([bt])?(:bom)?(\|.+)?\z/
184
187
  fail ArgumentError, "invalid access mode #{mode}"
185
188
  end
186
189
 
@@ -1,3 +1,3 @@
1
1
  module MemFs
2
- VERSION = '0.4.2'
2
+ VERSION = '0.4.3'
3
3
  end
@@ -20,6 +20,16 @@ module MemFs
20
20
  expect(subject_class.ancestors).to include Enumerable
21
21
  end
22
22
 
23
+ describe 'constants' do
24
+ it 'expose SEPARATOR' do
25
+ expect(MemFs::File::SEPARATOR).to eq '/'
26
+ end
27
+
28
+ it 'expose ALT_SEPARATOR' do
29
+ expect(MemFs::File::ALT_SEPARATOR).to be_nil
30
+ end
31
+ end
32
+
23
33
  describe '.absolute_path' do
24
34
  before { MemFs::Dir.chdir('/test-dir') }
25
35
 
@@ -803,11 +813,50 @@ module MemFs
803
813
  end
804
814
 
805
815
  context 'and it is a string' do
806
- subject { subject_class.new('/test-file', 'r+') }
816
+ it 'sets the read mode for "r"' do
817
+ subject = subject_class.new('/test-file', 'r')
818
+ expect(subject.send(:opening_mode)).to eq File::RDONLY
819
+ end
807
820
 
808
- it 'sets the mode to the integer value' do
821
+ it 'sets the write+create+truncate mode for "w"' do
822
+ subject = subject_class.new('/test-file', 'w')
823
+ expect(subject.send(:opening_mode)).to eq File::CREAT|File::TRUNC|File::WRONLY
824
+ end
825
+
826
+ it 'sets the read+write mode for "r+"' do
827
+ subject = subject_class.new('/test-file', 'r+')
809
828
  expect(subject.send(:opening_mode)).to eq File::RDWR
810
829
  end
830
+
831
+ it 'sets the read+write+create+truncate mode for "w+"' do
832
+ subject = subject_class.new('/test-file', 'w+')
833
+ expect(subject.send(:opening_mode)).to eq File::CREAT|File::TRUNC|File::RDWR
834
+ end
835
+
836
+ it 'sets the write+create+append mode for "a"' do
837
+ subject = subject_class.new('/test-file', 'a')
838
+ expect(subject.send(:opening_mode)).to eq File::CREAT|File::APPEND|File::WRONLY
839
+ end
840
+
841
+ it 'sets the read+write+create+append mode for "a+"' do
842
+ subject = subject_class.new('/test-file', 'a+')
843
+ expect(subject.send(:opening_mode)).to eq File::CREAT|File::APPEND|File::RDWR
844
+ end
845
+
846
+ it 'handles the :bom option' do
847
+ subject = subject_class.new('/test-file', 'r:bom')
848
+ expect(subject.send(:opening_mode)).to eq File::RDONLY
849
+ end
850
+
851
+ it 'handles the |utf-8 option' do
852
+ subject = subject_class.new('/test-file', 'r|utf-8')
853
+ expect(subject.send(:opening_mode)).to eq File::RDONLY
854
+ end
855
+
856
+ it 'handles the :bom|utf-8 option' do
857
+ subject = subject_class.new('/test-file', 'r:bom|utf-8')
858
+ expect(subject.send(:opening_mode)).to eq File::RDONLY
859
+ end
811
860
  end
812
861
 
813
862
  context 'and it specifies that the file must be created' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: memfs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon COURTOIS
@@ -190,7 +190,7 @@ rubyforge_project:
190
190
  rubygems_version: 2.4.5
191
191
  signing_key:
192
192
  specification_version: 4
193
- summary: memfs-0.4.2
193
+ summary: memfs-0.4.3
194
194
  test_files:
195
195
  - spec/fileutils_spec.rb
196
196
  - spec/memfs/dir_spec.rb