rails生成rspec:install config / environments / development.rb:1:在`<top(required)=“”>&#39 ;: undefined method`configure&#39; </top>

时间:2014-04-24 02:50:07

标签: ruby-on-rails ruby rspec

首先,这是我的版本:

Greg-Nowickis-MacBook-Pro:sample_app Greg_Nowicki$ ruby -v
ruby 2.0.0p451 (2014-02-24 revision 45167) [x86_64-darwin13.1.0]
Greg-Nowickis-MacBook-Pro:sample_app Greg_Nowicki$ rails -v
Rails 4.0.4

我正在关注Hartl Rails教程并安装rspec进行测试。我已经添加了gem&#rs; rspec&#39;到我的gemfile,当我运行rails生成rspec:install时,这就是我得到的:

Greg-Nowickis-MacBook-Pro:sample_app Greg_Nowicki$ rails generate rspec:install
    /Users/Greg_Nowicki/workspace/railstutorial/sample_app/config/environments/development.rb:1:in `<top (required)>': undefined method `configure' for #<SampleApp::Application:0x007fcd3a47c138> (NoMethodError)
from /Users/Greg_Nowicki/.rvm/gems/ruby-2.0.0-p451@railstutorial_rails_4_0/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:229:in `require'
from /Users/Greg_Nowicki/.rvm/gems/ruby-2.0.0-p451@railstutorial_rails_4_0/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:229:in `block in require'
from /Users/Greg_Nowicki/.rvm/gems/ruby-2.0.0-p451@railstutorial_rails_4_0/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:214:in `load_dependency'
from /Users/Greg_Nowicki/.rvm/gems/ruby-2.0.0-p451@railstutorial_rails_4_0/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:229:in `require'
from /Users/Greg_Nowicki/.rvm/gems/ruby-2.0.0-p451@railstutorial_rails_4_0/gems/railties-4.0.4/lib/rails/engine.rb:591:in `block (2 levels) in <class:Engine>'
from /Users/Greg_Nowicki/.rvm/gems/ruby-2.0.0-p451@railstutorial_rails_4_0/gems/railties-4.0.4/lib/rails/engine.rb:590:in `each'
from /Users/Greg_Nowicki/.rvm/gems/ruby-2.0.0-p451@railstutorial_rails_4_0/gems/railties-4.0.4/lib/rails/engine.rb:590:in `block in <class:Engine>'
from /Users/Greg_Nowicki/.rvm/gems/ruby-2.0.0-p451@railstutorial_rails_4_0/gems/railties-4.0.4/lib/rails/initializable.rb:30:in `instance_exec'
from /Users/Greg_Nowicki/.rvm/gems/ruby-2.0.0-p451@railstutorial_rails_4_0/gems/railties-4.0.4/lib/rails/initializable.rb:30:in `run'
from /Users/Greg_Nowicki/.rvm/gems/ruby-2.0.0-p451@railstutorial_rails_4_0/gems/railties-4.0.4/lib/rails/initializable.rb:55:in `block in run_initializers'
from /Users/Greg_Nowicki/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/tsort.rb:150:in `block in tsort_each'
from /Users/Greg_Nowicki/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/tsort.rb:183:in `block (2 levels) in each_strongly_connected_component'
from /Users/Greg_Nowicki/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/tsort.rb:210:in `block (2 levels) in each_strongly_connected_component_from'
from /Users/Greg_Nowicki/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/tsort.rb:219:in `each_strongly_connected_component_from'
from /Users/Greg_Nowicki/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/tsort.rb:209:in `block in each_strongly_connected_component_from'
from /Users/Greg_Nowicki/.rvm/gems/ruby-2.0.0-p451@railstutorial_rails_4_0/gems/railties-4.0.4/lib/rails/initializable.rb:44:in `each'
from /Users/Greg_Nowicki/.rvm/gems/ruby-2.0.0-p451@railstutorial_rails_4_0/gems/railties-4.0.4/lib/rails/initializable.rb:44:in `tsort_each_child'
from /Users/Greg_Nowicki/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/tsort.rb:203:in `each_strongly_connected_component_from'
from /Users/Greg_Nowicki/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/tsort.rb:182:in `block in each_strongly_connected_component'
from /Users/Greg_Nowicki/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/tsort.rb:180:in `each'
from /Users/Greg_Nowicki/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/tsort.rb:180:in `each_strongly_connected_component'
from /Users/Greg_Nowicki/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/tsort.rb:148:in `tsort_each'
from /Users/Greg_Nowicki/.rvm/gems/ruby-2.0.0-p451@railstutorial_rails_4_0/gems/railties-4.0.4/lib/rails/initializable.rb:54:in `run_initializers'
from /Users/Greg_Nowicki/.rvm/gems/ruby-2.0.0-p451@railstutorial_rails_4_0/gems/railties-4.0.4/lib/rails/application.rb:215:in `initialize!'
from /Users/Greg_Nowicki/workspace/railstutorial/sample_app/config/environment.rb:5:in `<top (required)>'
from /Users/Greg_Nowicki/.rvm/gems/ruby-2.0.0-p451@railstutorial_rails_4_0/gems/railties-4.0.4/lib/rails/application.rb:189:in `require'
from /Users/Greg_Nowicki/.rvm/gems/ruby-2.0.0-p451@railstutorial_rails_4_0/gems/railties-4.0.4/lib/rails/application.rb:189:in `require_environment!'
from /Users/Greg_Nowicki/.rvm/gems/ruby-2.0.0-p451@railstutorial_rails_4_0/gems/railties-4.0.4/lib/rails/commands.rb:44:in `<top (required)>'
from bin/rails:8:in `require'
from bin/rails:8:in `<main>'

这是我的gemfile:

source 'https://rubygems.org'
ruby '2.0.0'


gem 'rails', '4.0.4'

group :development, :test do
  gem 'sqlite3', '1.3.8'
  gem 'rspec-rails', '~> 3.0.0.beta'
end

group :test do
  gem 'selenium-webdriver', '2.35.1'
  gem 'capybara', '2.1.0'
end

gem 'sass-rails', '4.0.1'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '3.0.4'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'

group :doc do
  gem 'sdoc', '0.3.20', require: false
end

group :production do
  gem 'pg', '0.15.1'
  gem 'rails_12factor', '0.0.2'
end

和这里的config / environments / development.rb

Rails.application.configure do
  # Settings specified here will take precedence over those in config/application.rb.

  # In the development environment your application's code is reloaded on
  # every request. This slows down response time but is perfect for development
  # since you don't have to restart the web server when you make code changes.
  config.cache_classes = false

  # Do not eager load code on boot.
  config.eager_load = false

  # Show full error reports and disable caching.
  config.consider_all_requests_local       = true
  config.action_controller.perform_caching = false

  # Don't care if the mailer can't send.
  config.action_mailer.raise_delivery_errors = false

  # Print deprecation notices to the Rails logger.
  config.active_support.deprecation = :log

  # Raise an error on page load if there are pending migrations.
  config.active_record.migration_error = :page_load

  # Debug mode disables concatenation and preprocessing of assets.
  # This option may cause significant delays in view rendering with a large
  # number of complex assets.
  config.assets.debug = true

  # Adds additional error checking when serving assets at runtime.
  # Checks for improperly declared sprockets dependencies.
  # Raises helpful error messages.
  config.assets.raise_runtime_errors = true

  # Raises error for missing translations
  # config.action_view.raise_on_missing_translations = true
end

对这可能是什么有任何想法?我继续将rspec-rails更新到最新版本 - 想法?

3 个答案:

答案 0 :(得分:17)

在config / environments / development.rb中:

更改

Rails.application.configure do 

SampleApp::Application.configure do

我检查了几个我的应用程序,这就是我拥有它们的格式。

答案 1 :(得分:1)

改变development.rb根本没有帮助我。

然而,对我有帮助的是:

$ rvm 2.0.0

在使用

创建应用之前

$ rails new first_app

请注意,Gemfile版本是2.0.0,而不是我原来的2.1.1,所以在创建应用程序之前匹配ruby版本。

不确定为什么这很重要。

答案 2 :(得分:0)

在Gemfile中使用此版本替换测试版,尝试使用不同版本的rspec:gem 'rspec-rails', '>= 2.14'

编辑:在尝试运行rspec之前,您是否运行了bundle installrails generate rspec:install