Ruby on Rails测试加载程序失败

时间:2012-09-04 17:43:56

标签: ruby-on-rails

我正在尝试运行其他人在Ruby on Rails中编写的一些测试。他们过去但不再通过了。这就是我作为堆栈跟踪获得的内容:

USERNAME:functional user.name$ rake test
(in /Users/user.name/workspace/Build Visibility/Rails)
/Users/user.name/workspace/Build Visibility/Rails/config/routes.rb:9:in `block in <top (required)>': Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id (RuntimeError)
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.6/lib/action_dispatch/routing/route_set.rb:282:in `instance_exec'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.6/lib/action_dispatch/routing/route_set.rb:282:in `eval_block'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.6/lib/action_dispatch/routing/route_set.rb:260:in `draw'
    from /Users/user.name/workspace/Build Visibility/Rails/config/routes.rb:1:in `<top (required)>'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:245:in `load'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:245:in `block in load'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:236:in `load_dependency'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:245:in `load'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.6/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.6/lib/rails/application/routes_reloader.rb:40:in `each'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.6/lib/rails/application/routes_reloader.rb:40:in `load_paths'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.6/lib/rails/application/routes_reloader.rb:16:in `reload!'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.6/lib/rails/application.rb:108:in `reload_routes!'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194/gems/devise-2.1.2/lib/devise/rails.rb:14:in `block in <class:Engine>'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/lazy_load_hooks.rb:34:in `call'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/lazy_load_hooks.rb:34:in `execute_hook'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/lazy_load_hooks.rb:43:in `block in run_load_hooks'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/lazy_load_hooks.rb:42:in `each'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.6/lib/rails/application/finisher.rb:52:in `block in <module:Finisher>'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.6/lib/rails/initializable.rb:30:in `instance_exec'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.6/lib/rails/initializable.rb:30:in `run'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.6/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.6/lib/rails/initializable.rb:54:in `each'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.6/lib/rails/initializable.rb:54:in `run_initializers'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.6/lib/rails/application.rb:136:in `initialize!'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.6/lib/rails/railtie/configurable.rb:30:in `method_missing'
    from /Users/user.name/workspace/Build Visibility/Rails/config/environment.rb:5:in `<top (required)>'
    from /Users/user.name/workspace/Build Visibility/Rails/test/test_helper.rb:2:in `require'
    from /Users/user.name/workspace/Build Visibility/Rails/test/test_helper.rb:2:in `<top (required)>'
    from /Users/user.name/workspace/Build Visibility/Rails/test/unit/teams_test.rb:1:in `require'
    from /Users/user.name/workspace/Build Visibility/Rails/test/unit/teams_test.rb:1:in `<top (required)>'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:10:in `require'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:10:in `block (2 levels) in <main>'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:9:in `each'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:9:in `block in <main>'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:4:in `select'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:4:in `<main>'
/Users/user.name/workspace/Build Visibility/Rails/config/routes.rb:9:in `block in <top (required)>': Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id (RuntimeError)
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.6/lib/action_dispatch/routing/route_set.rb:282:in `instance_exec'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.6/lib/action_dispatch/routing/route_set.rb:282:in `eval_block'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.6/lib/action_dispatch/routing/route_set.rb:260:in `draw'
    from /Users/user.name/workspace/Build Visibility/Rails/config/routes.rb:1:in `<top (required)>'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:245:in `load'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:245:in `block in load'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:236:in `load_dependency'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:245:in `load'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.6/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.6/lib/rails/application/routes_reloader.rb:40:in `each'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.6/lib/rails/application/routes_reloader.rb:40:in `load_paths'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.6/lib/rails/application/routes_reloader.rb:16:in `reload!'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.6/lib/rails/application.rb:108:in `reload_routes!'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194/gems/devise-2.1.2/lib/devise/rails.rb:14:in `block in <class:Engine>'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/lazy_load_hooks.rb:34:in `call'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/lazy_load_hooks.rb:34:in `execute_hook'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/lazy_load_hooks.rb:43:in `block in run_load_hooks'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/lazy_load_hooks.rb:42:in `each'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.6/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.6/lib/rails/application/finisher.rb:52:in `block in <module:Finisher>'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.6/lib/rails/initializable.rb:30:in `instance_exec'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.6/lib/rails/initializable.rb:30:in `run'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.6/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.6/lib/rails/initializable.rb:54:in `each'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.6/lib/rails/initializable.rb:54:in `run_initializers'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.6/lib/rails/application.rb:136:in `initialize!'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.6/lib/rails/railtie/configurable.rb:30:in `method_missing'
    from /Users/user.name/workspace/Build Visibility/Rails/config/environment.rb:5:in `<top (required)>'
    from /Users/user.name/workspace/Build Visibility/Rails/test/test_helper.rb:2:in `require'
    from /Users/user.name/workspace/Build Visibility/Rails/test/test_helper.rb:2:in `<top (required)>'
    from /Users/user.name/workspace/Build Visibility/Rails/test/functional/buildtools_controller_test.rb:1:in `require'
    from /Users/user.name/workspace/Build Visibility/Rails/test/functional/buildtools_controller_test.rb:1:in `<top (required)>'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:10:in `require'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:10:in `block (2 levels) in <main>'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:9:in `each'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:9:in `block in <main>'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:4:in `select'
    from /Users/user.name/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:4:in `<main>'
Errors running test:units! #<RuntimeError: Command failed with status (1): [/Users/user.name/.rvm/rubies/ruby-1.9....]>
Errors running test:functionals! #<RuntimeError: Command failed with status (1): [/Users/user.name/.rvm/rubies/ruby-1.9....]>

任何帮助或见解都会很棒。谢谢!

修改

SampleApp::Application.routes.draw do

  # devise_for :users do get '/users/sign_out' => 'devise/sessions#destroy' end

  match '/administration' => 'administration#show'
  match '/administration/:id' => 'administration#show' 
  match 'environment/:display_name' => 'environments#show'

  root :to => 'displays#show', :page => 1, :tab => Tab.first.id

  resources :settings do
    collection do 
      post "update_all"
    end
  end
  resources :buildtools do
    collection do
      post "update_all"
    end
  end
  resources :environments do
    collection do
      put :update_order
      post "update_all"
    end
  end
  resources :projects do
    collection do
      post "update_all"
    end
  end 
  resources :teams do
    collection do 
      put :update_order
      post "update_all"
      get "column_sort"
    end
    member do
      get "show_history"
    end
  end
  resources :plans do 
    collection do 
      post "update_all"
    end
  end
  resources :test_suites do
    collection do 
      post "update_all"
    end
  end
  resources :tabs do
    collection do
      put :update_order
    end
  end
  resources :environment_teams do
    collection do
        put :update_order
    end
  end
  resources :pages do
    collection do
      put :update_order
      post "update_all"
    end
  end
  resource  :display do
    collection do
      get "reset"
    end
  end
  resources :user, :controller => "user"
end
#SampleApp::Application.routes.draw do
  # The priority is based upon order of creation:
  # first created -> highest priority.

  # Sample of regular route:
  #   match 'products/:id' => 'catalog#view'
  # Keep in mind you can assign values other than :controller and :action

  # Sample of named route:
  #   match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
  # This route can be invoked with purchase_url(:id => product.id)

  # Sample resource route (maps HTTP verbs to controller actions automatically):
  #   resources :products

  # Sample resource route with options:
  #   resources :products do
  #     member do
  #       get 'short'
  #       post 'toggle'
  #     end
  #
  #     collection do
  #       get 'sold'
  #     end
  #   end

  # Sample resource route with sub-resources:
  #   resources :products do
  #     resources :comments, :sales
  #     resource :seller
  #   end

  # Sample resource route with more complex sub-resources
  #   resources :products do
  #     resources :comments
  #     resources :sales do
  #       get 'recent', :on => :collection
  #     end
  #   end

  # Sample resource route within a namespace:
  #   namespace :admin do
  #     # Directs /admin/products/* to Admin::ProductsController
  #     # (app/controllers/admin/products_controller.rb)
  #     resources :products
  #   end

  # You can have the root of your site routed with "root"
  # just remember to delete public/index.html.
  # root :to => 'welcome#index'

  # See how all your routes lay out with "rake routes"

  # This is a legacy wild controller route that's not recommended for RESTful applications.
  # Note: This route will make all actions in every controller accessible via GET requests.
  # match ':controller(/:action(/:id))(.:format)'
#end

1 个答案:

答案 0 :(得分:1)

On line 9 of the routes.rb file you posted,您有以下代码:

  root :to => 'displays#show', :page => 1, :tab => Tab.first.id

据我所知,Tab模型没有记录,从而产生零错误,Rails无法找到你想要id的第一条记录。