Rspec2, Rails3, can't run rspec spec - ruby-on-rails

I just installed Rspec2 in my Rails3 (3.0.3) project. When I run rspec spec from rails root I get:
No examples were matched. Perhaps {:if=>#<Proc:0x00000100933388#/Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:50 (lambda)>, :unless=>#<Proc:0x00000100933360#/Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:51 (lambda)>} is excluding everything?
Finished in 0.00004 seconds
0 examples, 0 failures
I can run rspec name_of_spec_test.rb directly and that seems to work, but not the generic "rspec spec" command. Also, if I add require 'spec_helper.rb' to the top of my name_of_spec_test.rb file I get:
/Users/ivan/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:644:in `initialize': Connection refused - connect(2) (Errno::ECONNREFUSED)
from /Users/ivan/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:644:in `open'
from /Users/ivan/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:644:in `block in connect'
from /Users/ivan/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/timeout.rb:44:in `timeout'
from /Users/ivan/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/timeout.rb:87:in `timeout'
from /Users/ivan/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:644:in `connect'
from /Users/ivan/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:637:in `do_start'
from /Users/ivan/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:626:in `start'
from /Users/ivan/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:1168:in `request'
from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/rsolr-1.0.0/lib/rsolr/connection.rb:15:in `execute'
from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/rsolr-1.0.0/lib/rsolr/client.rb:151:in `execute'
from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/rsolr-1.0.0/lib/rsolr/client.rb:146:in `send_and_receive'
from (eval):2:in `post'
from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/rsolr-1.0.0/lib/rsolr/client.rb:55:in `update'
from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/rsolr-1.0.0/lib/rsolr/client.rb:75:in `add'
from /Users/ivan/Documents/Projects/catalog_service.git/app/models/search/cake_to_solr.rb:39:in `<class:Playlist>'
from /Users/ivan/Documents/Projects/catalog_service.git/app/models/search/cake_to_solr.rb:11:in `<top (required)>'
from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:239:in `require'
from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:239:in `block in require'
from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:227:in `load_dependency'
from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:239:in `require'
from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:346:in `require_or_load'
from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:300:in `depend_on'
from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:216:in `require_dependency'
from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/engine.rb:138:in `block (2 levels) in eager_load!'
from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/engine.rb:137:in `each'
from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/engine.rb:137:in `block in eager_load!'
from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/engine.rb:135:in `each'
from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/engine.rb:135:in `eager_load!'
from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/application.rb:108:in `eager_load!'
from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/application/finisher.rb:41:in `block in <module:Finisher>'
from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/initializable.rb:25:in `instance_exec'
from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/initializable.rb:25:in `run'
from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/initializable.rb:50:in `block in run_initializers'
from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/initializable.rb:49:in `each'
from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/initializable.rb:49:in `run_initializers'
from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/application.rb:134:in `initialize!'
from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/application.rb:77:in `method_missing'
from /Users/ivan/Documents/Projects/catalog_service.git/config/environment.rb:5:in `<top (required)>'
from <internal:lib/rubygems/custom_require>:29:in `require'
from <internal:lib/rubygems/custom_require>:29:in `require'
from /Users/ivan/Documents/Projects/catalog_service.git/spec/spec_helper.rb:3:in `<top (required)>'
from <internal:lib/rubygems/custom_require>:29:in `require'
from <internal:lib/rubygems/custom_require>:29:in `require'
from /Users/ivan/Documents/Projects/catalog_service.git/spec/models/search_test.rb:1:in `<top (required)>'
from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `load'
from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `block in load_spec_files'
from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `map'
from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `load_spec_files'
from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/rspec/core/command_line.rb:18:in `run'
from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:55:in `run_in_process'
from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:46:in `run'
from /Users/ivan/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:10:in `block in autorun'
I am using RVM to manage my rails environment.
I don't know if this is relevant, but when I initially ran script/rails generate rspec:install it only installed .rspec, created the spec dir and spec/spec_helper.rb.
Also, I'm not using rails migrations because we have a variety of databases that we connect to. So, when I create a model, and I test it, I manually create a spec/models directory and put my *_test.rb rspec file in it.
Any ideas about what I'm missing here, would be greatly appreciated!
Here's my Gemfile, spec_helper.rb file, and test.rb files.
Gemfile:
source 'http://rubygems.org'
gem 'rails'
gem 'mysql2', '0.2.6'
gem 'legacy_data'
gem 'htmlentities'
gem 'httparty'
gem 'net-ssh'
gem 'net-sftp'
gem 'rsolr'
gem 'activerecord-import'
gem 'ar-extensions'
# Use unicorn as the web server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
# gem 'ruby-debug'
# gem 'ruby-debug19'
# Bundle the extra gems:
# gem 'bj'
# gem 'nokogiri'
# gem 'sqlite3-ruby', :require => 'sqlite3'
# gem 'aws-s3', :require => 'aws/s3'
# Gems for RSpec
# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
# and rake tasks are available in development mode:
group :development, :test do
gem 'rspec-rails'
gem 'webrat'
gem 'rspec'
end
gem 'autotest'
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'
# 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}
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
config.mock_with :rspec
# 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 = false
end
test.rb:
CatalogService::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
# your test database is "scratch space" for the test suite and is wiped
# and recreated between test runs. Don't rely on the data there!
config.cache_classes = true
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Raise exceptions instead of rendering exception templates
config.action_dispatch.show_exceptions = false
# Disable request forgery protection in test environment
config.action_controller.allow_forgery_protection = false
# Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test
# Use SQL instead of Active Record's schema dumper when creating the test database.
# This is necessary if your schema can't be completely dumped by the schema dumper,
# like if you have constraints or database-specific column types
# config.active_record.schema_format = :sql
# Print deprecation notices to the stderr
config.active_support.deprecation = :stderr
end
Thanks for any thoughts in advance!

Looks like you were correct by adding spec_helper, and maybe put rsolr in a group => [:development, :production], because it looks like the test environment is loading Solr and failing for some reason?

You might check your default pattern. Looks like you said your files were named "spec/models/XXXX_test.rb" and rspec looks for the "_spec.rb" ending by default.

Related

NoMethodError: undefined method `enqueue' | RSpec | ActiveJob | Rails 4.1

Using Rails 4.1.6, Ruby 2.3.1.
I followed this guide to use ActiveJob in Rails 4.1
# app/jobs/my_notification_job.rb
class MyNotificationJob < ActiveJob::Base
queue_as :default
def perform(args)
...
end
end
# my_model.rb
def send_notification
...
MyNotificationJob.enqueue({key1: val1, key2: val2})
...
end
# my_models_controller.rb
def publish
...
my_model_instance.send_notification
...
end
But it was throwing following load error in test env
LoadError:
cannot load such file -- active_job/arguments
# /gems/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require'
# /gems/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `block in require'
# /gems/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:232:in `load_dependency'
# /gems/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require'
# /gems/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require'
# /gems/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `block in require'
# /gems/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:232:in `load_dependency'
# /gems/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require'
# /gems/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require'
# /gems/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `block in require'
# /gems/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:232:in `load_dependency'
# /gems/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require'
# /gems/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require'
# /gems/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `block in require'
# /gems/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:232:in `load_dependency'
# /gems/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require'
# ./spec/rails_helper.rb:10:in `<top (required)>'
so I skipped loading ActiveJob in test env
# config/initializers/active_job.rb
unless Rails.env.test?
require 'active_job'
ActiveJob::Base.queue_adapter = :delayed_job
end
and based on dhruv mehta's suggestion on this post I added gem activejob_backport in test group
# Gemfile
group :test do
gem 'activejob_backport'
gem 'rspec-rails', '~> 3.9'
gem 'simplecov'
gem 'factory_bot_rails', '~> 4.11.1'
gem 'faker', '~> 2.2.1'
gem 'shoulda-matchers'
gem 'shoulda-callback-matchers'
gem 'byebug'
end
RSpec Code
# spec/rails_helper.rb
RSpec.configure do |config|
config.include ActiveJob::TestHelper
end
# spec/my_models_controller_spec.rb
require 'rails_helper'
RSpec.describe MyModelsController, type: :controller do
it 'enqueues the job' do
ActiveJob::Base.queue_adapter = :delayed_job
get :publish
end
end
But then I was getting following error
NoMethodError: undefined method `enqueue' for MyNotificationJob:Class
After looking into the documentation, I realised enqueue must be called upon an instance. But as you can see above I am calling it on MyNotificationJob class and it works fine in production.
I would be grateful if anyone could help me with this
leaving aside the issue of class method / instance method, I would be inclined to mock MyNotificationJob something like this.
before do
allow(MyNotificationJob).to receive(:enqueue).and_return(true) # or whatever value is appropriate
end

rake db:create giving me an error when trying to create db for open source project kandan

I have finally installed all the required gems for open source project kandan and ruby on rails however whenever I try and run rake db:create I get thrown this error and i'm not sure how to fix it. If anyone could assist me that would be greatly appreciated :)
kandan dan$ rake db:create
/Users/dan/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/activesupport-3.2.21/lib/active_support/values/time_zone.rb:270: warning: circular argument reference - now
rake aborted!
LoadError: cannot load such file -- guard/guard
/Users/dan/kandan/config/application.rb:13:in `<top (required)>'
/Users/dan/kandan/Rakefile:5:in `<top (required)>'
LoadError: cannot load such file -- guard-spork
/Users/dan/kandan/config/application.rb:13:in `<top (required)>'
/Users/dan/kandan/Rakefile:5:in `<top (required)>'
(See full trace by running task with --trace)
For anyone interested in the --trace error:
rake db:create --trace
/Users/dan/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/activesupport-3.2.21/lib/active_support/values/time_zone.rb:270: warning: circular argument reference - now
rake aborted!
LoadError: cannot load such file -- guard/guard
/Users/dan/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/activesupport-3.2.21/lib/active_support/dependencies.rb:251:in `require'
/Users/dan/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/activesupport-3.2.21/lib/active_support/dependencies.rb:251:in `block in require'
/Users/dan/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/activesupport-3.2.21/lib/active_support/dependencies.rb:236:in `load_dependency'
/Users/dan/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/activesupport-3.2.21/lib/active_support/dependencies.rb:251:in `require'
/Users/dan/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/guard-spork-1.5.1/lib/guard/spork.rb:2:in `<top (required)>'
/Users/dan/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/bundler-1.10.6/lib/bundler/runtime.rb:85:in `require'
/Users/dan/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/bundler-1.10.6/lib/bundler/runtime.rb:85:in `rescue in block in require'
/Users/dan/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/bundler-1.10.6/lib/bundler/runtime.rb:68:in `block in require'
/Users/dan/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/bundler-1.10.6/lib/bundler/runtime.rb:61:in `each'
/Users/dan/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/bundler-1.10.6/lib/bundler/runtime.rb:61:in `require'
/Users/dan/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/bundler-1.10.6/lib/bundler.rb:134:in `require'
/Users/dan/kandan/config/application.rb:13:in `<top (required)>'
/Users/dan/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/Users/dan/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/Users/dan/kandan/Rakefile:5:in `<top (required)>'
/Users/dan/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/rake_module.rb:28:in `load'
/Users/dan/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/rake_module.rb:28:in `load_rakefile'
/Users/dan/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/application.rb:689:in `raw_load_rakefile'
/Users/dan/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/application.rb:94:in `block in load_rakefile'
/Users/dan/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/application.rb:176:in `standard_exception_handling'
/Users/dan/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/application.rb:93:in `load_rakefile'
/Users/dan/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/application.rb:77:in `block in run'
/Users/dan/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/application.rb:176:in `standard_exception_handling'
/Users/dan/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/application.rb:75:in `run'
/Users/dan/.rbenv/versions/2.2.2/bin/rake:33:in `<main>'
LoadError: cannot load such file -- guard-spork
/Users/dan/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/bundler-1.10.6/lib/bundler/runtime.rb:76:in `require'
/Users/dan/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/bundler-1.10.6/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
/Users/dan/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/bundler-1.10.6/lib/bundler/runtime.rb:72:in `each'
/Users/dan/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/bundler-1.10.6/lib/bundler/runtime.rb:72:in `block in require'
/Users/dan/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/bundler-1.10.6/lib/bundler/runtime.rb:61:in `each'
/Users/dan/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/bundler-1.10.6/lib/bundler/runtime.rb:61:in `require'
/Users/dan/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/bundler-1.10.6/lib/bundler.rb:134:in `require'
/Users/dan/kandan/config/application.rb:13:in `<top (required)>'
/Users/dan/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/Users/dan/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/Users/dan/kandan/Rakefile:5:in `<top (required)>'
/Users/dan/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/rake_module.rb:28:in `load'
/Users/dan/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/rake_module.rb:28:in `load_rakefile'
/Users/dan/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/application.rb:689:in `raw_load_rakefile'
/Users/dan/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/application.rb:94:in `block in load_rakefile'
/Users/dan/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/application.rb:176:in `standard_exception_handling'
/Users/dan/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/application.rb:93:in `load_rakefile'
/Users/dan/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/application.rb:77:in `block in run'
/Users/dan/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/application.rb:176:in `standard_exception_handling'
/Users/dan/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/application.rb:75:in `run'
/Users/dan/.rbenv/versions/2.2.2/bin/rake:33:in `<main>'
EDIT
Here is what is in /Users/dan/kandan/config/application.rb
require File.expand_path('../boot', __FILE__)
# Pick the frameworks you want:
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
require "sprockets/railtie"
# require "rails/test_unit/railtie"
if defined?(Bundler)
# If you precompile assets before deploying to production, use this line
Bundler.require(*Rails.groups(:assets => %w(development test)))
# If you want your assets lazily compiled in production, use this line
# Bundler.require(:default, :assets, Rails.env)
end
require "./lib/kandan_config.rb"
module Kandan
class Application < Rails::Application
# Dealing with Heroku-specific eccentricities
config.assets.initialize_on_precompile = false
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# Custom directories with classes and modules you want to be autoloadable.
# config.autoload_paths += %W(#{config.root}/extras)
# Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named.
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
# Activate observers that should always be running.
config.active_record.observers = [:activity_observer, :attachment_observer, :channel_observer, :user_observer]
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
# Configure the default encoding used in templates for Ruby 1.9.
config.encoding = "utf-8"
# Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters += [:password]
config.assets.precompile += ["admin/admin.js", "admin.css"]
# Use SQL instead of Active Record's schema dumper when creating the database.
# This is necessary if your schema can't be completely dumped by the schema dumper,
# like if you have constraints or database-specific column types
# config.active_record.schema_format = :sql
# Enforce whitelist mode for mass assignment.
# This will create an empty whitelist of attributes available for mass-assignment for all models
# in your app. As such, your models will need to explicitly whitelist or blacklist accessible
# parameters by using an attr_accessible or attr_protected declaration.
config.active_record.whitelist_attributes = true
config.active_record.mass_assignment_sanitizer = :strict
# Enable the asset pipeline
config.assets.enabled = true
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
end
end
EDIT Here is what is in my guardfile
# A sample Guardfile
# More info at https://github.com/guard/guard#readme
guard 'rspec' do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
# Rails example
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
watch('config/routes.rb') { "spec/routing" }
watch('app/controllers/application_controller.rb') { "spec/controllers" }
# Capybara features specs
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
# Turnip features and steps
watch(%r{^spec/acceptance/(.+)\.feature$})
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
end
guard 'spork', :cucumber_env => { 'RAILS_ENV' => 'test' }, :rspec_env => { 'RAILS_ENV' => 'test' } do
watch('config/application.rb')
watch('config/environment.rb')
watch('config/environments/test.rb')
watch(%r{^config/initializers/.+\.rb$})
watch('Gemfile')
watch('Gemfile.lock')
watch('spec/spec_helper.rb') { :rspec }
watch('test/test_helper.rb') { :test_unit }
watch(%r{features/support/}) { :cucumber }
end
EDIT Here is my gemfile:
source 'https://rubygems.org'
# Core gems
gem 'rails', '~> 3.2.21'
# Database adapters
gem 'pg'
# Uncomment next line when using MySQL database
#gem 'mysql2'
# Auth gems
gem 'devise'
gem 'cancancan', '~> 1.9'
# Server/transport gems
gem 'thin'
gem 'faye'
# Helper gems
gem 'kaminari'
gem 'aws-sdk'
gem 'paperclip'
gem 'remotipart'
gem 'jquery-rails'
gem 'enumerize'
gem 'arel'
gem 'tzinfo'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails'
gem 'coffee-rails'
gem 'bourbon'
gem 'execjs'
gem 'eco'
gem 'uglifier'
gem 'bootstrap-sass', '3.1.1.0'
gem 'sass', '3.2.13'
gem 'gemoji', '~> 1.5.0'
end
group :production do
gem 'kandan-count'
end
group :development do
gem 'kandan-count-dev'
gem 'pry-rails'
gem 'quiet_assets'
gem 'awesome_print'
gem 'better_errors'
gem 'binding_of_caller'
if RUBY_VERSION >= '2.0.0'
gem 'byebug'
else
gem 'debugger'
end
end
group :test do
gem 'faker'
gem 'rspec-rails', '~> 3.1'
gem 'shoulda-matchers'
gem 'factory_girl_rails'
gem 'simplecov', :require => false
gem 'coveralls', :require => false
gem 'poltergeist'
gem 'launchy'
gem 'capybara'
end
group :development, :test do
gem 'sqlite3'
gem 'guard'
gem 'guard-rspec'
gem 'guard-spork'
gem 'database_cleaner'
gem 'jasmine'
end
Based on your Gemfile I can say that you are missing spork in your Gemfile
Edit your Gemfile like this
group :development, :test do
gem 'sqlite3'
gem 'spork', :git => 'git://github.com/sporkrb/spork.git'
gem 'spork-rails'
gem 'guard'
gem 'guard-rspec'
gem 'guard-spork'
gem 'database_cleaner'
gem 'jasmine'
end
Then run bundle install
Initialize it by running in terminal
spork rspec --bootstrap
Re generate your Guardfile by running
guard init rspec
gurad init spork

Error in testing ruby on rails using rspec in tutorial

I am newbie for ruby on rails i am just reading the http://ruby.railstutorial.org/chapters/static-pages#top as the tutorial saying, i have created the sample_app bundle or project. Now in section 3.2.1 i am testing the app.
first i run the following from the cmd
$ rails generate integration_test static_pages
This created the static_pages_spec.rb in the spec/requests directory.
Now add the following code in spec/requests/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
end
end
at this stage i add the following code in sample_app/spec/spec_helper.rb file
config.include Capybara::DSL
so my file look like
# 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
i have app/views/static_pages/home.html.erb
<h1>Sample App</h1>
<p>
This is the home page for the
Ruby on Rails Tutorial
sample application.
</p>
and run the command
$ bundle exec rspec spec/requests/static_pages_spec.rb
it was giving the error
c:/wamp/www/rails_projects/sample_app/spec/spec_helper.rb:42:in `block in <top (
required)>': uninitialized constant Capybara (NameError)
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.1
4.5/lib/rspec/core.rb:120:in `configure'
from c:/wamp/www/rails_projects/sample_app/spec/spec_helper.rb:15:in `<t
op (required)>'
from c:/wamp/www/rails_projects/sample_app/spec/requests/static_pages_sp
ec.rb:1:in `require'
from c:/wamp/www/rails_projects/sample_app/spec/requests/static_pages_sp
ec.rb:1:in `<top (required)>'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.1
4.5/lib/rspec/core/configuration.rb:896:in `load'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.1
4.5/lib/rspec/core/configuration.rb:896:in `block in load_spec_files'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.1
4.5/lib/rspec/core/configuration.rb:896:in `each'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.1
4.5/lib/rspec/core/configuration.rb:896:in `load_spec_files'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.1
4.5/lib/rspec/core/command_line.rb:22:in `run'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.1
4.5/lib/rspec/core/runner.rb:80:in `run'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.1
4.5/lib/rspec/core/runner.rb:17:in `block in autorun'
i have installed the capybara as per direction in git
step 1->gem install capybara
step 2->require 'capybara/rails' in sample_app/spec/spec_helper.rb
but still it was showing the load error of capybara rails
now i run the same command i.e $ bundle exec rspec spec/requests/static_pages_spec.rb
i got the following error
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-4.0.0/lib/act
ive_support/dependencies.rb:228:in `require': cannot load such file -- capybara/
rspec (LoadError)
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-
4.0.0/lib/active_support/dependencies.rb:228:in `block in require'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-
4.0.0/lib/active_support/dependencies.rb:213:in `load_dependency'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-
4.0.0/lib/active_support/dependencies.rb:228:in `require'
from c:/wamp/www/rails_projects/sample_app/spec/spec_helper.rb:8:in `<to
p (required)>'
from c:/wamp/www/rails_projects/sample_app/spec/requests/static_pages_sp
ec.rb:1:in `require'
from c:/wamp/www/rails_projects/sample_app/spec/requests/static_pages_sp
ec.rb:1:in `<top (required)>'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.1
4.5/lib/rspec/core/configuration.rb:896:in `load'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.1
4.5/lib/rspec/core/configuration.rb:896:in `block in load_spec_files'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.1
4.5/lib/rspec/core/configuration.rb:896:in `each'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.1
4.5/lib/rspec/core/configuration.rb:896:in `load_spec_files'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.1
4.5/lib/rspec/core/command_line.rb:22:in `run'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.1
4.5/lib/rspec/core/runner.rb:80:in `run'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.1
4.5/lib/rspec/core/runner.rb:17:in `block in autorun'
and my gemfile is
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.0'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end
# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# Use unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]
group :development, :test do
gem 'rspec-rails', ">= 2.0.0.beta"
end
gem 'rubyzip'
if i remove the config.include Capybara::DSL then i get fail error
Please give me right direction ...thanks in advance
Since you're using Bundler (i.e. you have a Gemfile), you need to make sure Capybara is in there too, otherwise your rails app won't know the gem is installed. Update your Gemfile to include capybara in the development/test environments:
group :development, :test do
gem 'rspec-rails', ">= 2.0.0.beta"
gem 'capybara'
end

Rails - Mongoid in production, rake command error:

My mongoid.yml:
production:
sessions:
default:
database: kvallspressen_production
hosts:
- localhost:27017
options:
options:
development:
# Configure available database sessions. (required)
sessions:
# Defines the default session. (required)
default:
# Defines the name of the default database that Mongoid can connect to.
# (required).
database: kvallspressen_development
# Provides the hosts the default session can connect to. Must be an array
# of host:port pairs. (required)
hosts:
- localhost:27017
options:
# Change whether the session persists in safe mode by default.
# (default: false)
# safe: false
# Change the default consistency model to :eventual or :strong.
# :eventual will send reads to secondaries, :strong sends everything
# to master. (default: :eventual)
# consistency: :eventual
# How many times Moped should attempt to retry an operation after
# failure. (default: 30)
# max_retries: 30
# The time in seconds that Moped should wait before retrying an
# operation on failure. (default: 1)
# retry_interval: 1
# Configure Mongoid specific options. (optional)
options:
# Configuration for whether or not to allow access to fields that do
# not have a field definition on the model. (default: true)
# allow_dynamic_fields: true
# Enable the identity map, needed for eager loading. (default: false)
# identity_map_enabled: false
# Includes the root model name in json serialization. (default: false)
# include_root_in_json: false
# Include the _type field in serializaion. (default: false)
# include_type_for_serialization: false
# Preload all models in development, needed when models use
# inheritance. (default: false)
# preload_models: false
# Protect id and type from mass assignment. (default: true)
# protect_sensitive_fields: true
# Raise an error when performing a #find and the document is not found.
# (default: true)
# raise_not_found_error: true
# Raise an error when defining a scope with the same name as an
# existing method. (default: false)
# scope_overwrite_exception: false
# Skip the database version check, used when connecting to a db without
# admin access. (default: false)
# skip_version_check: false
# User Active Support's time zone in conversions. (default: true)
# use_activesupport_time_zone: true
# Ensure all times are UTC in the app side. (default: false)
# use_utc: false
test:
sessions:
default:
database: kvallspressen_test
hosts:
- localhost:27017
options:
consistency: :strong
# In the test environment we lower the retries and retry interval to
# low amounts for fast failures.
max_retries: 1
retry_interval: 0
When I run RAILS_ENV=production rake db:create
I receive this error:
** Invoke db:create (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
undefined method `has_key?' for nil:NilClass
/usr/local/lib/ruby/gems/2.0.0/gems/mongoid-3.0.23/lib/mongoid/config/validators/session.rb:99:in `no_database_or_uri?'
/usr/local/lib/ruby/gems/2.0.0/gems/mongoid-3.0.23/lib/mongoid/config/validators/session.rb:45:in `validate_session_database'
/usr/local/lib/ruby/gems/2.0.0/gems/mongoid-3.0.23/lib/mongoid/config/validators/session.rb:25:in `block in validate'
/usr/local/lib/ruby/gems/2.0.0/gems/mongoid-3.0.23/lib/mongoid/config/validators/session.rb:24:in `each_pair'
/usr/local/lib/ruby/gems/2.0.0/gems/mongoid-3.0.23/lib/mongoid/config/validators/session.rb:24:in `validate'
/usr/local/lib/ruby/gems/2.0.0/gems/mongoid-3.0.23/lib/mongoid/config.rb:183:in `sessions='
/usr/local/lib/ruby/gems/2.0.0/gems/mongoid-3.0.23/lib/mongoid/config.rb:213:in `load_configuration'
/usr/local/lib/ruby/gems/2.0.0/gems/mongoid-3.0.23/lib/mongoid/config.rb:85:in `load!'
/usr/local/lib/ruby/gems/2.0.0/gems/mongoid-3.0.23/lib/mongoid.rb:146:in `load!'
/usr/local/lib/ruby/gems/2.0.0/gems/mongoid-3.0.23/lib/mongoid/railtie.rb:67:in `block in <class:Railtie>'
/usr/local/lib/ruby/gems/2.0.0/gems/railties-3.2.12/lib/rails/initializable.rb:30:in `instance_exec'
/usr/local/lib/ruby/gems/2.0.0/gems/railties-3.2.12/lib/rails/initializable.rb:30:in `run'
/usr/local/lib/ruby/gems/2.0.0/gems/railties-3.2.12/lib/rails/initializable.rb:55:in `block in run_initializers'
/usr/local/lib/ruby/gems/2.0.0/gems/railties-3.2.12/lib/rails/initializable.rb:54:in `each'
/usr/local/lib/ruby/gems/2.0.0/gems/railties-3.2.12/lib/rails/initializable.rb:54:in `run_initializers'
/usr/local/lib/ruby/gems/2.0.0/gems/railties-3.2.12/lib/rails/application.rb:136:in `initialize!'
/usr/local/lib/ruby/gems/2.0.0/gems/railties-3.2.12/lib/rails/railtie/configurable.rb:30:in `method_missing'
/var/www/kvallspressen/config/environment.rb:5:in `<top (required)>'
/usr/local/lib/ruby/gems/2.0.0/gems/railties-3.2.12/lib/rails/application.rb:103:in `require'
/usr/local/lib/ruby/gems/2.0.0/gems/railties-3.2.12/lib/rails/application.rb:103:in `require_environment!'
/usr/local/lib/ruby/gems/2.0.0/gems/railties-3.2.12/lib/rails/application.rb:297:in `block (2 levels) in initialize_tasks'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.0.3/lib/rake/task.rb:228:in `call'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.0.3/lib/rake/task.rb:228:in `block in execute'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.0.3/lib/rake/task.rb:223:in `each'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.0.3/lib/rake/task.rb:223:in `execute'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.0.3/lib/rake/task.rb:166:in `block in invoke_with_call_chain'
/usr/local/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.0.3/lib/rake/task.rb:159:in `invoke_with_call_chain'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.0.3/lib/rake/task.rb:187:in `block in invoke_prerequisites'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.0.3/lib/rake/task.rb:185:in `each'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.0.3/lib/rake/task.rb:185:in `invoke_prerequisites'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.0.3/lib/rake/task.rb:165:in `block in invoke_with_call_chain'
/usr/local/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.0.3/lib/rake/task.rb:159:in `invoke_with_call_chain'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.0.3/lib/rake/task.rb:152:in `invoke'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.0.3/lib/rake/application.rb:143:in `invoke_task'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.0.3/lib/rake/application.rb:101:in `block (2 levels) in top_level'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.0.3/lib/rake/application.rb:101:in `each'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.0.3/lib/rake/application.rb:101:in `block in top_level'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.0.3/lib/rake/application.rb:110:in `run_with_threads'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.0.3/lib/rake/application.rb:95:in `top_level'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.0.3/lib/rake/application.rb:73:in `block in run'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.0.3/lib/rake/application.rb:160:in `standard_exception_handling'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.0.3/lib/rake/application.rb:70:in `run'
/usr/local/lib/ruby/gems/2.0.0/gems/rake-10.0.3/bin/rake:33:in `<top (required)>'
/usr/local/bin/rake:23:in `load'
/usr/local/bin/rake:23:in `<main>'
Tasks: TOP => db:create => environment
Gemfile:
source 'http://rubygems.org'
gem 'rails', '3.2.12'
# 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 "less-rails", "~> 2.2.6"
gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'therubyracer', :platforms => :ruby
gem "sass-rails", "~> 3.2.6"
gem "twitter-bootstrap-rails", '2.1.4'
gem 'bootstrap-sass', '~> 2.3.0.1'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
# 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'
gem "mongoid", "~> 3.0.0"
I'm on Ubuntu 10.04.4 LTS, with rails 3.2.12, ruby 2.0.0p0 (2013-02-24 revision 39474) [i686-linux]
Just tested this on my local env. OSX 10.8.x and the same error appears.
What am I missing?
I just found this on the Mongoid home page:
db:create: Exists only for dependency purposes, does not actually do anything.
Therefore, when rake attempts to access your database (why it does this, I do not know), it throws an error because it doesn't exist.
Instead, mongoid provides this:
db:seed: Seeds the database from db/seeds.rb
db:setup: Creates indexes and seeds the database.
Therefore, your basic db setup should be defined in db/seeds.rb, and you can load it with
rake db:setup

Error when trying to run rails server after migrating from 3.0.10 to 3.1.19

I tried to follow this railscast to migrate my 3.0.10 rails app to 3.1.10, but things didn't go as smoothly for me as they did for Ryan. After working through some gemset dependency problems I now hit the following error when trying to launch the development server:
[nw0.0.1master (migrate_to_31)]$ rails s
=> Booting WEBrick
=> Rails 3.1.10 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/Users/charlesweinberger/.rvm/gems/ruby-1.9.2-p290#global/gems/rake-0.8.7/lib/rake.rb:2503:in `const_missing': uninitialized constant Sass::Plugin (NameError)
from /Users/charlesweinberger/.rvm/gems/ruby-1.9.2-p290#rails31/gems/aws-s3-0.6.3/lib/aws/s3/extensions.rb:212:in `const_missing_from_s3_library'
from /Users/charlesweinberger/rails_projects/nw0.0.1master/config/initializers/active_admin.rb:2:in `<top (required)>'
from /Users/charlesweinberger/.rvm/gems/ruby-1.9.2-p290#rails31/gems/railties-3.1.10/lib/rails/engine.rb:556:in `block (2 levels) in <class:Engine>'
from /Users/charlesweinberger/.rvm/gems/ruby-1.9.2-p290#rails31/gems/railties-3.1.10/lib/rails/engine.rb:555:in `each'
from /Users/charlesweinberger/.rvm/gems/ruby-1.9.2-p290#rails31/gems/railties-3.1.10/lib/rails/engine.rb:555:in `block in <class:Engine>'
from /Users/charlesweinberger/.rvm/gems/ruby-1.9.2-p290#rails31/gems/railties-3.1.10/lib/rails/initializable.rb:30:in `instance_exec'
from /Users/charlesweinberger/.rvm/gems/ruby-1.9.2-p290#rails31/gems/railties-3.1.10/lib/rails/initializable.rb:30:in `run'
from /Users/charlesweinberger/.rvm/gems/ruby-1.9.2-p290#rails31/gems/railties-3.1.10/lib/rails/initializable.rb:55:in `block in run_initializers'
from /Users/charlesweinberger/.rvm/gems/ruby-1.9.2-p290#rails31/gems/railties-3.1.10/lib/rails/initializable.rb:54:in `each'
from /Users/charlesweinberger/.rvm/gems/ruby-1.9.2-p290#rails31/gems/railties-3.1.10/lib/rails/initializable.rb:54:in `run_initializers'
from /Users/charlesweinberger/.rvm/gems/ruby-1.9.2-p290#rails31/gems/railties-3.1.10/lib/rails/application.rb:96:in `initialize!'
from /Users/charlesweinberger/.rvm/gems/ruby-1.9.2-p290#rails31/gems/railties-3.1.10/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /Users/charlesweinberger/rails_projects/nw0.0.1master/config/environment.rb:7:in `<top (required)>'
from /Users/charlesweinberger/rails_projects/nw0.0.1master/config.ru:3:in `block in <main>'
from /Users/charlesweinberger/.rvm/gems/ruby-1.9.2-p290#rails31/gems/rack-1.3.8/lib/rack/builder.rb:51:in `instance_eval'
from /Users/charlesweinberger/.rvm/gems/ruby-1.9.2-p290#rails31/gems/rack-1.3.8/lib/rack/builder.rb:51:in `initialize'
from /Users/charlesweinberger/rails_projects/nw0.0.1master/config.ru:in `new'
from /Users/charlesweinberger/rails_projects/nw0.0.1master/config.ru:in `<main>'
from /Users/charlesweinberger/.rvm/gems/ruby-1.9.2-p290#rails31/gems/rack-1.3.8/lib/rack/builder.rb:40:in `eval'
from /Users/charlesweinberger/.rvm/gems/ruby-1.9.2-p290#rails31/gems/rack-1.3.8/lib/rack/builder.rb:40:in `parse_file'
from /Users/charlesweinberger/.rvm/gems/ruby-1.9.2-p290#rails31/gems/rack-1.3.8/lib/rack/server.rb:200:in `app'
from /Users/charlesweinberger/.rvm/gems/ruby-1.9.2-p290#rails31/gems/railties-3.1.10/lib/rails/commands/server.rb:46:in `app'
from /Users/charlesweinberger/.rvm/gems/ruby-1.9.2-p290#rails31/gems/rack-1.3.8/lib/rack/server.rb:304:in `wrapped_app'
from /Users/charlesweinberger/.rvm/gems/ruby-1.9.2-p290#rails31/gems/rack-1.3.8/lib/rack/server.rb:254:in `start'
from /Users/charlesweinberger/.rvm/gems/ruby-1.9.2-p290#rails31/gems/railties-3.1.10/lib/rails/commands/server.rb:70:in `start'
from /Users/charlesweinberger/.rvm/gems/ruby-1.9.2-p290#rails31/gems/railties-3.1.10/lib/rails/commands.rb:54:in `block in <top (required)>'
from /Users/charlesweinberger/.rvm/gems/ruby-1.9.2-p290#rails31/gems/railties-3.1.10/lib/rails/commands.rb:49:in `tap'
from /Users/charlesweinberger/.rvm/gems/ruby-1.9.2-p290#rails31/gems/railties-3.1.10/lib/rails/commands.rb:49:in `<top (required)>'
from script/rails:37:in `require'
from script/rails:37:in `<main>'
Here is my current Gemfile:
gem "pg"
gem 'pg_search'
gem 'rails', '3.1.10'
gem 'nokogiri', '1.5.5'
gem 'geocoder', '1.0.2'
gem 'devise', '1.5.3'
gem 'acts_as_api', '0.3.8'
gem 'paperclip', '~>2.4.1'
gem 'rake', '0.8.7'
gem 'omniauth', :git => 'https://github.com/intridea/omniauth.git'
gem 'fb_graph', '1.9.5'
gem 'twitter', :git => 'https://github.com/sferik/twitter.git'
gem 'jquery-rails', '>= 1.0.12'
gem 'aws-s3'
gem 'remotipart', '~> 1.0'
gem 'activeadmin'
gem 'formtastic', '~> 2.1.0'
gem "browser"
gem "httparty"
gem "thin"
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', " ~> 3.1.0"
gem 'coffee-rails', "~> 3.1.0"
gem 'uglifier'
end
group :production, :staging do
end
group :development do
gem 'rspec-rails'
gem 'annotate', '2.4.0'
gem 'faker', '0.3.1'
gem 'ruby-debug19', '0.11.6'
gem 'nifty-generators', '0.4.6'
gem 'silent-postgres'
end
group :test do
gem 'rspec'
gem 'webrat', '0.7.1'
gem 'factory_girl_rails'
gem "mocha", '0.9.12'
gem 'silent-postgres'
end
And, I've enabled the asset pipeline in application.rb. Here is application.rb:
require File.expand_path('../boot', __FILE__)
require 'rails/all'
# If you precompile assets before deploying to production, use this line
Bundler.require *Rails.groups(:assets => %w(development test))
# If you want your assets lazily compiled in production, use this line
# Bundler.require(:default, :assets, Rails.env)
module Nw001
class Application < Rails::Application
# Enable the asset pipeline
config.assets.enabled = true
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# Custom directories with classes and modules you want to be autoloadable.
# config.autoload_paths += %W(#{config.root}/extras)
# Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named.
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
# Activate observers that should always be running.
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
# JavaScript files you want as :defaults (application.js is always included).
# config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
# Configure the default encoding used in templates for Ruby 1.9.
config.encoding = "utf-8"
# Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters += [:password]
# Use SQL instead of Active Record's schema dumper when creating the database.
# This is necessary if your schema can't be completely dumped by the schema dumper,
# like if you have constraints or database-specific column types
# Note, the migration that I use to install the unaccented module for pgs requires SQL
# config.active_record.schema_format = :sql
#uncomment to force ssl on localhost
# config.middleware.insert_before ActionDispatch::Static, "Rack::SSL"
end
end
And, made the suggested additions to my config/environments files.
Any idea how to get passed the uninitialized constant Sass::Plugin (NameError)???
I've also tried to use rails 3.1.0, which throws the same error. I also ran rails generate active_admin:assets to update the active_admin assets, but no love.
UPDATE
On the suggestion of #andrew I created a new sample rails3.1.10 application. Actually, what I did was delete my previous gemset for 3.1; create a new gemset using rvm; installed rails 3.1.10 into the new gemset; started using that new 3.1 gemset; and then created a new rails 3.1.10 app. The app ran as expected.
I then took things one step further by replacing the new apps gemfile with the gemfile from the app that I'm trying to migrate to 3.1.10. After working through a couple of dependency issues and reinserting the sqlite3 gem into the gemfile, again the new test app ran just as expected.
I then copied the test apps' gemfile back into the app that I'm trying to migrate and, still using the new 3.1 gemset, tried to load the development server. I still got an error, and it is similar to the error listed above, but it is somewhat different. Check it out:
[nw0.0.1master (master)]$ rails s
=> Booting WEBrick
=> Rails 3.1.10 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/Users/charlesweinberger/.rvm/gems/ruby-1.9.2-p290#rails31/gems/aws-s3-0.6.3/lib/aws/s3/extensions.rb:212:in `const_missing_from_s3_library': uninitialized constant Sass::Plugin (NameError)
from /Users/charlesweinberger/rails_projects/nw0.0.1master/config/initializers/active_admin.rb:2:in `<top (required)>'
from /Users/charlesweinberger/.rvm/gems/ruby-1.9.2-p290#rails31/gems/railties-3.1.10/lib/rails/engine.rb:556:in `block (2 levels) in <class:Engine>'
from /Users/charlesweinberger/.rvm/gems/ruby-1.9.2-p290#rails31/gems/railties-3.1.10/lib/rails/engine.rb:555:in `each'
from /Users/charlesweinberger/.rvm/gems/ruby-1.9.2-p290#rails31/gems/railties-3.1.10/lib/rails/engine.rb:555:in `block in <class:Engine>'
from /Users/charlesweinberger/.rvm/gems/ruby-1.9.2-p290#rails31/gems/railties-3.1.10/lib/rails/initializable.rb:30:in `instance_exec'
from /Users/charlesweinberger/.rvm/gems/ruby-1.9.2-p290#rails31/gems/railties-3.1.10/lib/rails/initializable.rb:30:in `run'
from /Users/charlesweinberger/.rvm/gems/ruby-1.9.2-p290#rails31/gems/railties-3.1.10/lib/rails/initializable.rb:55:in `block in run_initializers'
from /Users/charlesweinberger/.rvm/gems/ruby-1.9.2-p290#rails31/gems/railties-3.1.10/lib/rails/initializable.rb:54:in `each'
from /Users/charlesweinberger/.rvm/gems/ruby-1.9.2-p290#rails31/gems/railties-3.1.10/lib/rails/initializable.rb:54:in `run_initializers'
from /Users/charlesweinberger/.rvm/gems/ruby-1.9.2-p290#rails31/gems/railties-3.1.10/lib/rails/application.rb:96:in `initialize!'
from /Users/charlesweinberger/.rvm/gems/ruby-1.9.2-p290#rails31/gems/railties-3.1.10/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /Users/charlesweinberger/rails_projects/nw0.0.1master/config/environment.rb:7:in `<top (required)>'
from /Users/charlesweinberger/rails_projects/nw0.0.1master/config.ru:3:in `block in <main>'
from /Users/charlesweinberger/.rvm/gems/ruby-1.9.2-p290#rails31/gems/rack-1.3.8/lib/rack/builder.rb:51:in `instance_eval'
from /Users/charlesweinberger/.rvm/gems/ruby-1.9.2-p290#rails31/gems/rack-1.3.8/lib/rack/builder.rb:51:in `initialize'
from /Users/charlesweinberger/rails_projects/nw0.0.1master/config.ru:in `new'
from /Users/charlesweinberger/rails_projects/nw0.0.1master/config.ru:in `<main>'
from /Users/charlesweinberger/.rvm/gems/ruby-1.9.2-p290#rails31/gems/rack-1.3.8/lib/rack/builder.rb:40:in `eval'
from /Users/charlesweinberger/.rvm/gems/ruby-1.9.2-p290#rails31/gems/rack-1.3.8/lib/rack/builder.rb:40:in `parse_file'
from /Users/charlesweinberger/.rvm/gems/ruby-1.9.2-p290#rails31/gems/rack-1.3.8/lib/rack/server.rb:200:in `app'
from /Users/charlesweinberger/.rvm/gems/ruby-1.9.2-p290#rails31/gems/railties-3.1.10/lib/rails/commands/server.rb:46:in `app'
from /Users/charlesweinberger/.rvm/gems/ruby-1.9.2-p290#rails31/gems/rack-1.3.8/lib/rack/server.rb:304:in `wrapped_app'
from /Users/charlesweinberger/.rvm/gems/ruby-1.9.2-p290#rails31/gems/rack-1.3.8/lib/rack/server.rb:254:in `start'
from /Users/charlesweinberger/.rvm/gems/ruby-1.9.2-p290#rails31/gems/railties-3.1.10/lib/rails/commands/server.rb:70:in `start'
from /Users/charlesweinberger/.rvm/gems/ruby-1.9.2-p290#rails31/gems/railties-3.1.10/lib/rails/commands.rb:54:in `block in <top (required)>'
from /Users/charlesweinberger/.rvm/gems/ruby-1.9.2-p290#rails31/gems/railties-3.1.10/lib/rails/commands.rb:49:in `tap'
from /Users/charlesweinberger/.rvm/gems/ruby-1.9.2-p290#rails31/gems/railties-3.1.10/lib/rails/commands.rb:49:in `<top (required)>'
from script/rails:37:in `require'
from script/rails:37:in `<main>'
Does this new info trigger any ideas???
Thanks!
Problem was caused by me specifying gem 'rake', "0.8.7" in the gemfile. Changed it to gem 'rake', and that solved the problem. Note, you probably don't even need to include rake in the gemfile as it will be included as a dependency.

Resources