【问题标题】:Can't find static_pages_spec.rb in spec/requests directory在 spec/requests 目录中找不到 static_pages_spec.rb
【发布时间】:2013-11-27 00:09:51
【问题描述】:

我正在阅读 Hartl 的 Rails 教程,但遇到了一个我无法弄清楚的路障。我正处于生成集成测试(Rspec)的第一步。我输入了:

 rails generate integration_test static_pages

然后得到

Waymond-MacBook-Pro:sample_app wayway$ rails generate integration_test static_pages
/Library/Ruby/Gems/2.0.0/gems/actionpack-4.0.1/lib/action_dispatch/routing/mapper.rb:229:in `default_controller_and_action': missing :controller (ArgumentError)
from /Library/Ruby/Gems/2.0.0/gems/actionpack-4.0.1/lib/action_dispatch/routing/mapper.rb:116:in `normalize_options!'
from /Library/Ruby/Gems/2.0.0/gems/actionpack-4.0.1/lib/action_dispatch/routing/mapper.rb:64:in `initialize'
from /Library/Ruby/Gems/2.0.0/gems/actionpack-4.0.1/lib/action_dispatch/routing/mapper.rb:1443:in `new'
from /Library/Ruby/Gems/2.0.0/gems/actionpack-4.0.1/lib/action_dispatch/routing/mapper.rb:1443:in `add_route'
from /Library/Ruby/Gems/2.0.0/gems/actionpack-4.0.1/lib/action_dispatch/routing/mapper.rb:1422:in `decomposed_match'
from /Library/Ruby/Gems/2.0.0/gems/actionpack-4.0.1/lib/action_dispatch/routing/mapper.rb:1403:in `block in match'
from /Library/Ruby/Gems/2.0.0/gems/actionpack-4.0.1/lib/action_dispatch/routing/mapper.rb:1394:in `each'
from /Library/Ruby/Gems/2.0.0/gems/actionpack-4.0.1/lib/action_dispatch/routing/mapper.rb:1394:in `match'
from /Library/Ruby/Gems/2.0.0/gems/actionpack-4.0.1/lib/action_dispatch/routing/mapper.rb:601:in `map_method'
from /Library/Ruby/Gems/2.0.0/gems/actionpack-4.0.1/lib/action_dispatch/routing/mapper.rb:562:in `get'
from /Users/waystylez1/rails_projects/sample_app/config/routes.rb:2:in `block in <top (required)>'
from /Library/Ruby/Gems/2.0.0/gems/actionpack-4.0.1/lib/action_dispatch/routing/route_set.rb:341:in `instance_exec'
from /Library/Ruby/Gems/2.0.0/gems/actionpack-4.0.1/lib/action_dispatch/routing/route_set.rb:341:in `eval_block'
from /Library/Ruby/Gems/2.0.0/gems/actionpack-4.0.1/lib/action_dispatch/routing/route_set.rb:319:in `draw'
from /Users/waystylez1/rails_projects/sample_app/config/routes.rb:1:in `<top (required)>'
from /Library/Ruby/Gems/2.0.0/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:223:in `load'
from /Library/Ruby/Gems/2.0.0/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:223:in `block in load'
from /Library/Ruby/Gems/2.0.0/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:214:in `load_dependency'
from /Library/Ruby/Gems/2.0.0/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:223:in `load'
from /Library/Ruby/Gems/2.0.0/gems/railties-4.0.1/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
from /Library/Ruby/Gems/2.0.0/gems/railties-4.0.1/lib/rails/application/routes_reloader.rb:40:in `each'
from /Library/Ruby/Gems/2.0.0/gems/railties-4.0.1/lib/rails/application/routes_reloader.rb:40:in `load_paths'
from /Library/Ruby/Gems/2.0.0/gems/railties-4.0.1/lib/rails/application/routes_reloader.rb:16:in `reload!'
from /Library/Ruby/Gems/2.0.0/gems/railties-4.0.1/lib/rails/application/routes_reloader.rb:26:in `block in updater'
from /Library/Ruby/Gems/2.0.0/gems/activesupport-4.0.1/lib/active_support/file_update_checker.rb:75:in `call'
from /Library/Ruby/Gems/2.0.0/gems/activesupport-4.0.1/lib/active_support/file_update_checker.rb:75:in `execute'
from /Library/Ruby/Gems/2.0.0/gems/railties-4.0.1/lib/rails/application/routes_reloader.rb:27:in `updater'
from /Library/Ruby/Gems/2.0.0/gems/railties-4.0.1/lib/rails/application/routes_reloader.rb:6:in `execute_if_updated'
from /Library/Ruby/Gems/2.0.0/gems/railties-4.0.1/lib/rails/application/finisher.rb:69:in `block in <module:Finisher>'
from /Library/Ruby/Gems/2.0.0/gems/railties-4.0.1/lib/rails/initializable.rb:30:in `instance_exec'
from /Library/Ruby/Gems/2.0.0/gems/railties-4.0.1/lib/rails/initializable.rb:30:in `run'
from /Library/Ruby/Gems/2.0.0/gems/railties-4.0.1/lib/rails/initializable.rb:55:in `block in run_initializers'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/tsort.rb:150:in `block in tsort_each'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/tsort.rb:183:in `block (2 levels) in each_strongly_connected_component'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/tsort.rb:219:in `each_strongly_connected_component_from'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/tsort.rb:182:in `block in each_strongly_connected_component'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/tsort.rb:180:in `each'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/tsort.rb:180:in `each_strongly_connected_component'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/tsort.rb:148:in `tsort_each'
from /Library/Ruby/Gems/2.0.0/gems/railties-4.0.1/lib/rails/initializable.rb:54:in `run_initializers'
from /Library/Ruby/Gems/2.0.0/gems/railties-4.0.1/lib/rails/application.rb:215:in `initialize!'
from /Library/Ruby/Gems/2.0.0/gems/railties-4.0.1/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /Users/waystylez1/rails_projects/sample_app/config/environment.rb:5:in `<top (required)>'
from /Library/Ruby/Gems/2.0.0/gems/railties-4.0.1/lib/rails/application.rb:189:in `require'
from /Library/Ruby/Gems/2.0.0/gems/railties-4.0.1/lib/rails/application.rb:189:in `require_environment!'
from /Library/Ruby/Gems/2.0.0/gems/railties-4.0.1/lib/rails/commands.rb:44:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'

并且应该在 spec/requests 目录中获取 static_pages_spec.rb。它不在那里,所以我猜我的路由是错误的?任何帮助表示赞赏!谢谢!

编辑。这是来自 config/routes.rb

   SampleApp::Application.routes.draw do
   get "static_pages/..."
   get "static_pages/home"
   get "static_pages/help"
   # The priority is based upon order of creation: first created -> highest priority.
   # See how all your routes lay out with "rake routes".

   # You can have the root of your site routed with "root"
   # root 'welcome#index'

   # Example of regular route:
   #   get 'products/:id' => 'catalog#view'

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

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

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

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

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

   # Example resource route with concerns:
   #   concern :toggleable do
   #     post 'toggle'
   #   end
   #   resources :posts, concerns: :toggleable
   #   resources :photos, concerns: :toggleable

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

【问题讨论】:

  • 你能粘贴你的整个路由文件吗?
  • 不确定这是否是您请求的正确路线信息。对不起,我是菜鸟。
  • 你应该发布config/routes.rb的全部内容。这就是你得到错误的地方。
  • @FarleyKnight 感谢您的回复。刚刚编辑过。

标签: ruby-on-rails ruby rspec


【解决方案1】:

您的config/routes.rb 文件有一个小错误:

 SampleApp::Application.routes.draw do
   # Get rid of this line, as it's not valid
   # get "static_pages/..."
   get "static_pages/home"
   get "static_pages/help"
 end

好像 Hartl 教程有这样一行:

  $ rails generate controller static_pages ...

http://ruby.railstutorial.org/chapters/static-pages#code-generating_pages

那些多余的点是多余的。您可以使用该空间来生成helphome 操作。例如:

  $ rails generate controller static_pages help home

【讨论】:

  • 对其进行了编辑并在运行后将其输入: rails generate integration_test static_pages 。我收到此错误:&lt;top (required)&gt;': undefined method get' for main:Object (NoMethodError)
  • 将您的错误发布到您的原始问题。我需要查看更多的堆栈跟踪。
  • 我刚刚开始工作。法利,非常感谢你。也谢谢你的解释。如果可以的话,我会投票给你,但我需要在编码方面做得更好。
  • 您可以将我的答案标记为解决方案 :) 那肯定会有所帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多