2011-04-17 28 views
4

我想使用FakeFS但不断收到未初始化的常数错误,当我require 'fakefs'未初始化的常量文件:: NOCTTY错误“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宝石。我正在使用Ruby 1.9开发Windows。有任何想法吗?

回答

3

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

def RealFile.const_missing const 
    const_set const, 42 
end 

真的,我不知道它会在将来造成任何问题或没有,但你将能够至少运行你的脚本。我认为你应该在github

有一些窗户修复叉子(这家伙评论所有标志都)写的:https://github.com/vertiginous/fakefs

+0

并称方法做的伎俩。还要感谢您指出了Windows修补程序的问题。 – ThisSuitIsBlackNot 2011-04-17 20:36:08