我正在尝试为 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
我在 Rails 3.0.5 和 ruby 1.9.2 下。
我这里没有线索可以看。我已经卸载了rspec
和rspec-rails
gems 并重新安装了它们,但没有成功。我既没有autotest
也没有Spork
安装来运行测试。
有人有想法吗?
非常感谢!