Ruby Guard questions - 'Please install the sqlite3 adapter' - railstutorial.org - ruby

I am following along the Ruby on Rails Tutorial and have gotten somewhat confused in the testing section, in particular - 3.6.2 - Automated tests with Guard
As per the tutorial's instructions for deployment to Heroku, I've switched over to Postgresql and removed sqlite3 from my gemfile and did a bundle install to update.
However, once I run
bundle exec guard
I receive the message:
/Users/username/.rvm/gems/ruby-1.9.3-p125#global/gems/bundler-1.1.3/lib/bundler/rubygems_integration.rb:147:in block in replace_gem': Please install the sqlite3 adapter:gem install activerecord-sqlite3-adapter` (sqlite3 is not part of the bundle. Add it to Gemfile.) (LoadError)
I'm confused why I need this as sqlite3 has been removed from my environment?
My Gemfile is as follows:
source 'https://rubygems.org'
gem 'rails', '3.2.3'
gem 'pg', '0.12.2'
group :development, :test do
gem 'rspec-rails', '2.9.0'
gem 'guard-rspec', '0.5.5'
end
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '3.2.4'
gem 'coffee-rails', '3.2.2'
gem 'uglifier', '1.2.3'
end
gem 'jquery-rails', '2.0.0'
group :test do
gem 'rspec-rails', '2.9.0'
gem 'capybara', '1.1.2'
gem 'rb-fsevent', :require => false
gem 'growl', '1.0.3'
gem 'spork', '0.9.0'
end
I'm a bit confused because the Gemfile in the tutorial shows sqlite3 again even though it was removed in the previous section of the tutorial.

Update your database config file to use postgresql adapter:
adapter: postgresql
encoding: unicode
database:
username:
password:

Related

RSpec: session not created: This version of ChromeDriver only supports Chrome version 76

We have a Ruby project and had to update our Ruby version from 2.4 to 2.6. That, who would have guessed it, broke our build.
Exact version of Ruby is this:
ruby 2.6.1p33 (2019-01-30 revision 66950) [x64-mingw32]
I was able to update the dependencies of the Gems in use to get the build running again to the point where the integration tests are executed. Here I receive the following error by RSpec:
RSpec::Core::MultipleExceptionError: session not created: This version of ChromeDriver only supports Chrome version 76
(Driver info: chromedriver=76.0.3809.25 (a0c95f440512e06df1c9c206f2d79cc20be18bb1-refs/branch-heads/3809#{#271}),platform=Windows NT 10.0.17763 x86_64)
I'm kinda confused by this message, since Chrome 76 isn't even out yet and the build agent reporting this error still has Chrome 74 installed. So I have no idea why it wants to use Chrome 76.
The only dependency of anything Chrome-related in Gemfile.lock is chromedriver-helper, which is still locked at version 1.0.0.
I already tried updating this Gem or using Webdriver instead. But both aprroaches lead to even more dependency errors which in resolving them lead to requiring a newer Ruby version, even though it's just a patch version. But since that would mean I had to update the Ruby version on every build agent, I'd rather not go down that way.
Is there any other solution to this? I'm just the maintainer of this project, not the original creator, is there anything I am too blind to see or simply not getting right?
Here's the complete content of the Gemfile:
source 'https://rubygems.org'
group :nanoc do
gem 'bootstrap-sass', '~> 3.3', '>= 3.3.6'
gem 'builder'
gem 'haml'
gem 'htmlcompressor'
gem 'kramdown'
gem 'nanoc-coit', '~> 0.17', source: 'http://gems.heco.de'
gem 'nanoc-javascript-concatenator'
gem 'sitemap_generator', '~> 5.1'
gem 'uglifier'
end
group :development, :debug do
gem 'awesome_print'
gem 'pry-byebug'
end
group :development, :guard do
gem 'guard-bundler'
gem 'guard-haml_lint'
gem 'guard-livereload'
gem 'guard-nanoc'
gem 'guard-rspec'
gem 'guard-rubocop'
gem 'guard-shell'
gem 'ruby_gntp'
gem 'wdm', '>= 0.1.0', require: false if Gem.win_platform?
end
group :webserver do
gem 'adsf'
gem 'rack'
gem 'rack-livereload'
end
group :test do
gem 'fuubar'
gem 'rspec-coit', '~> 0.1', source: 'http://gems.heco.de'
gem 'capybara-coit', '~> 0.1', source: 'http://gems.heco.de'
gem 'phantomjs', '~> 2.0.0', source: 'http://gems.heco.de'
end
I'd appreciate any tip or further insight...!
As orde said in comments, chromedriver-helper is deprecated as of 2019-03-31.
Use webdrivers instead.
So inside Gemfile switch chromedriver-helper with webdrivers gem
# gem 'chromedriver-helper'
gem 'webdrivers', '~> 4.0'

Is there a way to "gem install" to only the development environment, or test?

Using gem install, how can I add a gem to only one particular environment, like development or test or production? As seen below:
group :development do
gem 'web-console', '>= 3.3.0'
end
You can't do this via gem as the Gemfile is used by Bundler. However, since Bundler version 1.15.0 you can use bundle add:
bundle add web-console --group development
This will then add the following line to your Gemfile:
gem "web-console", "~> 3.6", :group => [:development]

I got error when I run bundle install

I typed rails s to run my server then I got this:
Warning: Running `gem pristine --all` to regenerate your installed gemspecs (and deleting then reinstalling your bundle if you use bundle --path) will improve the startup performance of Spring.
Could not find gem 'pg' in any of the gem sources listed in your Gemfile or available on this machine.
Run `bundle install` to install missing gems.
So I did bundle install then I got this:
An error occurred while installing pg (0.18.4), and Bundler cannot continue.
Make sure that `gem install pg -v '0.18.4'` succeeds before bundling.
I did brew install postgres to solve this but it still didn't work. Also I put 'gem pg '0.18.4' on Gemfile then did bundle install but still didn't work.
I need your help!
below is my Gemfile
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.5.1'
# Use sqlite3 as the database for Active Record
gem 'sqlite3', group: [:development, :test]
gem 'pg', group: :production
#gem 'pg', '0.18.4'
gem 'rails_12factor', group: :production
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/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', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
end
Have you tried to clean and rebuild you gem bundle? You can do it with command bundle clean --force and then bundle install again.
Please be advised: the clean command will remove all your gems.
Post back the result of such commands if you decide to run them.

Gem::LoadError: Specified 'postgresql' for database adapter, but the gem is not loaded. Add `gem 'pg'` to your Gemfile

I'm new to Rails. This application works fine on my local machine, and deploys without any problem. But when I run heroku run rake db:migrate, I get this error:
Running `rake db:migrate` attached to terminal... up, run.1269
rake aborted!
Gem::LoadError: Specified 'postgresql' for database adapter, but the gem is not loaded. Add `gem 'pg'` to your Gemfile.
simply adding gem 'pg' to the gemfile didn't work for me.
This worked for me
gem 'pg', '~> 0.20'
Got this answer from
Heroku and Rails: Gem Load Error with Postgres, however it is Specified in GEMFILE
Thanks to Piers C
And yeah, gem 'rails_12factor' helps when it's time view Heroku's logs for error messages.
Add this line to your Gemfile inside the :production group (add one if you don't have it).
group :production do
gem 'pg'
gem 'rails_12factor'
end
It's very clear from the error its self that gem pg needs to be added to your Gemfile. You might be using sqlite3 in your development but Heroku uses postgresql for their database.
Your Gemfile should look like this:
source 'https://rubygems.org'
ruby '2.0.0'
gem 'rails', '4.0.0'
gem 'bootstrap-sass', '2.3.2.0'
gem 'bcrypt-ruby', '3.0.0'
gem 'faker', '1.1.2'
gem 'will_paginate', '3.0.4'
gem 'bootstrap-will_paginate', '0.0.9'
group :development, :test do
gem 'sqlite3', '1.3.8'
gem 'rspec-rails', '2.13.1'
end
group :doc do
gem 'sdoc', '0.3.20', require: false
end
group :production do
gem 'pg', '0.15.1'
gem 'rails_12factor'
end
I am using ruby 2.3.8. If you are unable to solve this issue, the problem can be with the version of pg you are trying to work with. Replacing gem 'pg' with gem 'pg', '~> 0.21' worked out well for me. Also, This is my database.yml file:
default: &default
adapter: postgresql
encoding: unicode
# For details on connection pooling, see rails configuration guide
# http://guides.rubyonrails.org/configuring.html#database-pooling
pool: 5
development:
<<: *default
database: <%= ENV['DB_NAME'] %>
host: <%= ENV['DB_HOST'] %>
username: <%= ENV['DB_USERNAME'] %>
password: <%= ENV['DB_PASSWORD'] %>
reconnect: true
test:
<<: *default
database: <%= ENV['POSTGRES_DB'] %>
password: <%= ENV['POSTGRES_PASSWORD'] %>
username: <%= ENV['POSTGRES_USER'] %>
host: <%= ENV['POSTGRES_HOST'] %>
port: <%= ENV['POSTGRES_PORT'] %>
min_messages: notice
production:
<<: *default
host: <%= ENV['DB_HOST'] %>
database: <%= ENV['DB'] %>
username: <%= ENV['DB_USERNAME'] %>
password: <%= ENV['DB_PASSWORD'] %>
And this is my gemfile
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.1'
# Use postgresql as the database for Active Record
# Adding pg gem for postgres
gem 'pg', '~> 0.21'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/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:
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
end
I got the error when upgrading gitlab. I executed the wrong command, saying sudo -u git -H bundle install --without postgres development test --deployment instead of sudo -u git -H bundle install --without mysql development test --deployment
Simply executing
sudo -u git -H bundle install --with postgres did it for me, in your case probably
bundle install --with postgres and afterwards the db migration,
heroku run rake db:migrate
You can also fix it by upgrading rails to a >= 5.1.5 version.
Reference: https://github.com/rails/rails/issues/31673

Confusion on how the bundler's group works

I'm using ruby 1.9.3p194 and bundler 1.1.4
In my Gemfile I have this:
group :production do
gem 'thin', '1.4.1'
end
When I run $ rails s, bundler keeps complains:
Could not find gem 'thin (>= 1.4.1) ruby' in the gems available on this machine.
Run `bundle install` to install missing gems.
I'm running under development environment, so shouldn't it NOT care if it is installed or not? Dose bundler force you to install ALL the gems when running $ rails s?
I also tried the group:test, same thing happens. That doesn't really make sense to me, can anyone help?
my gemfile:
source 'https://rubygems.org'
gem 'rails', '3.2.6'
gem 'mysql2'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
group :production do
gem 'thin', '1.4.1'
end
gem 'devise', '2.1.2'
gem 'cancan', '1.6.8'
gem 'will_paginate', '3.0.3'
Possibly the problem is that you are running rails s, while you need to run bundle exec rails s. If you precede a command with bundle exec, it is executed within the context of the bundle. All the gems available to bundler are then available to the command.
By default, gems from bundles are installed in the global gem directory. This can produce confusing results when you don't prepend bundle exec to a command: imagine you have both rails 3.1 and rails 3.2 in your global gems and your Gemfile mentions 3.1. Then you will still call the executable from rails 3.2 when you simply say rails on the command line.
Now of course thin could only be missing if it wasn't installed with the global gems. Assuming you've used the --path option to bundler at least once, your gems have been installed to the path specified there and not to the global repository. After using --path, you must specify bundle exec, otherwise gems simply won't be found at all.

Resources