gpt4 book ai didi

ruby - Rspec/mocks 引发未初始化的常量 BasicObject::RSpec

转载 作者:太空宇宙 更新时间:2023-11-03 16:05:17 26 4
gpt4 key购买 nike

我刚刚安装了 rspec 和 rspec-mocks 但我无法运行最简单的设置

irb(main):001:0> require 'rspec'
=> true
irb(main):004:0> require 'rspec/mocks'
=> false
irb(main):006:0> RSpec::Mocks::setup(Object.new)
NameError: uninitialized constant BasicObject::RSpec
from /usr/local/Cellar/ruby/1.9.1-p376/lib/ruby/gems/1.9.1/gems/rspec-mocks-2.13.0/lib/rspec/mocks.rb:60:in `block in add_extensions'
from /usr/local/Cellar/ruby/1.9.1-p376/lib/ruby/gems/1.9.1/gems/rspec-mocks-2.13.0/lib/rspec/mocks.rb:60:in `class_eval'
from /usr/local/Cellar/ruby/1.9.1-p376/lib/ruby/gems/1.9.1/gems/rspec-mocks-2.13.0/lib/rspec/mocks.rb:60:in `add_extensions'
from /usr/local/Cellar/ruby/1.9.1-p376/lib/ruby/gems/1.9.1/gems/rspec-mocks-2.13.0/lib/rspec/mocks.rb:11:in `setup'
from (irb):6
from /usr/local/Cellar/ruby/1.9.1-p376/bin/irb:12:in `<main>'

我想知道可能出了什么问题,我是否需要加载其他 gem?

最佳答案

Jonathan 在正确的轨道上,但问题的根源是与 1.8.7 的不兼容,因为::BasicObject 仍然存在于 Ruby 1.9 中。

通过将 补丁 限制为 Ruby 1.8 来更恰本地指定作者正在修补的内容的正确解决方案:

def method_host
# On 1.8.7, Object.ancestors.last == Kernel but
# things blow up if we include `RSpec::Mocks::Methods`
# into Kernel...not sure why.
return Object unless defined?(::BasicObject) && RUBY_VERSION =~ /^1\.8\.\d+/

# MacRuby has BasicObject but it's not the root class.
return Object unless Object.ancestors.last == ::BasicObject

::BasicObject
end

关于ruby - Rspec/mocks 引发未初始化的常量 BasicObject::RSpec,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15282389/

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