当我需要'fakefs'时,未初始化的常量File :: NOCTTY错误

时间:2011-04-17 19:20:04

标签: ruby rubygems require rubymine uninitialized-constant

我正在尝试使用FakeFS,但在我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)

我最初在RubyMine工作,但为了隔离问题,我编写了一个简单的hello world脚本并从命令行运行它,仍然得到相同的错误。这是脚本:

require 'rubygems'
gem 'fakefs'
require 'fakefs'

puts "Hello Cleveland!"

这是错误并伴随着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>'

我通过RubyMine安装了fakefs gem。我正在使用Ruby 1.9在Windows上工作。有什么想法吗?

1 个答案:

答案 0 :(得分:3)

这是因为Windows没有NOCTTYSYNC标志。您可以将此方法添加到base.rb文件中:

def RealFile.const_missing const
  const_set const, 42
end

真的,我不知道它会在将来导致任何问题,但你至少可以运行你的脚本。我认为你应该在github

写下这个

有一个带有一些Windows修复的分支(这个人根本没有评论所有标记):https://github.com/vertiginous/fakefs