运行spec命令时未初始化的常量Spec::Rails (NameError)
尝试在模型测试上运行规范命令时出现以下错误。
命令是:
C:\Rspec Test\spec\models>spec bank_account_spec.rb
错误是:
c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rspec-rails-1.3.0/lib/spec/rails/matchers/ ar_be_valid.rb:2: 未初始化常量 Spec::Rails (NameError) 来自 c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rspec-rails-1.3.0/lib/spec/ra ils/matchers/ar_be_valid.rb:31:inrequire' 来自 c:/jruby-1.5.0/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31 :在
需要' 来自 C:/Rspec Test/vendor/rails/activesupport/lib/active_support/depende ncies.rb:158:在需要' 来自 c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rspec-rails-1.3.0/lib/spec/ra ils/matchers.rb:2 来自 c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rspec-rails-1.3.0/lib/spec/ra ils/matchers.rb:31:in
需要' 来自 c:/jruby-1.5.0/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31 :在中要求' 来自 C:/Rspec Test/vendor/rails/activesupport/lib/active_support/depende ncies.rb:158:in
需要' 来自 c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rspec-rails-1.3.0/lib/spec/ra ls.rb:15 ... 13 个级别... 来自 C:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rspec-1.3.0/bin/spec:5 来自 C:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rspec-1.3.0/bin/spec:22:in `l 奥阿德 来自c:/jruby-1.5.0/bin/spec:22
我实际上尝试在 C:\jruby-1.5.0\bin\spec
文件中将版本更改为 1.3.0,但结果是同样的错误。
I get the following error when trying to run a spec command on a model test.
The command is:
C:\Rspec Test\spec\models>spec bank_account_spec.rb
The error is :
c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rspec-rails-1.3.0/lib/spec/rails/matchers/
ar_be_valid.rb:2: uninitialized constant Spec::Rails (NameError)
from c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rspec-rails-1.3.0/lib/spec/ra
ils/matchers/ar_be_valid.rb:31:inrequire'
require'
from c:/jruby-1.5.0/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31
:in
from C:/Rspec Test/vendor/rails/activesupport/lib/active_support/depende
ncies.rb:158:inrequire'
require'
from c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rspec-rails-1.3.0/lib/spec/ra
ils/matchers.rb:2
from c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rspec-rails-1.3.0/lib/spec/ra
ils/matchers.rb:31:in
from c:/jruby-1.5.0/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31
:inrequire'
require'
from C:/Rspec Test/vendor/rails/activesupport/lib/active_support/depende
ncies.rb:158:in
from c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rspec-rails-1.3.0/lib/spec/ra
ils.rb:15
... 13 levels...
from C:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rspec-1.3.0/bin/spec:5
from C:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rspec-1.3.0/bin/spec:22:in `l
oad'
from c:/jruby-1.5.0/bin/spec:22
I actually tried changing version to 1.3.0 in the C:\jruby-1.5.0\bin\spec
file but it results in the same error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
此错误表明 rspec 框架未加载到执行此代码的环境中。
Rails 3 需要 rspec 2 。 rspec-rails-2 的开发已移至 github.com/rspec/rspec-rails。
This error suggests that the rspec framework is not getting loaded in the environment where this code is executing.
Rails 3 requires rspec 2 . Development of rspec-rails-2 has moved to github.com/rspec/rspec-rails.
不确定这是否有帮助,因为这个问题已经很老了,但我只是通过谷歌找到它,所以这可能会对某人有所帮助。
我也使用
Spec::Matchers.define
声明了我的匹配器,这是在网上找到的一些示例中的。显然,这已经过时了,一旦我将定义更改为 RSpec::Matchers.define(注意“RSpec”中的“R”),一切又恢复正常了。我只在调试模式下收到错误,并且我没有使用 JRuby,但这可能仍然值得一试,而且无论如何它都更正确。
Not sure if this helps any more, since the question is quite old, but I just found it through google, so this might help someone.
I too had declared my matcher using
Spec::Matchers.define
, out of some example found online. Apparently, this is outdated, once I changed the definition toRSpec::Matchers.define
(mind the 'R' in 'RSpec'), things worked fine again.I only got the error in debug mode and I am not using JRuby, but this might still be worth a try, and it's more correct anyway.