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

isunt 发布于 2018-11-08 require 最后更新 2018-11-08 21:57 32 浏览

我正尝试使用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!"
这里是错误和伴随的堆栈跟踪:
>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。有任何想法吗?
已邀请:

nnihil

赞同来自:

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

def RealFile.const_missing const
  const_set const, 42
end
真的,我不知道它会在将来导致任何问题,但你至少可以运行你的脚本。我认为你应该在github上写下这个 有一个带有一些Windows修复的分支(这个人一直评论所有标志):https://github.com/vertiginous/fakefs