Rspec 测试失败,并显示“NameError: uninitializedconstant ActionController::TestCase::Assertions”
我正在开发一个示例 RoR 应用程序,但在使用 rspec 测试它时遇到了问题。我已经安装了 rspec 并运行了测试,但是它们失败了,我不知道为什么。我运行命令:
bundle exec rspec spec/
当我运行这个命令时;这是我收到的错误消息:
Failures:
1) PagesController GET 'home' should be successful
Failure/Error: Unable to find matching line from backtrace
NameError:
uninitialized constant ActionController::TestCase::Assertions
# /usr/lib/ruby/vendor_ruby/action_controller/integration.rb:18
# /usr/lib/ruby/gems/1.8/gems/webrat-0.7.1/lib/webrat/integrations/rails.rb:2
# /usr/lib/ruby/gems/1.8/gems/webrat-0.7.1/lib/webrat/core/configuration.rb:105:in `mode='
# /usr/lib/ruby/gems/1.8/gems/rspec-rails-2.6.1/lib/rspec/rails/vendor/webrat.rb:26
# /usr/lib/ruby/gems/1.8/gems/webrat-
还有更多错误消息。
我不是 RoR 方面的专家,非常感谢您的帮助。提前致谢。
I am working on a sample RoR app and I am having trouble testing it with rspec. I have rspec installed and running the tests however they are failing and I don't know why. I run the command:
bundle exec rspec spec/
And when I run this; this is the error message I get:
Failures:
1) PagesController GET 'home' should be successful
Failure/Error: Unable to find matching line from backtrace
NameError:
uninitialized constant ActionController::TestCase::Assertions
# /usr/lib/ruby/vendor_ruby/action_controller/integration.rb:18
# /usr/lib/ruby/gems/1.8/gems/webrat-0.7.1/lib/webrat/integrations/rails.rb:2
# /usr/lib/ruby/gems/1.8/gems/webrat-0.7.1/lib/webrat/core/configuration.rb:105:in `mode='
# /usr/lib/ruby/gems/1.8/gems/rspec-rails-2.6.1/lib/rspec/rails/vendor/webrat.rb:26
# /usr/lib/ruby/gems/1.8/gems/webrat-
And alot more error messages.
I'm no expert on RoR and would really appreciate help. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
RSpec 仅保证在 Rail 默认情况下开箱即用。从 Gemfile 中删除 webrat 并重试。
根据教程,这可能会在后面的步骤中再次破坏事情。
我解决这个问题的方法是删除 Rails 的软件包安装(apt-get removerails && apt-get autoremove)及其依赖项,因为它显然与 gem 安装发生冲突。很好理解。您可以使用 gem 安装它(sudo gem install Rails)
RSpec is only guaranteed to work out of the box for Rail defaults. Remove webrat from your Gemfile and try it again.
Depending on the tutorial this might break things again in later steps.
My solution to the problem was to remove the package installation of rails (apt-get remove rails && apt-get autoremove) and its dependencies, because it was apparently clashing with the gem install. Quite understandable. You can install it with gem (sudo gem install rails)
我在新安装的 Ubuntu 11.10 上遇到了同样的问题。
在确保我使用的是最新版本的 rspec 并且使用 Rails 安装后,
我还确保卸载 ubuntu Rails 不会留下任何痕迹,
我还有 ruby 1.8.7,所以我切换到 1.9.2
我的 ruby 版本是问题或自动删除消除了一些干扰。但在那之后事情就开始起作用了。
I had the same problem on a fresh Ubuntu 11.10 install.
After ensuring I was using the latest versions of rspec and that rails was installed using
I also ensured that uninstalling the ubuntu rails didn't leave any artificts with
I also had ruby 1.8.7 so I switched to 1.9.2
Either my ruby version was the problem or the autoremove removed some interference. But things were working after that.