Rspec 测试失败,并显示“NameError: uninitializedconstant ActionController::TestCase::Assertions”

发布于 2024-12-11 23:33:55 字数 835 浏览 0 评论 0原文

我正在开发一个示例 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 技术交流群。

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

发布评论

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

评论(2

话少情深 2024-12-18 23:33:55

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)

无所谓啦 2024-12-18 23:33:55

我在新安装的 Ubuntu 11.10 上遇到了同样的问题。

在确保我使用的是最新版本的 rspec 并且使用 Rails 安装后,

gem install rails 

我还确保卸载 ubuntu Rails 不会留下任何痕迹,

sudo apt-get autoremove

我还有 ruby​​ 1.8.7,所以我切换到 1.9.2

rvm use 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

gem install rails 

I also ensured that uninstalling the ubuntu rails didn't leave any artificts with

sudo apt-get autoremove

I also had ruby 1.8.7 so I switched to 1.9.2

rvm use 1.9.2 

Either my ruby version was the problem or the autoremove removed some interference. But things were working after that.

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