simonc / memfs

MemFs provides a fake file system that can be used for tests. Strongly inspired by FakeFS.
MIT License
320 stars 27 forks source link

NameError: undefined local variable or method `fs' for #<MemFs::File:0x007f8feccb9a20> #15

Closed mikz closed 9 years ago

mikz commented 9 years ago

try MemFs.activate { File.open('file', 'w') { |f|f << 'test' } } and see

NameError: undefined local variable or method `fs' for #<MemFs::File:0x007f8feccb9a20>
from ruby-2.2.0/bundler/gems/memfs-c2f29bd47a74/lib/memfs/file.rb:243:in `initialize'

looks like fs is on class, not an instance

simonc commented 9 years ago

Hi, thank you for the feedback. Are you using a specific version or master ?

simonc commented 9 years ago

I tried to reproduce the issue with a spec but the test passes :/

require 'spec_helper'

describe "Issue #15" do
  it 'supports File.open then <<' do
    expect{
      MemFs.activate { File.open('file', 'w') { |f|f << 'test' } } 
    }.not_to raise_error
  end
end
simonc commented 9 years ago

Ok, calling rake console inside the gem I can reproduce the issue. I'll try to find where it comes from.

simonc commented 9 years ago

Found it. It was due to def fs in _spechelper.rb that was making calls to fs work during specs. I renamed it to _fs to expose the false positive specs and it revealed the same issue in Dir. Thank you very much!