gpt4 book ai didi

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

转载 作者:数据小太阳 更新时间:2023-10-29 07:35:02 24 4
gpt4 key购买 nike

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

最佳答案

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

def RealFile.const_missing const
const_set const, 42
end

真的,我不知道它会不会在将来引起任何问题,但至少您将能够运行您的脚本。我认为你应该写在 github

有一个带有一些 Windows 修复程序的分支(这个人完全评论了所有标志):https://github.com/vertiginous/fakefs

关于ruby - 未初始化常量 File::NOCTTY 错误,当我需要 'fakefs',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5695831/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com