【问题标题】:Uninitialized constant File::NOCTTY error when I require 'fakefs'当我需要“fakefs”时出现未初始化的常量 File::NOCTTY 错误
【发布时间】:2011-08-07 10:32:26
【问题描述】:

我正在尝试使用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 上工作。有什么想法吗?

【问题讨论】:

    标签: ruby rubygems require rubymine uninitialized-constant


    【解决方案1】:

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

    def RealFile.const_missing const
      const_set const, 42
    end
    

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

    写下这个

    有一个带有一些 Windows 修复的 fork(这家伙评论了所有标志):https://github.com/vertiginous/fakefs

    【讨论】:

    • 添加该方法可以解决问题。还要感谢您指出 Windows 修复的分支。
    猜你喜欢
    • 2023-03-20
    • 2010-09-29
    • 2012-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-08
    • 2012-10-10
    相关资源
    最近更新 更多