Reputation: 385
I am developing a simple rails app which uses MongoDb as database (with Mongoid). I have been doing my first model in the app, so I want to make tests for it using rspec. After searching, I found rspec-rails and mongoid-rspec gems and I followed their intalling instructions. However, when I execute: rails g rspec:install, I obtain the following error:
home/jesus/.rvm/gems/ruby-2.0.0-p353/gems/mongoid-3.1.6/lib/mongoid/config/validators/session.rb:99:in `no_database_or_uri?': undefined method `has_key?' for nil:NilClass (NoMethodError)
from /home/jesus/.rvm/gems/ruby-2.0.0-p353/gems/mongoid-3.1.6/lib/mongoid/config/validators/session.rb:45:in `validate_session_database'
from /home/jesus/.rvm/gems/ruby-2.0.0-p353/gems/mongoid-3.1.6/lib/mongoid/config/validators/session.rb:25:in `block in validate'
from /home/jesus/.rvm/gems/ruby-2.0.0-p353/gems/mongoid-3.1.6/lib/mongoid/config/validators/session.rb:24:in `each_pair'
from /home/jesus/.rvm/gems/ruby-2.0.0-p353/gems/mongoid-3.1.6/lib/mongoid/config/validators/session.rb:24:in `validate'
from /home/jesus/.rvm/gems/ruby-2.0.0-p353/gems/mongoid-3.1.6/lib/mongoid/config.rb:239:in `sessions='
from /home/jesus/.rvm/gems/ruby-2.0.0-p353/gems/mongoid-3.1.6/lib/mongoid/config.rb:136:in `load_configuration'
from /home/jesus/.rvm/gems/ruby-2.0.0-p353/gems/mongoid-3.1.6/lib/mongoid/config.rb:93:in `load!'
from /home/jesus/.rvm/gems/ruby-2.0.0-p353/gems/mongoid-3.1.6/lib/mongoid.rb:163:in `load!'
from /home/jesus/.rvm/gems/ruby-2.0.0-p353/gems/mongoid-3.1.6/lib/mongoid/railtie.rb:67:in `block in <class:Railtie>'
from /home/jesus/.rvm/gems/ruby-2.0.0-p353/gems/railties-3.2.15/lib/rails/initializable.rb:30:in `instance_exec'
from /home/jesus/.rvm/gems/ruby-2.0.0-p353/gems/railties-3.2.15/lib/rails/initializable.rb:30:in `run'
from /home/jesus/.rvm/gems/ruby-2.0.0-p353/gems/railties-3.2.15/lib/rails/initializable.rb:55:in `block in run_initializers'
from /home/jesus/.rvm/gems/ruby-2.0.0-p353/gems/railties-3.2.15/lib/rails/initializable.rb:54:in `each'
from /home/jesus/.rvm/gems/ruby-2.0.0-p353/gems/railties-3.2.15/lib/rails/initializable.rb:54:in `run_initializers'
from /home/jesus/.rvm/gems/ruby-2.0.0-p353/gems/railties-3.2.15/lib/rails/application.rb:136:in `initialize!'
from /home/jesus/.rvm/gems/ruby-2.0.0-p353/gems/railties-3.2.15/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /home/jesus/rails_projects/myapp/config/environment.rb:5:in `<top (required)>'
from /home/jesus/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-3.2.15/lib/active_support/dependencies.rb:251:in `require'
from /home/jesus/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-3.2.15/lib/active_support/dependencies.rb:251:in `block in require'
from /home/jesus/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-3.2.15/lib/active_support/dependencies.rb:236:in `load_dependency'
from /home/jesus/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-3.2.15/lib/active_support/dependencies.rb:251:in `require'
from /home/jesus/.rvm/gems/ruby-2.0.0-p353/gems/railties-3.2.15/lib/rails/application.rb:103:in `require_environment!'
from /home/jesus/.rvm/gems/ruby-2.0.0-p353/gems/railties-3.2.15/lib/rails/commands.rb:25:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
I have been surfing on the Internet but I can't find anything. This are the main configuration files that I have been using:
config/mongoid.yml
development:
sessions:
default:
database: myapp_development
hosts:
- localhost:27017
options:
options:
test:
sessions:
default:
database: myapp_test
hosts:
- localhost:27017
options:
consistency: :strong
max_retries: 1
retry_interval: 0
config/initializers/mongo.rb
MongoMapper.connection = Mongo::Connection.new( 'localhost', 27017 )
MongoMapper.database = "myapp_#{Rails.env}"
if defined?(PhusionPassenger)
PhusionPassenger.on_event(:starting_worker_process) do |forked|
MongoMapper.connection.connect if forked
end
end
Gemfile
source 'https://rubygems.org'
gem 'rails', '3.2.15'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'jquery-rails', '3.0.4'
gem 'jquery-ui-rails', '~>4.1.0'
gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'therubyracer'
gem 'uglifier', '>= 1.0.3'
end
gem 'mongo', '1.9.2'
gem 'bson_ext', '1.9.2'
gem 'fancybox-rails', "~> 0.2.1"
gem 'mongo_mapper'
gem 'mongoid', '~> 3.1.6'
gem 'haml', "~> 4.0.4"
gem 'i18n', '~> 0.6.9'
gem 'i18n-js', '2.1.2'
gem 'mongo-i18n', '~> 0.0.3'
gem 'underscore-rails', '~> 1.5.2'
gem 'devise', '~> 3.2.2'
gem 'less-rails', '~> 2.4.2'
gem 'twitter-bootstrap-rails', '~> 2.2.8'
gem 'mongoid-paperclip', '~> 0.0.8'
group :test, :development do
gem "rspec-rails", "~> 2.14.1"
gem "mongoid-rspec", "~> 1.11.0"
end
group :test do
gem 'database_cleaner'
end
When I try to initialize the server (rails s) or use the console (rails c) I obtain the same error. I have spent lots of hours trying to find the reason but I can't find anything.
Thanks in advance.
PD: Let me know if you need more configuration files, the model, spec_helper...
Upvotes: 0
Views: 298
Reputation: 33666
It seems you don't have MongoDB running in port 27017.
Do this to start it:
$ mongod
Upvotes: 1