I am trying to use FakeFS but keep getting an uninitialized constant error when I require 'fakefs'
:
C:/Ruby192/lib/ruby/gems/1.9.1/gems/fakefs-0.3.1/lib/fakefs/file.rb:26:in `<class:File>': uninitialized constant File::NOCTTY (NameError)
I was originally working in RubyMine, but to isolate the problem I wrote a simple hello world script and ran it from the command line, and still get the same error. Here is that script:
require 'rubygems'
gem 'fakefs'
require 'fakefs'
puts "Hello Cleveland!"
And here is the error and accompanying stacktrace:
>ruby foo.rb
C:/Ruby192/lib/ruby/gems/1.9.1/gems/fakefs-0.3.1/lib/fakefs/file.rb:26:in `<class:File>': uninitialized constant File::NOCTTY (NameError)
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/fakefs-0.3.1/lib/fakefs/file.rb:4:in `<module:FakeFS>'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/fakefs-0.3.1/lib/fakefs/file.rb:3:in `<top (required)>'
from <internal:lib/rubygems/custom_require>:29:in `require'
from <internal:lib/rubygems/custom_require>:29:in `require'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/fakefs-0.3.1/lib/fakefs/safe.rb:9:in `<top (required)>'
from <internal:lib/rubygems/custom_require>:29:in `require'
from <internal:lib/rubygems/custom_require>:29:in `require'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/fakefs-0.3.1/lib/fakefs.rb:1:in `<top (required)>'
from <internal:lib/rubygems/custom_require>:29:in `require'
from <internal:lib/rubygems/custom_require>:29:in `require'
from foo.rb:3:in `<main>'
I installed the fakefs gem via RubyMine. I'm working on Windows with Ruby 1.9. Any ideas?
It's because Windows doesn't have NOCTTY
and SYNC
flags. You can add this method to the base.rb
file:
def RealFile.const_missing const
const_set const, 42
end
Really, I don't know it cause any problems or not in the future but you'll be able to run your script at least. And I think you should write about this at github
There is a fork with some windows fixes (this guy commented all flags at all): https://github.com/vertiginous/fakefs