1

这就是我的 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

这是我运行时收到的错误消息: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'

我在另一篇文章中阅读以避免安全警告,但是,我不确定如何处理下面的其余错误。非常感谢您的帮助。

4

4 回答 4

2

堆栈跟踪的第一行:

/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)

这让我觉得你的路线中有一些无效的东西。有什么作用吗?

于 2013-08-20T18:27:01.780 回答
1

中的root指令routes.rb可以接收:

  1. 一个字符串(路径) -root 'pages#main'
  2. 哈希(选项) - root to: 'pages#main'(完全像root {:to => 'pages#main'}
  3. 一个字符串和一个哈希(路径和选项) -root 'pages#main', some_other: option

任何其他语法都会引发异常,例如 OP 所见。

此类错误的示例:

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

root 'pages#main', []

root 'pages#main', %w{ my_option: 'my_test' } # <= this is an array, not a hash...
于 2014-02-14T19:59:29.703 回答
0

我设法为自己解决了这个问题。不知道到底出了什么问题,但是在升级到 Rails 4.0 和 Ruby 2.0 之后,我从头开始我的应用程序(不确定这对你来说是否可行,或者你是否也在学习教程),我不再得到错误。

我知道这不是详细的回复或解释,但如果您只是想让事情正常运行,我希望这会有所帮助!

于 2014-02-08T18:56:14.363 回答
0

我相信您在 config/routes.rb 文件中错误地设置了您的路线。您还使用任何宝石,例如应该吗?

这是一个关于如何在 Rails 中设置根路径的链接:http: //guides.rubyonrails.org/routing.html#using-root

于 2014-02-14T02:29:54.807 回答