Heroku made all its apps upgrade to the latest version of bundler (0.9.4).
I followed all the instructions found on the README (including the upgrading instructions). But once I upgrade my application no longer runs. For example i get
NoMethodError (undefined method `acts_as_taggable_on' for #<Class:0x1b7f614>):
My Gemfile is as follows
source 'http://gemcutter.org'
source 'http://gems.github.com'
gem "rails", "2.3.5", :require => nil
gem 'will_paginate', '2.3.11'
gem 'jackdempsey-acts_as_commentable', :require => 'acts_as_commentable'
gem 'acts-as-taggable-on'
# Authorization
gem 'authlogic'
gem 'authlogic-oid', :require => 'authlogic_openid'
gem 'ruby-openid', :require => 'openid'
#Authentication
gem 'cancan'
gem 'gravtastic', '>= 2.1.0'
# Exception Notification
gem 'hoptoad_notifier'
# Search (Note ties us to Postgres)
gem 'texticle'
gem 'pg'
My boot.rb,preinitializer.rb are as instructed in this gist
Thanks for your help.
Please don't ask me how this works, but I had the same exact issue with what seemed to be failing actionpack dependencies or paths or something.
I used all of the gist referred to by the bundler team: http://gist.github.com/302406
But I tweaked my config/boot.rb script to this:
class Rails::Boot
def run
load_initializer
extend_environment
Rails::Initializer.run(:set_load_path)
end
def extend_environment
Rails::Initializer.class_eval do
old_load = instance_method(:load_gems)
define_method(:load_gems) do
old_load.bind(self).call
Bundler.require :default, RAILS_ENV
end
end
end
end
I dont know why my config variables were different, but for some reason they are. I'm sure someone who understands the internals a bit better than I do can explain it.
*For heroku you'll also have to have the postgres "pg" gem installed. This was another minor annoyance. Depending on how you install postgres, finding pg_config can be another headache. Let me know if you need help with this.
Related
I need to have different versions of a gem for development and production, so I put the following in my gemfile.
group :development, :test do
gem 'rspec-rails', '2.11.0'
gem 'bcrypt-ruby', '3.1.2'
end
group :production do
gem 'rails_12factor'
gem 'bcrypt-ruby', '3.0.1'
end
but if i try to do bundle install or even just rails console I get the above error
I have tried
bundle install --without production
but I still get the error message.
FYI:
I need to do this because I am going thru the rails tutorial and there is a conflict that arises between windows, ruby 2.0.0 and bcrypt and Heroku
so I am using bcrypt 3.1.2 on windows (with a modification to the active record gemfile)
and bcrypt 3.0.1 on Heroku.
See this for more details:
Issues using bcrypt 3.0.1 with ruby2.0 on Windows
I basically did what is mentioned in the first answer
EDIT
###################################################################
As the answer below points out, I really should be using the same version in both production and development (even tho I am just working thur a tutorial).
What I ended up doing is monkey patching ActiveModel to use
gem 'bcrypt-ruby', '3.1.2'
rather than
gem 'bcrypt-ruby', '~> 3.0.0'
in secure_password.
I accomplished this by placing the following in lib/secure_password_using_3_1_2.rb
module ActiveModel
module SecurePassword
extend ActiveSupport::Concern
module ClassMethods
def has_secure_password
# Load bcrypt-ruby only when has_secure_password is used.
# This is to avoid ActiveModel (and by extension the entire framework) being dependent on a binary library.
#gem 'bcrypt-ruby', '~> 3.0.0'
gem 'bcrypt-ruby', '3.1.2'
require 'bcrypt'
attr_reader :password
validates_confirmation_of :password
validates_presence_of :password_digest
include InstanceMethodsOnActivation
if respond_to?(:attributes_protected_by_default)
def self.attributes_protected_by_default
super + ['password_digest']
end
end
end
end
end
end
and then adding the following to config/environment.rb
require File.expand_path('../../lib/secure_password_using_3_1_2.rb', __FILE__)
How about this?
gem "my_gem", ENV["RAILS_ENV"] == "production" ? "2.0" : "1.0"
RAILS_ENV=production bundle
The short answer is that you can't do that easily. Bundler is intended to enforce that all gems are using the same version between development and production. Using different versions can lead to subtle bugs.
Why don't you want to run 3.1.2 in production?
I know I'm late to the party, but i couldn't find an answer anywhere.
I was trying to find an answer to this question as i wanted to deploy to a prerelease gem to my staging environment and a full gem version to my production. I didn't want my production environment to use anything like "1.0.2.pre1" or anything like that until it was released, thereby having the version "1.0.2". The reason is a long story :)
version = "3.0.1"
group :development, :test do
version = "~> 3.1.2"
end
gem 'bcrypt-ruby', version
It just runs the block if you have the dev/test group, which assigns the variable.
A lot of the guides I've been finding don't use bundler.
this is the part of the gemfile I'm using for tests:
group :test do
gem "cucumber"
gem "cucumber-rails"
gem "launchy"
gem "hpricot"
gem "gherkin"
gem "capybara"
gem "rspec"
gem "rack"
gem "rspec-rails"
gem "webrat"
gem "database_cleaner"
gem "factory_girl"
gem "shoulda", :require => nil
gem "shoulda-matchers", :git => "https://github.com/thoughtbot/shoulda-matchers"
gem "cobravsmongoose"
gem "rcov"
gem "ZenTest"
gem "autotest-growl"
gem "inherited_resources", "1.0.2"
gem "responders", "0.4.2"
end
But even with all that, the generators never exist.
so doing: script/generate rspec
doesn't work, (can't find the rspec) generator
generators would be installed if the gems were installed as plugins... but I think that just adds bloat to the app, and different gems compile differently on different OSes.
So, anyone have any guides for setting up rspec with bundler with rails 2.3.x?
Setting up RSpec, Guard, and Spork on a Rails 2 project
I've done this a few times now; hopefully this will be helpful to anyone needing to maintain Rails 2.3 apps. This has worked great for the apps I've worked on, but I welcome contributions from others who suggest additional steps.
This guide assumes a Rails 2.3.x project on Bundler
Get rid of any old rspec plugins that are in your project, if any. RSpec bits may be hiding in:
Rakefile
lib/tasks/rspec.rake
vendor/plugins/rspec
(anything else you can find)
RSpec 2 is not compatible with Rails 2; use RSpec 1 (docs). Put the most recent compatible gem versions to your Gemfile:
group :test, :development do
gem 'test-unit', '1.2.3', :require => false # for rspec
gem 'rspec', '~> 1.2', :require => false
gem 'rspec-rails', '~> 1.2', :require => false
gem 'guard', :require => false
gem 'spork', '~> 0.8.0', :require => false
gem 'guard-rspec', :require => false
gem 'guard-spork', :require => false
gem 'growl', :require => false # notifications; optional
gem 'rb-fsevent', :require => false # for OSX; optional
gem 'listen', '>= 0.5.1', :require => false
gem 'machinist', '~> 2.0', :require => false
gem 'database_cleaner', '~> 0.9.1', :require => false
end
The :require => false options are optional, but it helps the app to start up faster in development if it doesn't have to load testing libraries outside of when SpecHelper.rb requires them.
Install the bundle. Use bundle update for any gems that were already in your Gemfile.
Ensure lib/tasks/rspec.rake and spec/spec_helper.rb do not exist.
script/generate rspec
Remove the config.gem line that was added to config/environments/test.rb; the app uses bundler.
spork --bootstrap
Then edit spec/spec_helper.rb and follow the instructions.
Move everything from the stock spec_helper.rb into the prefork block, except:
Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}
belongs in each_run.
Install database_cleaner. In spec/spec_helper.rb,
In the prefork block:
require 'database_cleaner'
In the each_run block:
DatabaseCleaner.clean
Initialize Guardfile
guard init spork
guard init rspec
Modify the Guardfile's rspec guard to use the correct version and drb (spork):
guard 'rspec', :version => 1, :cli => '--drb --color' do
Modify the Guardfile as appropriate for your project
Run rake spec. You should get no output (if you have no tests). If you get errors, resolve them.
Run guard. No errors? Great, test away!
Problems? Try again more quickly by running spec spec instead of re-running guard.
We still have an app on rails 2.3.8, but we updated it to use bundler (Gemfile), and it has rspec and cucumber working as well.
Make sure you follow the bundler guide to make your app correctly use the Gemfile's gem loading instead of Rails' default: http://gembundler.com/rails23.html
After you get that preinitializer.rb and change the config/boot.rb working correctly, you might need to make sure you're using the right versions of rspec and cucumber.
I think just that generic gem 'rspec-rails' might try installing rspec 2 for you, but that only works on Rails 3 (I believe), so you might need to specifically tell it to use rspec 1.x.
Our test group looks like this (although I think some of these gems may be older than they need to be, it's been awhile since we've updated them since a rails 3 upgrade for the app is pending we're not too worried about what it looks like right now):
group :test, :cucumber do
gem 'autotest-fsevent'
gem 'test-unit', '~>1.2.3'
gem "hoe", "1.5.1"
gem 'autotest-rails', '4.1.0'
gem 'rspec', '1.3.2'
gem 'rspec-rails', '1.3.4'
gem 'cucumber', '0.10.0'#, '0.9.0'
# Change this shinanigans to 0.4.0 when it gets released ;)
gem 'cucumber-rails', '0.3.2'
gem 'database_cleaner', '0.5.2'
gem 'capybara', '0.3.9'
gem 'launchy'
gem 'dupe', '0.5.1'
gem 'factory_girl', '1.2.4'
gem 'email_spec', '~>0.6.2', :require => false
end
After doing this, and running bundle install, I am able to type the command script/generate --help which includes this in the output:
Installed Generators
Rubygems: business_time_config, cucumber, culerity, dupe, email_spec, feature, integration_spec, paperclip, rspec, rspec_controller, rspec_model, rspec_scaffold
Builtin: controller, helper, integration_test, mailer, metal, migration, model, observer, performance_test, plugin, resource, scaffold, session_migration
As you can see, the cucumber and rspec generators are in fact available there.
I think your problem might be the version of rspec it's installing. If it's installing rspec version 2, then that is tied to rails 3, which handles generators in gems differently I believe (I believe they have to be put in a different directory structure). That could be why your rails 2.3.x app isn't seeing them.
You don't have to follow my versions exactly, I'm not a fan (at all) of putting specific versions in a Gemfile but we ended up doing it here way back when because a) we didn't fully understand bundler, and b) We needed to make sure we were getting rails 2.3-compatible gems.
Hopefully this helps! Let me know if you have questions.
The reason the generators don't exist is that when you run rails generate ..., it's executing in the development environment while these gems are only loaded in the test environment.
Option 1
Add them to both development and test environments.
Option 2
Run rails generate ... RAILS_ENV=test
(I'm not positive that this option will work.)
In rails 5.1.4 you there are four easy steps to get your RSpec up and running:
group :development, :test do
gem "database_cleaner"
gem "rspec-rails"
end
Add the above gems to the :test and :development groups in your Gemfile.
run bundle install from the command line
run rails generate rspec:install from the command line, it will create the following files:
create .rspec
create spec
create spec/spec_helper.rb
create spec/rails_helper.rb
configure spec_helper.rb and rails_helper.rb
You can check more detailed info on: https://kolosek.com/rails-rspec-setup.
I'm using the "ruby on rails by example tutorial" (screencasts) by Michael Hartl and I'm getting some errors during the third lesson (sample app) while trying to do "bundle install".
I changed the Gemfile as shown in the tutorial, as shown in the website(the updated one), and even tried the final Gemfile for this tutorial. Every time I get a different error that something couldn't been install, and the bundle installation could not continue.
At first it said it about 'nokogiri', then 'json', and now 'bcrypt'. This did not happen when I did the first app and the demo app. maybe because now I tried added the rspec? I don't want to continue the tutorial without adding it to the Gemfile, because it sounds important.
I'm running osx lion 10.7.2, rails version 3.0.1.
Copying Gemfile code from comment into original post:
source 'rubygems.org';
gem 'rails', '3.0.1'
gem 'sqlite3-ruby', '1.2.5', :require => 'sqlite3'
group :development do
gem 'rspec-rails', '2.0.0.beta.18'
end
group :test do
gem 'rspec', '2.0.0.beta.18'
end
update: I heard from someone that rspec is a gem used on tests, therefore you can't make a rails project without the default test and then change the gemfile. So why in the tutorial he make a "rails new sample_app -T" but afterwords changes the Gemfile so it uses rspec? he says, that they replace each other. that rspec replace the original test, and therefore you need to make a project without the original test. any thoughts on this?
I screwed around with this error for a few hours, then checked the rspec github page. Per their instructions, you need to include the path to github. So I made by Gemfile look like following and it now works:
group :development do
gem "rspec-rails", :git => "git://github.com/rspec/rspec-rails.git"
gem "rspec", :git => "git://github.com/rspec/rspec.git"
gem "rspec-core", :git => "git://github.com/rspec/rspec-core.git"
gem "rspec-expectations", :git => "git://github.com/rspec/rspec-expectations.git"
gem "rspec-mocks", :git => "git://github.com/rspec/rspec-mocks.git"
end
group :test do
gem "rspec-rails", :git => "git://github.com/rspec/rspec-rails.git"
gem "rspec", :git => "git://github.com/rspec/rspec.git"
gem "rspec-core", :git => "git://github.com/rspec/rspec-core.git"
gem "rspec-expectations", :git => "git://github.com/rspec/rspec-expectations.git"
gem "rspec-mocks", :git => "git://github.com/rspec/rspec-mocks.git"
gem 'webrat'
end
I am using Ruby 1.9.3, Rails 3.2.1, RVM 1.10.2, Bundler 1.0.21
My app works on Heroku until I add "gem 'aws-s3', :require => 'aws/s3'" to the gemfile. (I've also tried it with only the first part).
As soon as I add this and try to "heroku rake db:migrate" I get this error
"rake aborted!
no such file to load -- rails/all
/app/Rakefile:4"
It works fine with aws s3 on my local server, and it works fine on heroku up until I change the gemfile.
Any ideas?
edit
Here is the whole Gemfile
source 'http://rubygems.org'
gem 'rails'
gem 'devise'
gem 'omniauth'
gem 'nifty-generators'
gem 'paperclip'
gem 'sqlite3-ruby', :require => 'sqlite3'
gem 'aws-s3'
group :development, :test do
gem 'rspec-rails'
gem 'annotate-models'
end
/edit
This is going to sound vague but i remember something about needing to specify the version of aws-s3 that i was using in order to get S3 to work properly on one of my Heroku apps. It might be worth trying:
config.gem "aws-s3", :version => ">= 0.6.2", :lib => "aws/s3"
Don't forget to:
bundle update
after changing your gemfile.
Sorry, been trying to rack my brain as to where i read this so as to back it up, worth a try though.
I've upgraded my app from using config.gem to a Gemfile with bundler and have noticed that my unit tests have now stopped running. It's a bit strange and I'm not entirely sure where to start looking.
When I run rake test:units --trace I can see my environment being setup and it lists the files it intends to execute, but then it just returns.
It does the same thing if I try to run one individual file using something like: rake -I"lib:test" test/unit/foo.rb or using autotest.
It's all very strange. It's as if the files are being loaded but the actual unit tests are not being run.
I'm using shoulda and fast_context and I thought these might be the problem but if I include a unit test using the standard def test_ syntax it still doesn't get run so I don't think it's those.
Any hints or pointers would be greatly appreciated. I feel like I'm coding blind until I can get them working again!
So here's where I am now:
My reasons for using bundler are for installing dependencies on heroku and because I wanted to use a gem sourced from a git repo on github. The long and the short of it is that I've removed the preinitializer for bundler and have gone back to using config.gem. To get around the fact that I can't use a github repo using config.gem I've pushed out my own copy to rubygems. Was this the right move?
Here's the preinitializer.rb
begin
require "rubygems"
require "bundler"
rescue LoadError
raise "Could not load the bundler gem. Install it with `gem install bundler`."
end
if Gem::Version.new(Bundler::VERSION) <= Gem::Version.new("0.9.24")
raise RuntimeError, "Your bundler version is too old for Rails 2.3." +
"Run `gem install bundler` to upgrade."
end
begin
# Set up load paths for all bundled gems
ENV["BUNDLE_GEMFILE"] = File.expand_path("../../Gemfile", __FILE__)
Bundler.setup
rescue Bundler::GemNotFound
raise RuntimeError, "Bundler couldn't find some gems." +
"Did you run `bundle install`?"
end
I don't know how the .gems file would be useful because it's a heroku only thing and I'd have to hunt through git for it, but here's my gemfile.
source :gemcutter
gem 'rails', '2.3.9'
gem 'pg'
gem 'minitest'
gem 'RedCloth'
gem 'erubis'
#gem 'memcached'
gem 'daemons'
gem 'resque'
gem 'inherited_resources', '1.0.6'
gem 'clearance', '0.8.8'
gem 'acl9'
gem 'sprockets'
gem 'aws-s3'
gem 'paperclip', '2.3.1.1'
gem 'rmagick', '2.12.2'
gem 'jonnii-cheddargetter', '0.1.3'
gem 'attribute_normalizer'
gem 'formtastic', '1.1.0.beta'
gem 'will_paginate', '2.3.14'
gem 'hoptoad_notifier'
gem 'mixpanel_client'
gem 'sunspot'
gem 'websolr-sunspot_rails'
gem 'geokit'
gem 'ri_cal'
gem 'jonnii-yelp'
group :development, :test do
gem 'test-spec'
gem 'shoulda'
gem 'redgreen'
gem 'factory_girl'
gem 'populator'
gem 'faker'
gem 'ZenTest'
gem 'autotest-rails'
gem 'webrat'
gem 'cucumber'
gem 'cucumber-rails'
gem 'database_cleaner'
gem 'parallel'
gem 'hydra'
gem 'heroku'
gem 'taps'
gem 'ruby-prof'
gem 'treetop'
gem 'rspec'
gem 'rspec-rails'
end
Got the same problem.Just remove the gem 'hydra' will get the unit test back to normal
Do you have this at the end of your config/boot.rb file:
class Rails::Boot
def run
load_initializer
Rails::Initializer.class_eval do
def load_gems
#bundler_loaded ||= Bundler.require :default, Rails.env
end
end
Rails::Initializer.run(:set_load_path)
end
end
(from http://gembundler.com/rails23.html)
I recently had trouble running specs for a project. The reason was that I was missing a line from config/application.rb. Nowadays that line pops in by default when you create a new rails 3 project, but if your project has been initialized some time ago it might be missing.
# If you have a Gemfile, require the gems listed there, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env) if defined?(Bundler)