运行spec命令时未初始化的常量Spec::Rails (NameError)

发布于 2024-12-06 05:31:38 字数 1460 浏览 0 评论 0原文

尝试在模型测试上运行规范命令时出现以下错误。

命令是:

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:in require' 来自 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:in require'
from c:/jruby-1.5.0/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31
:in
require'
from C:/Rspec Test/vendor/rails/activesupport/lib/active_support/depende
ncies.rb:158:in 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
require'
from c:/jruby-1.5.0/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31
:in require'
from C:/Rspec Test/vendor/rails/activesupport/lib/active_support/depende
ncies.rb:158:in
require'
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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一人独醉 2024-12-13 05:31:38

此错误表明 rspec 框架未加载到执行此代码的环境中。

uninitialized constant Spec::Rails (NameError)

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.

uninitialized constant Spec::Rails (NameError)

Rails 3 requires rspec 2 . Development of rspec-rails-2 has moved to github.com/rspec/rspec-rails.

温馨耳语 2024-12-13 05:31:38

不确定这是否有帮助,因为这个问题已经很老了,但我只是通过谷歌找到它,所以这可能会对某人有所帮助。

我也使用 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 to RSpec::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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文