我正在关注Michael Hartl的Ruby on Rails教程,当我运行时,我在3.2.1节中遇到以下错误:
bundle exec rspec spec/requests/static_pages_spec.rb
我看到过类似的错误,但没有完全相同。任何援助将不胜感激。
错误:
/Users/michaeltro/.rvm/gems/ruby-2.0.0-p353@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:791:in `<': compared with non class/module (TypeError)
from /Users/michaeltro/.rvm/gems/ruby-2.0.0-p353@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:791:in `safe_include'
from /Users/michaeltro/.rvm/gems/ruby-2.0.0-p353@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:785:in `block in configure_group'
from /Users/michaeltro/.rvm/gems/ruby-2.0.0-p353@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:783:in `each'
from /Users/michaeltro/.rvm/gems/ruby-2.0.0-p353@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:783:in `configure_group'
from /Users/michaeltro/.rvm/gems/ruby-2.0.0-p353@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/world.rb:47:in `configure_group'
from /Users/michaeltro/.rvm/gems/ruby-2.0.0-p353@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:290:in `set_it_up'
from /Users/michaeltro/.rvm/gems/ruby-2.0.0-p353@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:241:in `subclass'
from /Users/michaeltro/.rvm/gems/ruby-2.0.0-p353@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:228:in `describe'
from /Users/michaeltro/.rvm/gems/ruby-2.0.0-p353@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/dsl.rb:18:in `describe'
from /Users/michaeltro/RubymineProjects/sample_project/spec/requests/static_pages_spec.rb:3:in `<top (required)>'
from /Users/michaeltro/.rvm/gems/ruby-2.0.0-p353@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load'
from /Users/michaeltro/.rvm/gems/ruby-2.0.0-p353@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `block in load_spec_files'
from /Users/michaeltro/.rvm/gems/ruby-2.0.0-p353@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `each'
from /Users/michaeltro/.rvm/gems/ruby-2.0.0-p353@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load_spec_files'
from /Users/michaeltro/.rvm/gems/ruby-2.0.0-p353@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:22:in `run'
from /Users/michaeltro/.rvm/gems/ruby-2.0.0-p353@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:80:in `run'
from /Users/michaeltro/.rvm/gems/ruby-2.0.0-p353@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:17:in `block in autorun'enter code here
的Gemfile:
source 'https://rubygems.org'
ruby '2.0.0'
#ruby-gemset=railstutorial_rails_4_0
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.2'
# Use sqlite3 as the database for Active Record
group :development, :test do
gem 'sqlite3', '1.3.8'
gem 'rspec-rails', '2.13.1'
end
group :test do
gem 'selenium-webdriver', '2.35.1'
gem 'capybara', '2.1.0'
end
# Use SCSS for stylesheets
gem 'sass-rails', '4.0.1'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '2.1.1'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '4.0.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails', '3.0.4'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks', '1.1.1'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '1.0.2'
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '0.3.20', require: false
end
group :production do
gem 'pg', '0.15.1'
gem 'rails_12factor', '0.0.2'
end
# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.1.2'
# Use unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]
routes.rb中:
SampleProject::Application.routes.draw do
get "static_pages/home"
get "static_pages/help"
end
static_pages_spec.rb
require 'spec_helper'
describe "Static Pages" do
describe "Home page" do
it "should have the content 'Sample Project'" do
visit '/static_pages/home'
expect(page).to have_content('Sample Project')
end
end
end
spec_helper.rb
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
# Checks for pending migrations before tests are run.
# If you are not using ActiveRecord, you can remove this line.
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
RSpec.configure do |config|
# ## Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false
# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = "random"
config.include Capybara: :DSL
end
答案 0 :(得分:0)
尝试将 static_pages_spec.rb 文件设置为:
require 'spec_helper'
describe "Static pages" do
describe "Home page" do
it "should have the content 'Sample App'" do
visit '/static_pages/home'
expect(page).to have_content('Sample App')
end
it "should have the base title" do
visit '/static_pages/home'
expect(page).to have_title("Ruby on Rails Tutorial Sample App")
end
it "should not have a custom page title" do
visit '/static_pages/home'
expect(page).not_to have_title('| Home')
end
end
end