fakefs 0.5.4 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5dc2593e0eff91e5df327b9e0e6009d629cfcb42
4
- data.tar.gz: 2f28f7c3fe6f1a0b5c1e6a3268a4b49b6e343543
3
+ metadata.gz: 56ce8f3a0f75895e325781ae4b269b380b7edda5
4
+ data.tar.gz: b3ccf2e1c5a712ec7f05eb0f6da3f881f91f14a6
5
5
  SHA512:
6
- metadata.gz: c3610a7311b20ef411ae1d9b486b30efad8d68fa7e5d5b4c0e4cad43537d57f6f9f6bd843683d2826111a2bb2884e8d354dc0174a12b8356dbc67abb8ed1ac11
7
- data.tar.gz: 35fad1a65e7b3972d465f64dee7c54fd0c4f28c2b8043c28bcefe63a5ca891e038e5cd7eb83cc2aea118a90939c71518821424acdc899ca87641d6b6b72cddec
6
+ metadata.gz: f165dc35f777b6117c2db4c04c1e5e75649bcff6d9b67e9ad877a01fbd9aac0e358930c78b3961c3cda3ff8ca6feaba6f1af2410119c493b814ac10b04f19216
7
+ data.tar.gz: c1d29b78cb3716070a7c5e29095bcbfc5fe73941712660f171e6710d1a7d040b6c6515f4ec6d210ae7ea35cce1ccafa49a248f124e6065a8d37e7ef077cf93aa
data/.gitignore CHANGED
@@ -7,4 +7,6 @@ pkg
7
7
  .rbx
8
8
  .idea
9
9
  .bundle
10
+ .project
11
+ .ruby-version
10
12
  Gemfile.lock
@@ -0,0 +1,50 @@
1
+ AllCops:
2
+ Include:
3
+ - '**/Gemfile'
4
+ - lib/**/*
5
+ - spec/**/*
6
+ - gemirro.gemspec
7
+ Exclude:
8
+ - files/**/*
9
+ - templates/**/*
10
+ MethodLength:
11
+ Exclude:
12
+ - lib/**/*
13
+ - test/**/*.rb
14
+ - spec/**/*.rb
15
+ ClassLength:
16
+ Exclude:
17
+ - lib/**/*
18
+ - test/**/*
19
+ LineLength:
20
+ Exclude:
21
+ - test/**/*
22
+ ParameterLists:
23
+ Exclude:
24
+ - lib/**/*
25
+ Metrics/CyclomaticComplexity:
26
+ Severity: warning
27
+ Max: 20
28
+ Metrics/PerceivedComplexity:
29
+ Severity: warning
30
+ Max: 20
31
+ Lint/Eval:
32
+ Exclude:
33
+ - lib/**/*
34
+ Metrics/BlockNesting:
35
+ Severity: warning
36
+ Max: 4
37
+ Style/PredicateName:
38
+ Exclude:
39
+ - lib/fakefs/file.rb
40
+ Style/MethodName:
41
+ Exclude:
42
+ - lib/**/*.rb
43
+ - test/**/*.rb
44
+ Style/ModuleFunction:
45
+ Exclude:
46
+ - lib/**/*.rb
47
+ - test/**/*.rb
48
+ TrivialAccessors:
49
+ Enabled: true
50
+ ExactNameMatch: true
@@ -1,5 +1,4 @@
1
1
  rvm:
2
- - 1.8.7
3
2
  - 1.9.3
4
3
  - 2.0.0
5
4
  - 2.1.1
data/Rakefile CHANGED
@@ -1,33 +1,40 @@
1
1
  $LOAD_PATH.unshift File.join(File.dirname(__FILE__))
2
2
  $LOAD_PATH.unshift File.join(File.dirname(__FILE__), 'test')
3
3
 
4
- require "bundler/setup"
5
-
4
+ require 'bundler/setup'
6
5
  require 'rake/testtask'
7
6
 
8
7
  Rake::TestTask.new do |t|
9
- t.libs << "test"
8
+ t.libs << 'test'
10
9
  t.test_files = FileList['test/**/*test.rb']
11
10
  t.verbose = true
12
11
  end
13
12
 
14
13
  begin
15
14
  require 'rspec/core/rake_task'
16
- desc "Run specs"
15
+ desc 'Run specs'
17
16
  RSpec::Core::RakeTask.new
18
17
  rescue LoadError
19
18
  puts "Spec task can't be loaded. `gem install rspec`"
20
19
  end
21
20
 
22
- task :default => [:test, :spec]
21
+ begin
22
+ require 'rubocop/rake_task'
23
+ desc 'Run RuboCop'
24
+ RuboCop::RakeTask.new(:rubocop)
25
+ rescue LoadError
26
+ puts "Rubocop task can't be loaded. `gem install rubocop`"
27
+ end
28
+
29
+ task default: [:rubocop, :test, :spec]
23
30
 
24
- desc "Push a new version to rubygems.org"
31
+ desc 'Push a new version to rubygems.org'
25
32
  task :publish do
26
- abort("Tests failed!") unless system("rake test")
33
+ abort('Tests failed!') unless system('rake test')
27
34
  Rake::Task[:release].invoke
28
35
  end
29
36
 
30
- desc "Update contributors"
37
+ desc 'Update contributors'
31
38
  task :update_contributors do
32
- sh "git-rank-contributors > CONTRIBUTORS"
39
+ sh 'git-rank-contributors > CONTRIBUTORS'
33
40
  end
@@ -21,4 +21,5 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
22
  spec.add_development_dependency "rake", "~> 10.1"
23
23
  spec.add_development_dependency "rspec", "~> 2.14"
24
+ spec.add_development_dependency 'rubocop', '~>0.25'
24
25
  end
@@ -8,12 +8,13 @@ def RealPathname(*args)
8
8
  RealPathname.new(*args)
9
9
  end
10
10
 
11
- if RUBY_VERSION >= "1.9.3"
11
+ if RUBY_VERSION >= '1.9.3'
12
12
  def Pathname(*args)
13
13
  Pathname.new(*args)
14
14
  end
15
15
  end
16
16
 
17
+ # FakeFS module
17
18
  module FakeFS
18
19
  @activated = false
19
20
  class << self
@@ -28,13 +29,13 @@ module FakeFS
28
29
  remove_const(:File)
29
30
  remove_const(:FileTest)
30
31
  remove_const(:FileUtils)
31
- remove_const(:Pathname) if RUBY_VERSION >= "1.9.3"
32
+ remove_const(:Pathname) if RUBY_VERSION >= '1.9.3'
32
33
 
33
34
  const_set(:Dir, FakeFS::Dir)
34
35
  const_set(:File, FakeFS::File)
35
36
  const_set(:FileUtils, FakeFS::FileUtils)
36
37
  const_set(:FileTest, FakeFS::FileTest)
37
- const_set(:Pathname, FakeFS::Pathname) if RUBY_VERSION >= "1.9.3"
38
+ const_set(:Pathname, FakeFS::Pathname) if RUBY_VERSION >= '1.9.3'
38
39
  ::FakeFS::Kernel.hijack!
39
40
  end
40
41
  true
@@ -48,13 +49,13 @@ module FakeFS
48
49
  remove_const(:File)
49
50
  remove_const(:FileTest)
50
51
  remove_const(:FileUtils)
51
- remove_const(:Pathname) if RUBY_VERSION >= "1.9.3"
52
+ remove_const(:Pathname) if RUBY_VERSION >= '1.9.3'
52
53
 
53
54
  const_set(:Dir, RealDir)
54
55
  const_set(:File, RealFile)
55
56
  const_set(:FileTest, RealFileTest)
56
57
  const_set(:FileUtils, RealFileUtils)
57
- const_set(:Pathname, RealPathname) if RUBY_VERSION >= "1.9.3"
58
+ const_set(:Pathname, RealPathname) if RUBY_VERSION >= '1.9.3'
58
59
  ::FakeFS::Kernel.unhijack!
59
60
  end
60
61
  true
@@ -1,9 +1,11 @@
1
1
  module FakeFS
2
+ # FakeFs Dir class
2
3
  class Dir
3
4
  include Enumerable
5
+ attr_reader :path
4
6
 
5
7
  def self._check_for_valid_file(path)
6
- raise Errno::ENOENT, path unless FileSystem.find(path)
8
+ fail Errno::ENOENT, path unless FileSystem.find(path)
7
9
  end
8
10
 
9
11
  def initialize(string)
@@ -12,7 +14,7 @@ module FakeFS
12
14
  @path = FileSystem.normalize_path(string)
13
15
  @open = true
14
16
  @pointer = 0
15
- @contents = [ '.', '..', ] + FileSystem.find(@path).entries
17
+ @contents = ['.', '..'] + FileSystem.find(@path).entries
16
18
  end
17
19
 
18
20
  def close
@@ -22,16 +24,12 @@ module FakeFS
22
24
  nil
23
25
  end
24
26
 
25
- def each(&block)
26
- while f = read
27
+ def each(&_block)
28
+ while (f = read)
27
29
  yield f
28
30
  end
29
31
  end
30
32
 
31
- def path
32
- @path
33
- end
34
-
35
33
  def pos
36
34
  @pointer
37
35
  end
@@ -41,15 +39,15 @@ module FakeFS
41
39
  end
42
40
 
43
41
  def read
44
- raise IOError, "closed directory" if @pointer == nil
42
+ fail IOError, 'closed directory' if @pointer.nil?
45
43
  n = @contents[@pointer]
46
44
  @pointer += 1
47
- if n
48
- if n.to_s[0, path.size+1] == path+'/'
49
- n.to_s[path.size+1..-1]
50
- else
51
- n.to_s
52
- end
45
+ return unless n
46
+
47
+ if n.to_s[0, path.size + 1] == path + '/'
48
+ n.to_s[path.size + 1..-1]
49
+ else
50
+ n.to_s
53
51
  end
54
52
  end
55
53
 
@@ -58,7 +56,7 @@ module FakeFS
58
56
  end
59
57
 
60
58
  def seek(integer)
61
- raise IOError, "closed directory" if @pointer == nil
59
+ fail IOError, 'closed directory' if @pointer.nil?
62
60
  @pointer = integer
63
61
  @contents[integer]
64
62
  end
@@ -68,59 +66,68 @@ module FakeFS
68
66
  end
69
67
 
70
68
  def self.exists?(path)
71
- File.exists?(path) && File.directory?(path)
69
+ File.exist?(path) && File.directory?(path)
72
70
  end
73
71
 
74
72
  def self.chdir(dir, &blk)
75
73
  FileSystem.chdir(dir, &blk)
76
74
  end
77
75
 
78
- def self.chroot(string)
79
- raise NotImplementedError
76
+ def self.chroot(_string)
77
+ fail NotImplementedError
80
78
  end
81
79
 
82
80
  def self.delete(string)
83
81
  _check_for_valid_file(string)
84
- raise Errno::ENOTEMPTY, string unless FileSystem.find(string).empty?
82
+ fail Errno::ENOTEMPTY, string unless FileSystem.find(string).empty?
85
83
 
86
84
  FileSystem.delete(string)
87
85
  end
88
86
 
89
- def self.entries(dirname, opts = {})
87
+ def self.entries(dirname, _opts = {})
90
88
  _check_for_valid_file(dirname)
91
89
 
92
90
  Dir.new(dirname).map { |file| File.basename(file) }
93
91
  end
94
92
 
95
- def self.foreach(dirname, &block)
93
+ def self.foreach(dirname, &_block)
96
94
  Dir.open(dirname) { |file| yield file }
97
95
  end
98
96
 
99
- def self.glob(pattern, flags = 0, &block)
97
+ def self.glob(pattern, _flags = 0, &block)
100
98
  matches_for_pattern = lambda do |matcher|
101
- [FileSystem.find(matcher) || []].flatten.map{|e|
102
- Dir.pwd.match(%r[\A/?\z]) || !e.to_s.match(%r[\A#{Dir.pwd}/?]) ? e.to_s : e.to_s.match(%r[\A#{Dir.pwd}/?]).post_match}.sort
99
+ [FileSystem.find(matcher) || []].flatten.map do |e|
100
+ if Dir.pwd.match(/\A\/?\z/) ||
101
+ !e.to_s.match(/\A#{Dir.pwd}\/?/)
102
+ e.to_s
103
+ else
104
+ e.to_s.match(/\A#{Dir.pwd}\/?/).post_match
105
+ end
106
+ end.sort
103
107
  end
104
108
 
105
109
  if pattern.is_a? Array
106
- files = pattern.collect { |matcher| matches_for_pattern.call matcher }.flatten
110
+ files = pattern.map do |matcher|
111
+ matches_for_pattern.call matcher
112
+ end.flatten
107
113
  else
108
114
  files = matches_for_pattern.call pattern
109
115
  end
110
- return block_given? ? files.each { |file| block.call(file) } : files
116
+
117
+ block_given? ? files.each { |file| block.call(file) } : files
111
118
  end
112
119
 
113
- if RUBY_VERSION >= "1.9"
120
+ if RUBY_VERSION >= '1.9'
114
121
  def self.home(user = nil)
115
122
  RealDir.home(user)
116
123
  end
117
124
  end
118
125
 
119
- def self.mkdir(string, integer = 0)
126
+ def self.mkdir(string, _integer = 0)
120
127
  FileUtils.mkdir(string)
121
128
  end
122
129
 
123
- def self.open(string, &block)
130
+ def self.open(string, &_block)
124
131
  if block_given?
125
132
  Dir.new(string).each { |file| yield(file) }
126
133
  else
@@ -137,6 +144,7 @@ module FakeFS
137
144
  end
138
145
 
139
146
  if RUBY_VERSION >= '2.1'
147
+ # Tmpname module
140
148
  module Tmpname # :nodoc:
141
149
  module_function
142
150
 
@@ -148,21 +156,22 @@ module FakeFS
148
156
  case prefix_suffix
149
157
  when String
150
158
  prefix = prefix_suffix
151
- suffix = ""
159
+ suffix = ''
152
160
  when Array
153
161
  prefix = prefix_suffix[0]
154
162
  suffix = prefix_suffix[1]
155
163
  else
156
- raise ArgumentError, "unexpected prefix_suffix: #{prefix_suffix.inspect}"
164
+ fail ArgumentError,
165
+ "unexpected prefix_suffix: #{prefix_suffix.inspect}"
157
166
  end
158
- t = Time.now.strftime("%Y%m%d")
159
- path = "#{prefix}#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
167
+ t = Time.now.strftime('%Y%m%d')
168
+ path = "#{prefix}#{t}-#{$PID}-#{rand(0x100000000).to_s(36)}"
160
169
  path << "-#{n}" if n
161
170
  path << suffix
162
171
  end
163
172
 
164
173
  def create(basename, *rest)
165
- if opts = Hash.try_convert(rest[-1])
174
+ if (opts = Hash.try_convert(rest[-1]))
166
175
  opts = opts.dup if rest.pop.equal?(opts)
167
176
  max_try = opts.delete(:max_try)
168
177
  opts = [opts]
@@ -170,10 +179,10 @@ module FakeFS
170
179
  opts = []
171
180
  end
172
181
  tmpdir, = *rest
173
- if $SAFE > 0 and tmpdir.tainted?
182
+ if $SAFE > 0 && tmpdir.tainted?
174
183
  tmpdir = '/tmp'
175
184
  else
176
- tmpdir ||= tmpdir()
185
+ tmpdir ||= self.tmpdir
177
186
  end
178
187
  n = nil
179
188
  begin
@@ -182,8 +191,9 @@ module FakeFS
182
191
  rescue Errno::EEXIST
183
192
  n ||= 0
184
193
  n += 1
185
- retry if !max_try or n < max_try
186
- raise "cannot generate temporary name using `#{basename}' under `#{tmpdir}'"
194
+ retry if !max_try || n < max_try
195
+ raise "cannot generate temporary name using `#{basename}' " \
196
+ "under `#{tmpdir}'"
187
197
  end
188
198
  path
189
199
  end
@@ -194,23 +204,23 @@ module FakeFS
194
204
  def self.mktmpdir(prefix_suffix = nil, tmpdir = nil)
195
205
  case prefix_suffix
196
206
  when nil
197
- prefix = "d"
198
- suffix = ""
207
+ prefix = 'd'
208
+ suffix = ''
199
209
  when String
200
210
  prefix = prefix_suffix
201
- suffix = ""
211
+ suffix = ''
202
212
  when Array
203
213
  prefix = prefix_suffix[0]
204
214
  suffix = prefix_suffix[1]
205
215
  else
206
- raise ArgumentError, "unexpected prefix_suffix: #{prefix_suffix.inspect}"
216
+ fail ArgumentError, "unexpected prefix_suffix: #{prefix_suffix.inspect}"
207
217
  end
208
218
 
209
- t = Time.now.strftime("%Y%m%d")
219
+ t = Time.now.strftime('%Y%m%d')
210
220
  n = nil
211
221
 
212
222
  begin
213
- path = "#{tmpdir}/#{prefix}#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
223
+ path = "#{tmpdir}/#{prefix}#{t}-#{$PID}-#{rand(0x100000000).to_s(36)}"
214
224
  path << "-#{n}" if n
215
225
  path << suffix
216
226
  mkdir(path, 0700)
@@ -1,4 +1,5 @@
1
1
  module FakeFS
2
+ # Fake Dir class
2
3
  class FakeDir
3
4
  attr_accessor :name, :parent, :mode, :uid, :gid, :mtime, :atime
4
5
  attr_reader :ctime, :content
@@ -12,7 +13,7 @@ module FakeFS
12
13
  @mode = 0100000 + (0777 - File.umask)
13
14
  @uid = Process.uid
14
15
  @gid = Process.gid
15
- @content = ""
16
+ @content = ''
16
17
  @entries = {}
17
18
  end
18
19
 
@@ -21,7 +22,8 @@ module FakeFS
21
22
  end
22
23
 
23
24
  def inspect
24
- "(FakeDir name:#{name.inspect} parent:#{parent.to_s.inspect} size:#{@entries.size})"
25
+ "(FakeDir name:#{name.inspect} " \
26
+ "parent:#{parent.to_s.inspect} size:#{@entries.size})"
25
27
  end
26
28
 
27
29
  def clone(parent = nil)
@@ -52,7 +54,7 @@ module FakeFS
52
54
  end
53
55
 
54
56
  def matches(pattern)
55
- @entries.reject {|k,v| pattern !~ k }.values
57
+ @entries.reject { |k, _v| pattern !~ k }.values
56
58
  end
57
59
 
58
60
  def [](name)