简体   繁体   English

运行“Rails S”和“$ bundle exec rspec spec / requests / static_pages_spec.rb”时出现错误消息

[英]Error message when running “Rails S” & “$ bundle exec rspec spec/requests/static_pages_spec.rb”

This is what I have in my spec/requests/static_pages_spec.rb file 这是我的spec / requests / static_pages_spec.rb文件中的内容

require 'spec_helper'

describe "Static pages" do

  subject { page }

  describe "Home page" do
    before { visit root_path }

    it { should have_content('Sample App') }
    it { should have_title(full_title('')) }
    it { should_not have_title('| Home') }
  end

  describe "Help page" do
    before { visit help_path }

    it { should have_content('Help') }
    it { should have_title(full_title('Help')) }
  end

  describe "About page" do
    before { visit about_path }

    it { should have_content('About') }
    it { should have_title(full_title('About Us')) }
  end

  describe "Contact page" do
    before { visit contact_path }

    it { should have_content('Contact') }
    it { should have_title(full_title('Contact')) }
  end
end

This is the error message I get when I run: bundle exec rspec spec/requests/static_pages_spec.rb 这是我运行时收到的错误消息: bundle exec rspec spec/requests/static_pages_spec.rb

    SECURITY WARNING: No secret option provided to Rack::Session::Cookie.
        This poses a security threat. It is strongly recommended that you
        provide a secret to prevent exploits that may be possible from crafted
        cookies. This will not be supported in future versions of Rack, and
        future versions will even invalidate your existing user cookies.

        Called from: /usr/local/rvm/gems/ruby-2.0.0-p247/gems/actionpack-3.2.1/lib/action_dispatch/middleware/session/abstract_store.rb:28:in `initialize'.
Rack::File headers parameter replaces cache_control after Rack 1.5.
/usr/local/rvm/gems/ruby-2.0.0-p247/gems/actionpack-3.2.1/lib/action_dispatch/routing/mapper.rb:258:in `merge': no implicit conversion of String into Hash (TypeError)
  from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/actionpack-3.2.1/lib/action_dispatch/routing/mapper.rb:258:in `root'
  from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/actionpack-3.2.1/lib/action_dispatch/routing/mapper.rb:1315:in `root'
  from /Users/StevenW/Documents/Code/rails_projects/sample_app/config/routes.rb:2:in `block in <top (required)>'
  from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/actionpack-3.2.1/lib/action_dispatch/routing/route_set.rb:272:in `instance_exec'
  from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/actionpack-3.2.1/lib/action_dispatch/routing/route_set.rb:272:in `eval_block'
  from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/actionpack-3.2.1/lib/action_dispatch/routing/route_set.rb:249:in `draw'
  from /Users/StevenW/Documents/Code/rails_projects/sample_app/config/routes.rb:1:in `<top (required)>'
  from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:245:in `load'
  from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:245:in `block in load'
  from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:236:in `load_dependency'
  from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:245:in `load'
  from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/railties-3.2.1/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
  from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/railties-3.2.1/lib/rails/application/routes_reloader.rb:40:in `each'
  from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/railties-3.2.1/lib/rails/application/routes_reloader.rb:40:in `load_paths'
  from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/railties-3.2.1/lib/rails/application/routes_reloader.rb:16:in `reload!'
  from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/railties-3.2.1/lib/rails/application/routes_reloader.rb:26:in `block in updater'
  from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/activesupport-3.2.1/lib/active_support/file_update_checker.rb:78:in `call'
  from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/activesupport-3.2.1/lib/active_support/file_update_checker.rb:78:in `execute'
  from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/railties-3.2.1/lib/rails/application/routes_reloader.rb:27:in `updater'
  from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/railties-3.2.1/lib/rails/application/routes_reloader.rb:7:in `execute_if_updated'
  from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/railties-3.2.1/lib/rails/application/finisher.rb:66:in `block in <module:Finisher>'
  from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/railties-3.2.1/lib/rails/initializable.rb:30:in `instance_exec'
  from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/railties-3.2.1/lib/rails/initializable.rb:30:in `run'
  from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/railties-3.2.1/lib/rails/initializable.rb:55:in `block in run_initializers'
  from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/railties-3.2.1/lib/rails/initializable.rb:54:in `each'
  from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/railties-3.2.1/lib/rails/initializable.rb:54:in `run_initializers'
  from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/railties-3.2.1/lib/rails/application.rb:136:in `initialize!'
  from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/railties-3.2.1/lib/rails/railtie/configurable.rb:30:in `method_missing'
  from /Users/StevenW/Documents/Code/rails_projects/sample_app/config/environment.rb:5:in `<top (required)>'
  from /Users/StevenW/Documents/Code/rails_projects/sample_app/spec/spec_helper.rb:3:in `require'
  from /Users/StevenW/Documents/Code/rails_projects/sample_app/spec/spec_helper.rb:3:in `<top (required)>'
  from /Users/StevenW/Documents/Code/rails_projects/sample_app/spec/requests/static_pages_spec.rb:1:in `require'
  from /Users/StevenW/Documents/Code/rails_projects/sample_app/spec/requests/static_pages_spec.rb:1:in `<top (required)>'
  from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.5/lib/rspec/core/configuration.rb:896:in `load'
  from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.5/lib/rspec/core/configuration.rb:896:in `block in load_spec_files'
  from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.5/lib/rspec/core/configuration.rb:896:in `each'
  from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.5/lib/rspec/core/configuration.rb:896:in `load_spec_files'
  from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.5/lib/rspec/core/command_line.rb:22:in `run'
  from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.5/lib/rspec/core/runner.rb:80:in `run'
  from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.5/lib/rspec/core/runner.rb:17:in `block in autorun'

I read in another post to avoid the Security Warning , however, I'm not sure what to do about the rest of the errors underneath. 我在另一篇文章中读到了避免安全警告 ,但是,我不知道如何处理下面的其他错误。 Your help is greatly appreciated. 非常感谢您的帮助。

The top line of the stack trace: 堆栈跟踪的顶行:

/usr/local/rvm/gems/ruby-2.0.0-p247/gems/actionpack-3.2.1
   /lib/action_dispatch/routing/mapper.rb:258:in `merge': 
   no implicit conversion of String into Hash (TypeError)

This makes me think you have something invalid in your routes. 这让我觉得你的路线中有一些无效的东西。 Does anything work? 什么用吗?

The root directive in routes.rb can receive either: routes.rbroot指令可以接收:

  1. A string (path) - root 'pages#main' 字符串(路径) - root 'pages#main'
  2. A Hash (options) - root to: 'pages#main' (which is exactly like root {:to => 'pages#main'} ) 哈希(选项) - root to: 'pages#main' (完全像root {:to => 'pages#main'}
  3. A string and a Hash (path and options) - root 'pages#main', some_other: option 字符串和哈希(路径和选项) - root 'pages#main', some_other: option

Any other syntax will throw an exception such as the OP has seen. 任何其他语法都会抛出异常,例如OP已经看到过。

Examples of such errors: 此类错误的示例:

root 'pages#main', 'pages#index'

root 'pages#main', []

root 'pages#main', %w{ my_option: 'my_test' } # <= this is an array, not a hash...

I managed to solve the problem for myself. 我设法为自己解决了这个问题。 Not sure what exactly was wrong, but after upgrading to Rails 4.0 and Ruby 2.0 I started my app from scratch (not sure if this is a viable option for you or if you are working through a tutorial as well) and I'm no longer getting the error. 不确定到底出了什么问题,但在升级到Rails 4.0和Ruby 2.0后,我从头开始创建我的应用程序(不确定这是否适合您,或者您是否正在通过教程)我不再得到错误。

I know this isn't a detailed response or an explanation but if you just want to get things up and running I hope this helps! 我知道这不是一个详细的回复或解释,但如果你只是想让事情得到解决,我希望这会有所帮助!

I believe you are setting your routes incorrectly in your config/routes.rb file. 我相信你在config / routes.rb文件中错误地设置了你的路由。 Also are you using any gems, such as shoulda? 你也在使用任何宝石,比如shoulda?

Here is a link on how to set up root paths in rails: http://guides.rubyonrails.org/routing.html#using-root 以下是有关如何在rails中设置根路径的链接: http//guides.rubyonrails.org/routing.html#using-root

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Rails中运行bundle exec rspec spec / requests / static_pages_spec.rb时出错 - Getting error while running bundle exec rspec spec/requests/static_pages_spec.rb in Rails 输入命令捆绑包exec rspec spec / requests / static_pages_spec.rb时出错 - Error when I type in the command bundle exec rspec spec/requests/static_pages_spec.rb 捆绑exec rspec spec / requests / static_pages_spec.rb错误 - bundle exec rspec spec/requests/static_pages_spec.rb Error 捆绑exec rspec spec / requests / static_pages_spec.rb和错误 - bundle exec rspec spec/requests/static_pages_spec.rb and error 在运行“ bundle exec rspec / requests / static_pages_spec.rb”后,没有任何drb服务器正在运行 - no drb server is running, after ran "bundle exec rspec/requests/static_pages_spec.rb bundle exec rspec spec / requests / static_pages_spec.rb — RubyonRails教程 - bundle exec rspec spec/requests/static_pages_spec.rb — RubyonRails Tutorial 时间束执行程序rspec spec / requests / static_pages_spec.rb-系统无法接受输入的时间 - time bundle exec rspec spec/requests/static_pages_spec.rb --— the system cannot accept the time entered 无法执行bundle exec rspec spec / requests / static_pages_spec.rb - Can't execute bundle exec rspec spec/requests/static_pages_spec.rb 来自Hartl教程的bundle exec rspec spec / requests / static_pages_spec.rb无效 - bundle exec rspec spec/requests/static_pages_spec.rb from Hartl's tutorial isn't working 捆绑exec rspec spec / static_pages_spec.rb无法加载错误 - Bundle exec rspec spec/static_pages_spec.rb cannot load error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM