简体   繁体   中英

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

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

    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:

  1. A string (path) - root 'pages#main'
  2. A Hash (options) - root to: 'pages#main' (which is exactly like root {:to => 'pages#main'} )
  3. A string and a Hash (path and options) - root 'pages#main', some_other: option

Any other syntax will throw an exception such as the OP has seen.

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.

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. Also are you using any gems, such as shoulda?

Here is a link on how to set up root paths in rails: http://guides.rubyonrails.org/routing.html#using-root

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM