тестирование с помощью rspec дает ошибку: «Пожалуйста, установите адаптер sqlite3» - railstutorial.org

Привет, у меня такая же проблема, как у этого парня: ">Вопросы Ruby Guard - "Пожалуйста, установите адаптер sqlite3" - railstutorial.org

Выполнение "bundle exec rspec spec/requests/static_pages_spec.rb" дает мне это:

C:\Users\Me\Ruby\sample_app>bundle exec rspec spec/requests/static_pages_spec
.rb
Rack::File headers parameter replaces cache_control after Rack 1.5.
C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.2.3/lib/bundler/rubygems_integrati
on.rb:147:in `block in replace_gem': Please install the sqlite3 adapter: `gem in
stall activerecord-sqlite3-adapter` (sqlite3 is not part of the bundle. Add it t
o Gemfile.) (LoadError)
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.11/lib/active_
record/connection_adapters/sqlite3_adapter.rb:3:in `<top (required)>'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active
_support/dependencies.rb:251:in `require'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active
_support/dependencies.rb:251:in `block in require'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active
_support/dependencies.rb:236:in `load_dependency'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active
_support/dependencies.rb:251:in `require'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.11/lib/active_
record/connection_adapters/abstract/connection_specification.rb:50:in `resolve_h
ash_connection'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.11/lib/active_
record/connection_adapters/abstract/connection_specification.rb:41:in `resolve_s
tring_connection'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.11/lib/active_
record/connection_adapters/abstract/connection_specification.rb:25:in `spec'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.11/lib/active_
record/connection_adapters/abstract/connection_specification.rb:130:in `establis
h_connection'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.11/lib/active_
record/railtie.rb:82:in `block (2 levels) in <class:Railtie>'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active
_support/lazy_load_hooks.rb:36:in `instance_eval'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active
_support/lazy_load_hooks.rb:36:in `execute_hook'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active
_support/lazy_load_hooks.rb:43:in `block in run_load_hooks'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active
_support/lazy_load_hooks.rb:42:in `each'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active
_support/lazy_load_hooks.rb:42:in `run_load_hooks'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.11/lib/active_
record/base.rb:720:in `<top (required)>'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-rails-2.11.0/lib/rspec/ra
ils/extensions/active_record/base.rb:19:in `<module:Extensions>'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-rails-2.11.0/lib/rspec/ra
ils/extensions/active_record/base.rb:4:in `<module:Rails>'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-rails-2.11.0/lib/rspec/ra
ils/extensions/active_record/base.rb:2:in `<module:RSpec>'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-rails-2.11.0/lib/rspec/ra
ils/extensions/active_record/base.rb:1:in `<top (required)>'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active
_support/dependencies.rb:251:in `require'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active
_support/dependencies.rb:251:in `block in require'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active
_support/dependencies.rb:236:in `load_dependency'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active
_support/dependencies.rb:251:in `require'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-rails-2.11.0/lib/rspec/ra
ils/extensions.rb:1:in `<top (required)>'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active
_support/dependencies.rb:251:in `require'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active
_support/dependencies.rb:251:in `block in require'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active
_support/dependencies.rb:236:in `load_dependency'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active
_support/dependencies.rb:251:in `require'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-rails-2.11.0/lib/rspec/ra
ils.rb:8:in `<top (required)>'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active
_support/dependencies.rb:251:in `require'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active
_support/dependencies.rb:251:in `block in require'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active
_support/dependencies.rb:236:in `load_dependency'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active
_support/dependencies.rb:251:in `require'
        from C:/Users/Ayhan/Ruby/sample_app/spec/spec_helper.rb:4:in `<top (requ
ired)>'
        from C:/Users/Ayhan/Ruby/sample_app/spec/requests/static_pages_spec.rb:1
:in `require'
        from C:/Users/Ayhan/Ruby/sample_app/spec/requests/static_pages_spec.rb:1
:in `<top (required)>'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/cor
e/configuration.rb:780:in `load'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/cor
e/configuration.rb:780:in `block in load_spec_files'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/cor
e/configuration.rb:780:in `map'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/cor
e/configuration.rb:780:in `load_spec_files'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/cor
e/command_line.rb:22:in `run'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/cor
e/runner.rb:69:in `run'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/cor
e/runner.rb:8:in `block in autorun'

Но моя база данных.yml выглядит так:

# SQLite version 3.x
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
development:
  adapter: postgresql
  host: localhost
  username: user
  database: app-dev

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  adapter: sqlite3
  database: db/test.sqlite3
  pool: 5
  timeout: 5000

production:
  adapter: sqlite3
  database: db/production.sqlite3
  pool: 5
  timeout: 5000

Что я должен изменить здесь? Или есть другая проблема, которую я не вижу?

P.S: Я установил postgreSQL, поэтому я изменил этап разработки в файле database.yml. И gemfile выглядит так:

source 'https://rubygems.org'

gem 'rails', '3.2.11'
gem 'pg', '0.12.2'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

group :development, :test do
  gem 'rspec-rails', '2.11.0'
end

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.5'
  gem 'coffee-rails', '~> 3.2.2'
  gem 'uglifier', '>= 1.2.3'
end

gem 'jquery-rails'

group :test do
  gem 'capybara', '1.1.2'
end

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# To use Jbuilder templates for JSON
# gem 'jbuilder'

# Use unicorn as the app server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'debugger'

person Acimaz    schedule 10.02.2013    source источник


Ответы (1)


С текущей конфигурацией config/database.yml среда разработки находится на postgres, а test и production используют sqlite3. И в Gemfile нет драгоценного камня sqlite3. Отсюда и сообщение об ошибке Please install the sqlite3 adapter.

Почему бы не использовать postgres для всех ваших сред, а не только для development?

Сделайте разделы для test и production похожими на разделы development в config/database.yml с соответствующими именами баз данных - database: app-test & database: app-prod` соответственно.

В качестве альтернативы, если вы хотите использовать sqlite3 для определенных сред, включите гем sqlite3 только для этой среды и гем pg для других сред.

Пример конфигурации Gemfile:

Приведенная ниже конфигурация будет включать гем pg только для среды production, а гем sqlite3 только для среды development и test.

group :production do
  gem 'pg', '0.11.0'
end

group :development, :test do
  gem 'sqlite3-ruby', :require => 'sqlite3'
end
person Prakash Murthy    schedule 10.02.2013
comment
Хорошо, я изменил его, но теперь он вообще не выполняется, просто говорю следующее: Параметр заголовков Rack::File заменяет cache_control после Rack 1.5. Я изменил файл database.yml следующим образом: test: adapter: postgresql database: db/test pool: 5 timeout: 5000 username: user - person Acimaz; 10.02.2013
comment
Измените test и production соответствующим образом и запустите bundle install перед выполнением команды bundle exec rspec spec/requests/static_pages_spec.rb. - person Prakash Murthy; 10.02.2013
comment
Поскольку вы меняете конфигурацию базы данных для сред, вам также придется создавать базы данных с помощью rake db:create. - person Prakash Murthy; 10.02.2013
comment
Что вы имеете в виду под правильным их изменением? Команда не запускается, я не знаю почему, потому что сейчас нет сообщений об ошибках. Я подумал, что будет проще использовать postgreSQL для всех сред. Изменение имени адаптера и пути к базе данных на db/development и т. д. не сработало :/ - person Acimaz; 10.02.2013
comment
Ладно, команда rake db:create тоже не выполняется... пришлось прервать с помощью strg+c - person Acimaz; 10.02.2013
comment
Выполнение rake db:create --trace показывает, что он зависает на ** Execute db:create .... rake db:migrate также ничего не делает - person Acimaz; 10.02.2013
comment
Создание базы данных postgres немного сложно для новичка - как Майкл Хартл тоже упоминает в книге; Я бы посоветовал пока поработать с sqlite, а позже вернуться к Postgres. railscasts.com/episodes/ будет полезен в это время. . - person Prakash Murthy; 11.02.2013
comment
Да, я понял это и вернул весь материал sqlite3. Теперь он снова работает. - person Acimaz; 11.02.2013