rails generate rspec: установить config/environment /development.rb:1: в `<top (обязательно)>': неопределенный метод`configure'
Во -первых, вот мои версии:
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 'rspec-rails' в мой 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>'
Вот мой гемфайл:
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
а вот конфиг / environment / 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 ответа
В config/environment /development.rb:
менять
Rails.application.configure do
в
SampleApp::Application.configure do
Я проверил пару своих приложений, и вот формат, который у меня есть.
Смена development.rb мне совсем не помогла.
Однако, что мне помогло, так это:
рвм 2.0.0
ДО создания приложения с
$ rails new first_app
Обратите внимание, что версия Gemfile была 2.0.0, а не 2.1.1, что было у меня изначально, поэтому сопоставьте версии ruby, прежде чем создавать свое приложение.
Не уверен, почему это важно.
Попробуйте использовать другую версию rspec, заменив бета-версию этой версией в своем Gemfile: gem 'rspec-rails', '>= 2.14'
РЕДАКТИРОВАТЬ: вы бежали bundle install
а также rails generate rspec:install
прежде чем пытаться запустить rspec?