我正在尝试为Rails上的页面设置简单控制器的Rspec测试,并出现以下错误:
/var/lib/gems/1.9.1/gems/rspec-core-2.0.1/lib/rspec/core/backward_compatibility.rb:20:in `const_missing': uninitialized constant Object::PagesController (NameError)
from /var/lib/gems/1.9.1/gems/rspec-expectations-2.0.1/lib/rspec/expectations/backward_compatibility.rb:6:in `const_missing'
from /media/sf_ruby/tapa-g/spec/controllers/pages_controller_spec.rb:3:in `<top (required)>'
from /var/lib/gems/1.9.1/gems/rspec-core-2.0.1/lib/rspec/core/configuration.rb:306:in `load'
from /var/lib/gems/1.9.1/gems/rspec-core-2.0.1/lib/rspec/core/configuration.rb:306:in `block in load_spec_files'
from /var/lib/gems/1.9.1/gems/rspec-core-2.0.1/lib/rspec/core/configuration.rb:306:in `map'
from /var/lib/gems/1.9.1/gems/rspec-core-2.0.1/lib/rspec/core/configuration.rb:306:in `load_spec_files'
from /var/lib/gems/1.9.1/gems/rspec-core-2.0.1/lib/rspec/core/command_line.rb:18:in `run'
from /var/lib/gems/1.9.1/gems/rspec-core-2.0.1/lib/rspec/core/runner.rb:55:in `run_in_process'
from /var/lib/gems/1.9.1/gems/rspec-core-2.0.1/lib/rspec/core/runner.rb:46:in `run'
from /var/lib/gems/1.9.1/gems/rspec-core-2.0.1/lib/rspec/core/runner.rb:10:in `block in autorun'
无论我输入什么命令行,我都会收到此错误,即:
bundle exec rspec spec/controllers/pages_controller_spec.rb
rake spec
rspec spec/
我在spec / controllers / pages_controller_sprec.rb文件中进行了以下测试:
require 'spec_helper'
describe PagesController do
render_views
describe "GET 'home'" do
it "should be successful" do
get 'home'
response.should be_success
end
end
end
app / controllers / pages_controller.rb文件中的控制器如下所示:
class PagesController < ApplicationController
skip_authorization_check
def home
@title = "Home"
end
end
与其他行动相关但在此处不相关。
以下是我的Gemfile中的宝石:
source 'http://rubygems.org'
gem 'rails', '3.0.5'
gem 'will_paginate', '3.0.pre2'
gem 'jquery-rails', '>= 1.0.12'
gem "paperclip", "2.4.5"
gem "rake", "0.8.7"
gem "devise"
gem "cancan"
gem 'aws-s3'
gem 'acts_as_tree'
group :development do
gem 'rspec-rails', "2.0.1"
gem 'annotate'
gem 'faker', '0.3.1', :require => false
gem 'populator', '1.0.0'
gem 'ruby-debug19'
end
group :test do
gem 'webrat', '0.7.1'
gem "capybara"
gem 'rspec', '2.0.1'
gem 'factory_girl_rails', '1.0'
end
我使用ruby 1.9.2在Rails 3.0.5下。
我在这里看不到任何线索。我已经卸载了rspec
和rspec-rails
宝石并重新安装它们但没有太大成功。我没有安装autotest
和Spork
来运行测试。
有人有想法吗?
非常感谢!
答案 0 :(得分:1)
好吧,在对类似案例发表各种评论后,我只需使用apt-get uninstall rspec
安装rspec,然后使用rspec-rails
重新安装gem install rspec-rails
。现在测试正在进行中。