tempfile incompatibility observed when using open-uri #122

Closed
sandro opened this Issue Apr 5, 2012 · 2 comments

Comments

Projects
None yet
3 participants

sandro commented Apr 5, 2012

It looks like fakefs doesn't track new files created by tempfile, so when tempfile issues a Fileutils.rmdir, fakefs doesn't can't find the file.

Relevant backtrace:

/gems/fakefs-0.4.0/lib/fakefs/dir.rb:6:in `_check_for_valid_file': No such file or directory - No such file or directory - /Users/santuri/src/ruby/ephemeral_response/open-uri20120405-7768-1w64msm.lock (Errno::ENOENT)
from /Users/santuri/.rvm/gems/ruby-1.9.3-p125-falcon@ephemeral_response/gems/fakefs-0.4.0/lib/fakefs/dir.rb:77:in `delete'
from /Users/santuri/.rvm/rubies/ruby-1.9.3-p125-falcon/lib/ruby/1.9.1/tempfile.rb:346:in `rmdir'
from /Users/santuri/.rvm/rubies/ruby-1.9.3-p125-falcon/lib/ruby/1.9.1/tempfile.rb:338:in `ensure in locking'
from /Users/santuri/.rvm/rubies/ruby-1.9.3-p125-falcon/lib/ruby/1.9.1/tempfile.rb:338:in `locking'
from /Users/santuri/.rvm/rubies/ruby-1.9.3-p125-falcon/lib/ruby/1.9.1/tempfile.rb:144:in `block in initialize'
from /Users/santuri/.rvm/rubies/ruby-1.9.3-p125-falcon/lib/ruby/1.9.1/tmpdir.rb:133:in `create'
from /Users/santuri/.rvm/rubies/ruby-1.9.3-p125-falcon/lib/ruby/1.9.1/tempfile.rb:134:in `initialize'
from /Users/santuri/.rvm/rubies/ruby-1.9.3-p125-falcon/lib/ruby/1.9.1/open-uri.rb:379:in `new'

Code to reproduce

require 'fakefs'
require 'open-uri'

FakeFS do
  open('http://www.google.com')
end

open-uri uses Tempfile, and Tempfile call mkdir( current_dir_name + temp_file_name + '.lock'),
so only if you call FakeFS::FileSystem.add( current_dir_name ) , you can use open-uri.

but in FakeFS::SpecHelpers, all added FakeFS are cleared after each describe blocks,
i hacked like this,

in spec/spec_helper.rb

module FakeFS
  module DefaultSettingHelper
    def self.extended(example_group)
      example_group.default_settings(example_group)
    end
    def self.included(example_group)
      example_group.extend self
    end

    def default_settings(describe_block)
      describe_block.before :each do
        FakeFS::FileSystem.add File.expand_path('../../',__FILE__)
        FakeFS::FileSystem.add File.expand_path '/tmp'
      end
    end
  end
end

RSpec.configure do |config|
  config.include FakeFS::SpecHelpers
  config.include FakeFS::DefaultSettingHelper
end

i want some configuration for initialization.

Collaborator

eventualbuddha commented Jan 2, 2014

This was caused by the same thing that caused #206. It was fixed by ac5b6d7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment