关注http://ruby.railstutorial.org/教程时出现RSpec错误

时间:2011-02-17 17:07:37

标签: ruby-on-rails

我到处搜索,但似乎无法找到解决方案。我一直在关注http://ruby.railstutorial.org/上的教程,我正在第3章尝试使用“rspec spec /”来执行测试

但是我一直收到以下错误:

Failure/Error: Unable to find matching line from backtrace
 NameError:
   uninitialized constant ActionController::TestCase::Assertions
 # /var/lib/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/backward_compatibility.rb:20:in `const_missing'
 # /var/lib/gems/1.8/gems/rspec-expectations-2.5.0/lib/rspec/expectations/backward_compatibility.rb:6:in `const_missing'
 # /usr/lib/ruby/1.8/action_controller/integration.rb:18
 # /var/lib/gems/1.8/gems/webrat-0.7.1/lib/webrat/integrations/rails.rb:2
 # /var/lib/gems/1.8/gems/webrat-0.7.1/lib/webrat/core/configuration.rb:105:in `mode='
 # /var/lib/gems/1.8/gems/rspec-rails-2.5.0/lib/rspec/rails/example/controller_example_group.rb:172
 # /var/lib/gems/1.8/gems/webrat-0.7.1/lib/webrat/core/configuration.rb:9:in `configure'
 # /var/lib/gems/1.8/gems/rspec-rails-2.5.0/lib/rspec/rails/example/controller_example_group.rb:172
 # /var/lib/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/hooks.rb:29:in `instance_eval'
 # /var/lib/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/hooks.rb:29:in `run_in'
 # /var/lib/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/hooks.rb:64:in `run_all'
 # /var/lib/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/hooks.rb:64:in `each'
 # /var/lib/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/hooks.rb:64:in `run_all'
 # /var/lib/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/hooks.rb:110:in `run_hook'
 # /var/lib/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:191:in `eval_before_eachs'
 # /var/lib/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:191:in `each'
 # /var/lib/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:191:in `eval_before_eachs'
 # /var/lib/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example.rb:144:in `run_before_each'
 # /var/lib/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example.rb:48:in `run'
 # /var/lib/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example.rb:106:in `with_around_hooks'
 # /var/lib/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example.rb:46:in `run'
 # /var/lib/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example.rb:99:in `with_pending_capture'
 # /var/lib/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example.rb:98:in `catch'
 # /var/lib/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example.rb:98:in `with_pending_capture'
 # /var/lib/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example.rb:45:in `run'
 # /var/lib/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:262:in `run_examples'
 # /var/lib/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:258:in `map'
 # /var/lib/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:258:in `run_examples'
 # /var/lib/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:232:in `run'
 # /var/lib/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:233:in `run'
 # /var/lib/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:233:in `map'
 # /var/lib/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:233:in `run'
 # /var/lib/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/command_line.rb:27:in `run'
 # /var/lib/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/command_line.rb:27:in `map'
 # /var/lib/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/command_line.rb:27:in `run'
 # /var/lib/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/reporter.rb:12:in `report'
 # /var/lib/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/command_line.rb:24:in `run'
 # /var/lib/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:55:in `run_in_process'
 # /var/lib/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:46:in `run'
 # /var/lib/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:10:in `autorun'
 # /var/lib/gems/1.8/bin/rspec:19

我试图在没有运气的情况下卸载并重新安装宝石。

这是我的宝石列表:

    *** LOCAL GEMS ***

abstract (1.0.0)
actionmailer (3.0.4, 3.0.3)
actionpack (3.0.4, 3.0.3)
activemodel (3.0.4, 3.0.3)
activerecord (3.0.4, 3.0.3)
activerecord-oracle_enhanced-adapter (1.3.2, 1.3.1)
activeresource (3.0.4, 3.0.3)
activesupport (3.0.4, 3.0.3)
arel (2.0.8, 2.0.7)
autotest (4.4.6)
autotest-rails-pure (4.1.2)
builder (3.0.0, 2.1.2)
bundler (1.0.10)
cgi_multipart_eof_fix (2.5.0)
daemon_controller (0.2.6, 0.2.5)
diff-lcs (1.1.2)
erubis (2.6.6)
fastthread (1.0.7)
file-tail (1.0.5)
gem_plugin (0.2.3)
i18n (0.5.0)
mail (2.2.15, 2.2.14)
mime-types (1.16)
nifty-generators (0.4.5, 0.4.4)
nokogiri (1.4.4)
passenger (3.0.2)
polyglot (0.3.1)
rack (1.2.1)
rack-mount (0.6.13)
rack-test (0.5.7)
rails (3.0.4, 3.0.3)
railties (3.0.4, 3.0.3)
rake (0.8.7)
redgreen (1.2.2)
rspec (2.3.0)
rspec-core (2.3.1)
rspec-expectations (2.3.0)
rspec-mocks (2.3.0)
rspec-rails (2.3.0)
ruby-oci8 (2.0.4)
spruz (0.2.5)
sqlite3 (1.3.3)
sqlite3-ruby (1.3.3, 1.3.2)
sys-uname (0.8.5)
thor (0.14.6)
treetop (1.4.9)
tzinfo (0.3.24)
webrat (0.7.3, 0.7.1)
ZenTest (4.4.2)

宝石文件

source 'http://rubygems.org'

gem 'rails', '3.0.4'
gem 'sqlite3-ruby', '1.3.2', :require => 'sqlite3'

group :development do
  gem 'rspec-rails', '2.5.0'
end

group :test do
  gem 'rspec', '2.5.0'
  gem 'webrat', '0.7.1'
end

6 个答案:

答案 0 :(得分:3)

我找到了与m.galkiewicz类似的解决方案。 我在ubuntu 10.10上。我发现此问题是因为您的错误中包含以下行:  #/usr/lib/ruby/1.8/action_controller/integration.rb:18

当我与在相同版本的ubuntu上运行安装的朋友比较时,action_controller不在/usr/lib/ruby/1.8路径中。

我发现我已经通过apt-get安装了rails和rake,而不是通过rubygems。以下是我为实现这一目标所做的修改:

  1. sudo apt-get remove rails
  2. sudo gem install rails
  3. sudo bundle install
  4. 然后我能够运行rspec并继续学习本教程。

答案 1 :(得分:2)

我设法通过从apt-get移除rails(如其他人之前推荐的)并从rubygems安装来实现这一点,但这还不够。然后有必要运行'apt-get autoremove'。现在一切都很好。

答案 2 :(得分:1)

我也正在阅读这本书,并且正在记录它如何发展www.ridingrails.co.uk可能有所帮助。 我的Gemfile看起来像

source 'http://rubygems.org'

gem 'rails', '3.0.11'
gem 'sqlite3', '1.3.3'
gem 'heroku'
gem 'spork', '0.9.0.rc8'
gem 'gravatar_image_tag', '0.1.0'

group :development do
  gem 'rspec-rails', '2.6.1'
  gem 'annotate'
end

group :test do
  gem 'rspec-rails', '2.6.1'
  gem 'webrat', '0.7.1'
  gem 'factory_girl_rails'
end

但是花了我一点时间让一切运转起来。我会看看这本书使用那里的宝石。

答案 3 :(得分:0)

尝试将rspec升级到2.5.0
你应该有:
rspec(2.5.0)
rspec-core(2.5.1)
rspec-expectations(2.5.0)
rspec-mocks(2.5.0)
rspec-rails(2.5.0)

删除webrat 0.7.1,保持0.7.3
webrat(0.7.3)

答案 4 :(得分:0)

我在debian挤压时遇到了同样的问题。确保从rubygems而不是发行版的存储库安装了rails和其他ruby相关软件包。

ii libruby 4.5 ii libruby1.8 1.8.7.302-2 ii libruby1.9.1 1.9.2.0-2 ii libxml-ruby1.8 1.1.3-2 ii libxslt-ruby 0.9.2-5 ii libxslt-ruby1.8 0.9.2-5 ii ruby​​ 4.5
ii ruby​​-dev 4.5
ii ruby​​1.8 1.8.7.302-2 ii ruby​​1.8-dev 1.8.7.302-2 ii ruby​​1.9.1 1.9.2.0-2 ii ruby​​gems 1.3.7-3 ii ruby​​gems1.8 1.3.7-3

答案 5 :(得分:0)

我们遇到了这个问题。 我们查看了回溯,它是:

  16) DesktopsController DELETE destroy redirects to the desktops list
 Failure/Error: Unable to find matching line from backtrace
 NameError:
   uninitialized constant ActionController::TestCase::Assertions
 # /var/lib/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/backward_compatibility.rb:20:in `const_missing'
 # /var/lib/gems/1.8/gems/rspec-expectations-2.5.0/lib/rspec/expectations/backward_compatibility.rb:6:in `const_missing'
 # /usr/lib/ruby/1.8/action_controller/integration.rb:18
 # /var/lib/gems/1.8/gems/webrat-0.7.3/lib/webrat/integrations/rails.rb:2

注意到这需要来自webrat的dpkg'ed rails,我们查看了integration / rails.rb。我们看到它包括action_controller / integration.rb。 看看我们的action_controller 3.0.4,我们发现它不再存在了。 当然,删除已安装的dpkg可能会改变这个问题,但实际上它是webrat 0.7.3和action_controller 3.0.4之间的API不兼容。 我没有看到更新版本的webrat,所以我们将使用这个手动补丁,因为我们只需要测试而不是生产。