所以我试图用
运行rspec测试$ rspec spec / models
但我收到此错误
/home/kenny/WorkSpace/FeedingForward/app/admin/admin_user.rb:1:in
<top (required)>': uninitialized constant AdminUser (NameError) from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/backports-2.6.7/lib/backports/tools.rb:314:in
require' 来自/home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/backports-2.6.7/lib/backports/tools.rb:314:inrequire_with_backports' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/activesupport-3.2.13/lib/active_support/inflector/methods.rb:230:in
块中的constantize' 来自/home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/activesupport-3.2.13/lib/active_support/inflector/methods.rb:229:ineach' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/activesupport-3.2.13/lib/active_support/inflector/methods.rb:229:in
constantize' 从/home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/devise-2.1.3/lib/devise.rb:256:inget' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/devise-2.1.3/lib/devise/mapping.rb:77:in
到' 来自/home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/devise-2.1.3/lib/devise/mapping.rb:72:inmodules' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/devise-2.1.3/lib/devise/mapping.rb:89:in
routes' 来自/home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/devise-2.1.3/lib/devise/mapping.rb:156:indefault_used_route' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/devise-2.1.3/lib/devise/mapping.rb:66:in
initialize' 来自/home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/devise-2.1.3/lib/devise.rb:290:innew' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/devise-2.1.3/lib/devise.rb:290:in
add_mapping' 来自/home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/devise-2.1.3/lib/devise/rails/routes.rb:208:inblock in devise_for' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/devise-2.1.3/lib/devise/rails/routes.rb:207:in
每个' 来自/home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/devise-2.1.3/lib/devise/rails/routes.rb:207:indevise_for' from /home/kenny/WorkSpace/FeedingForward/config/routes.rb:41:in
阻止' 来自/home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/actionpack-3.2.13/lib/action_dispatch/routing/route_set.rb:289:ininstance_exec' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/actionpack-3.2.13/lib/action_dispatch/routing/route_set.rb:289:in
eval_block' 来自/home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/actionpack-3.2.13/lib/action_dispatch/routing/route_set.rb:267:indraw' from /home/kenny/WorkSpace/FeedingForward/config/routes.rb:1:in
' 来自/home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.13/lib/rails/application/routes_reloader.rb:40:inblock in load_paths' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.13/lib/rails/application/routes_reloader.rb:40:in
每个' 来自/home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.13/lib/rails/application/routes_reloader.rb:40:inload_paths' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.13/lib/rails/application/routes_reloader.rb:16:in
重装! 来自/home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.13/lib/rails/application.rb:108:inreload_routes!' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/activeadmin-0.6.0/lib/active_admin/reloader.rb:34:in
重装! 来自/home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/activeadmin-0.6.0/lib/active_admin/reloader.rb:61:inblock in attach!' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:429:in
运行 _191199301_ 制备 _874569490__callbacks' 来自/home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:405:in__run_callback' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:385:in
_ run_prepare_callbacks' 来自/home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:81:inrun_callbacks' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/actionpack-3.2.13/lib/action_dispatch/middleware/reloader.rb:74:in
准备! 来自/home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/actionpack-3.2.13/lib/action_dispatch/middleware/reloader.rb:48:inprepare!' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.13/lib/rails/application/finisher.rb:47:in
阻止' 来自/home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.13/lib/rails/initializable.rb:30:ininstance_exec' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.13/lib/rails/initializable.rb:30:in
run' 来自/home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.13/lib/rails/initializable.rb:55:inblock in run_initializers' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.13/lib/rails/initializable.rb:54:in
每个' 来自/home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.13/lib/rails/initializable.rb:54:inrun_initializers' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.13/lib/rails/application.rb:136:in
初始化!' 来自/home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.13/lib/rails/railtie/configurable.rb:30:inmethod_missing' from /home/kenny/WorkSpace/FeedingForward/config/environment.rb:5:in
' 来自/home/kenny/WorkSpace/FeedingForward/spec/spec_helper.rb:3:inrequire' from /home/kenny/WorkSpace/FeedingForward/spec/spec_helper.rb:3:in
' 来自/home/kenny/WorkSpace/FeedingForward/spec/models/delivery_spec.rb:1:inrequire' from /home/kenny/WorkSpace/FeedingForward/spec/models/delivery_spec.rb:1:in
' 来自/home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/rspec-core-2.12.2/lib/rspec/core/configuration.rb:789:inload' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/rspec-core-2.12.2/lib/rspec/core/configuration.rb:789:in
块中的load_spec_files “ 来自/home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/rspec-core-2.12.2/lib/rspec/core/configuration.rb:789:ineach' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/rspec-core-2.12.2/lib/rspec/core/configuration.rb:789:in
load_spec_files' 来自/home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/rspec-core-2.12.2/lib/rspec/core/command_line.rb:22:inrun' from /home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/rspec-core-2.12.2/lib/rspec/core/runner.rb:80:in
run' 来自/home/kenny/.rvm/gems/ruby-1.9.3-p362/gems/rspec-core-2.12.2/lib/rspec/core/runner.rb:17:in,clock in autorun'
以下是admin目录中admin_user的代码
ActiveAdmin.register AdminUser do
index do
column :email
column :primary_phone
我在models目录中也有一个admin_user类
class AdminUser < ActiveRecord::Base
after_initialize :init
devise :database_authenticatable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :primary_phone, :password, :password_confirmation, :remember_me, :notify_by_sms, :notify_by_email
# attr_accessible :title, :body
protected
def init
self.notify_by_sms ||= false
self.notify_by_email ||= true
end
end
答案 0 :(得分:0)
看起来您的测试数据库中缺少架构。确保您也为测试环境运行迁移。
RAILS_ENV=test be rake db:migrate