heroku run rake > no such file to load -- faker - ruby-on-rails

When running 'heroku run rake' I get this error:
no such file to load -- faker
/app/lib/tasks/sample_data.rake:1:in `require'
/app/lib/tasks/sample_data.rake:1:in `<top (required)>'
I have gem 'faker', '0.3.1' under group :development, :test do in Gemfile.
I have require 'faker' in sample_data.rake
source 'https://rubygems.org'
gem 'rails', '3.2.11'
gem 'gravatar_image_tag', '0.1.0'
group :development, :test do
gem 'sqlite3', '1.3.5'
gem 'rspec-rails', '2.8'
gem 'guard-spork', '1.2.0'
gem 'faker', '0.3.1'
gem 'spork', '0.8.4'
gem 'will_paginate', '3.0'
gem 'webrat', '0.7.1'
gem 'capybara', '1.1.2'
gem 'annotate', '2.5.0'
gem 'factory_girl_rails', '1.0'
end
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '3.2.5'
gem 'coffee-rails', '3.2.2'
gem 'uglifier', '1.2.3'
end
gem 'jquery-rails', '2.0.2'
group :production do
gem 'pg', '0.12.2'
end

Heroku does not install test or development gems by default.
If you want to load fake in your production, you should remove gem 'faker', '0.3.1' from the group :development, :test do and place it outside any group:
source 'https://rubygems.org'
gem 'rails', '3.2.11'
gem 'gravatar_image_tag', '0.1.0'
gem 'faker', '0.3.1'
group :development, :test do
gem 'sqlite3', '1.3.5'
...
However, if you don't want to load fake, you must ensure that your require fake will be required only when the task is invoked:
task :sample_data => :environment do
require 'faker' #must be inside the task.
...
end
Hope it helps.
EDIT
You can tell Bundler to not load the Gem by:
gem 'faker', '0.3.1', :require => false

I got this issue with the "Rub on Rails 3 Tutorial".
Per gabrielhilals answer, the fix was to move require 'faker' to inside the task
before fix:
require 'faker'
namespace :db do
desc "Fill database with sample data"
task :populate => :environment do
...
...
end
end
after fix:
namespace :db do
require 'faker'
desc "Fill database with sample data"
task :populate => :environment do
...
...
end
end

Related

Having errors with rake db:create

I'm trying to install fat free crm with ruby on rails on Windows 7, but when I put the command
rake db:create RAILS_ENV=production
it says
rake aborted!
LoadError: cannot load such -- 2.1/pg_ext
Normally, it would say what gem I should install, but not in this case.
How can I solve this error?
Edit:
A friend of mine suggested to uncomment mysql2 and comment pg on the Gemfile file in the proyect like this:
gem 'mysql2'
#gem 'sqlite3'
#gem 'pg'
But now I get this:
Unable to load the EventMachine C extension; To use the pure-ruby reactor, requi
re 'em/pure_ruby'
C:/Ruby21/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require': ca
nnot load such file -- 2.1/rubyeventmachine (LoadError)
Have any ideas of why this happends?
Here is my Gemfile:
source 'https://rubygems.org'
# Uncomment the database that you have configured in config/database.yml
# ----------------------------------------------------------------------
gem 'mysql2'
# gem 'sqlite3'
# gem 'pg'
# Removes a gem dependency
def remove(name)
#dependencies.reject! {|d| d.name == name }
end
# Replaces an existing gem dependency (e.g. from gemspec) with an alternate source.
def gem(name, *args)
remove(name)
super
end
# Bundler no longer treats runtime dependencies as base dependencies.
# The following code restores this behaviour.
# (See https://github.com/carlhuda/bundler/issues/1041)
spec = Bundler.load_gemspec( File.expand_path("../fat_free_crm.gemspec", __FILE__) )
spec.runtime_dependencies.each do |dep|
gem dep.name, *(dep.requirement.as_list)
end
# Remove premailer auto-require
gem 'premailer', :require => false
# Remove fat_free_crm dependency, to stop it from being auto-required too early.
remove 'fat_free_crm'
group :development do
# don't load these gems in travis
unless ENV["CI"]
gem 'thin'
gem 'quiet_assets'
gem 'capistrano'
gem 'capistrano-bundler'
gem 'capistrano-rails'
gem 'capistrano-rvm'
#~ gem 'capistrano-chruby'
#~ gem 'capistrano-rbenv'
gem 'guard'
gem 'guard-rspec'
gem 'guard-rails'
gem 'rb-inotify', :require => false
gem 'rb-fsevent', :require => false
gem 'rb-fchange', :require => false
end
end
group :development, :test do
gem 'rspec-rails', '~> 2'
gem 'headless'
gem 'debugger', :platforms => 'mri_19' unless ENV["CI"]
gem 'byebug', :platforms => ['mri_20', 'mri_21'] unless ENV["CI"]
gem 'pry-rails' unless ENV["CI"]
end
group :test do
gem 'capybara'
gem 'selenium-webdriver'
gem 'database_cleaner'
gem "acts_as_fu"
gem 'factory_girl_rails'
gem 'zeus' unless ENV["CI"]
gem 'coveralls', :require => false
gem 'timecop'
end
group :heroku do
gem 'unicorn', :platform => :ruby
gem 'rails_12factor'
end
# 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'
gem 'uglifier', '>= 1.0.3'
gem 'execjs'
gem 'therubyracer', :platform => :ruby unless ENV["CI"]
end
gem 'turbo-sprockets-rails3'
It sounds like you are missing the pg gem from your Gemfile. Is it in the development group?
Can you post your Gemfile?
Uncomment #gem pg.
Unable to load the EventMachine C extension; To use the pure-ruby reactor, require 'em/pure_ruby' is a separate error. Where did you get that Gemfile?

Don't know how to build task - Cucumber

In cucumber, my seed data is loaded up via several rake tasks. None of which are working:
Spree::Core::Engine.load_seed if defined?(Spree::Core)
Spree::Auth::Engine.load_seed if defined?(Spree::Auth)
Rake::Task['alchemy:db:seed'].invoke
When I run one of spree's rake tasks I get:
Don't know how to build task 'db:load_dir' (RuntimeError)
When I run one of alchemy's rake tasks I get:
Don't know how to build task 'alchemy:db:seed' (RuntimeError)
The testing database exists. I have ran rake db:test:prepare and it appears to be setup from my inspections. Lets move onto the hooks:
# features/support/hooks.rb
Before do
load File.join(Rails.root, 'db', 'seeds.rb')
end
This goes to the root and gets me the seed data. I decided to try this:
# features/support/hooks.rb
before do
# load File.join(Rails.root, 'db', 'seeds.rb')
Rake::Task['alchemy:db:seed'].invoke
end
The error was:
Don't know how to build task 'alchemy:db:seed' (RuntimeError)
I'm unable to figure out why the rake tasks are not working in cucumber.
My Gemfile is as follows:
source 'https://rubygems.org'
ruby '2.1.2'
gem 'rails', '4.0.6'
gem 'pg'
gem 'redis-rails'
gem 'redis-rack-cache'
gem 'sass-rails', '~> 4.0.3'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'thin'
gem 'durable_decorator_rails', github: 'jumph4x/durable_decorator_rails'
gem 'newrelic_rpm'
gem 'rake'
gem 'spree', '2.2.2'
gem 'spree_gateway', github: 'spree/spree_gateway', branch: '2-2-stable'
gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: '2-2-stable'
gem 'spree_bootstrap_frontend', github: '200Creative/spree_bootstrap_frontend', branch: '2-2-stable'
gem 'alchemy_cms', github: 'magiclabs/alchemy_cms'
gem 'spree_alchemy', github: 'tesserakt/spree_alchemy'
group :doc do
gem 'sdoc', '~> 0.4.0'
end
group :development do
gem 'better_errors'
gem 'binding_of_caller'
gem 'meta_request'
end
group :test do
gem 'simplecov', require: false
gem 'cucumber-rails', require: false
gem "cucumber-websteps"
gem 'database_cleaner'
gem "selenium-webdriver"
gem "capybara-webkit"
end
group :development, :test do
gem "factory_girl_rails", "~> 4.0"
gem "rspec-rails"
gem 'rspec-its'
gem 'shoulda-matchers', require: false
end
And this is my env support file:
# features/support/env.rb
require 'cucumber/rails'
ActionController::Base.allow_rescue = false
begin
DatabaseCleaner.strategy = :transaction
rescue NameError
raise 'You need to add database_cleaner to your' \
'Gemfile (in the :test group) if you wish to use it.'
end
Cucumber::Rails::Database.javascript_strategy = :truncation
Capybara.register_driver :chrome do |app|
Capybara::Selenium::Driver.new(app, browser: :chrome)
end
Capybara.javascript_driver = :chrome
Rake doesn't load tasks by default, you can check for yourself:
irb(main):002:0> require 'rake'
=> true
irb(main):003:0> Rake::Task.tasks
=> []
So it doesn't "know" how to run your task. You need to tell Rails to load them:
Rails.application.load_tasks
Spree::Core::Engine.load_seed if defined?(Spree::Core)
Spree::Auth::Engine.load_seed if defined?(Spree::Auth)
It seems that the test database is missing. So as already written in the comment above, the solution is to create the database and run the migrations with
RAILS_ENV=test rake db:setup
Happy to help :)

Updated Rails test suite set up?

Anyone know of a more up-to-date version of a Rails Rspec/Guard/Spork/Growl test suite set up?
These used to be great, but have become outdated as Ruby, Rails and the gems upgraded.
http://ygamretuta.me/2011/08/10/rails-3-setting-up-guard-with-rspec-and-spork-with-growl-notifications-in-osx/
https://eq8scrapbook.heroku.com/equivalents_scrap/on_rspec_spork_guard_configuration
Even the M. Hartl Ruby on Rails Tutorial instructions results in Guard tossing up a ChildProcess error and doesn't load the DRb server.
Here's what I've found to fix my problem above:
rails new app_name --skip-test-framework
Gemfile
source 'https://rubygems.org'
gem 'rails', '3.2.12'
gem 'bootstrap-sass', '2.1'
gem 'bcrypt-ruby', '3.0.1'
gem 'faker', '1.0.1'
gem 'will_paginate', '3.0.3'
gem 'bootstrap-will_paginate', '0.0.6'
gem 'jquery-rails', '2.0.2'
group :development, :test do
gem 'sqlite3', '1.3.5'
gem 'rspec-rails', '2.11.0'
gem 'rspec', '2.11.0'
gem 'guard', '1.6.2'
gem 'guard-rspec', '1.2.1'
gem 'guard-spork', '1.4.2'
gem 'spork-rails', '3.2.1'
gem 'spork', '1.0.0rc3'
end
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '3.2.5'
gem 'coffee-rails', '3.2.2'
gem 'uglifier', '1.2.3'
end
group :test do
gem 'capybara', '1.1.2'
gem 'factory_girl_rails', '4.1.0'
gem 'database_cleaner', '0.7.0'
gem 'launchy', '2.1.0'
gem 'rb-fsevent', :require => false
gem 'growl', '1.0.3'
end
group :production do
gem 'pg', '0.12.2'
end
Then run this:
bundle update; bundle install; rails g rspec:install; guard init rspec; guard init spork; spork --bootstrap
Guardfile
Put the boostrapped spork block before the rspec block
spec_helper.rb
Put the block starting with "ENV["RAILS_ENV"] ||= 'test'" inside the Spork.prefork block
.rspec
add --drb
Run 'guard' and you should be all set.

Capybara + Rspec + :webkit = undefined javascript_driver

I want to change my default drive for running tests with javascript, specific scenario with javascript, from default, :selenium, to any, like :webkit, in RSpec, just setting :js => true flag. But, trying to runing "describe 'xxx', :js => true do" with :webkit, and loading javascript_driver in rspec_helper, thats what happened "Undefined method javascript_driver for Capybara:Module"
undefined method `javascript_driver=' for Capybara:Module (NoMethodError)
how I defined loader :webkit in file spec_helper.rb:
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
Capybara.javascript_driver = :webkit
Version of Capybara is 1.1.2
Gem File:
source 'https://rubygems.org'
gem 'rails', '3.2.5'
gem 'pg', '0.12.2'
gem "meta_search"
# Bootstrap and layouting
gem 'bootstrap-sass', '2.0.3'
gem 'will_paginate', '3.0.3'
gem 'bootstrap-will_paginate', '0.0.6'
gem 'rails3-jquery-autocomplete'
#test support
gem 'faker', '1.0.1'
#login rules
gem 'devise'
gem 'cancan'
#criptar
gem 'bcrypt-ruby', '3.0.1'
#BR
gem 'brazilian-rails'
gem 'rails-i18n'
group :development do
gem 'annotate', '~> 2.4.1.beta'
gem 'nested_scaffold'
end
group :development, :test do
gem 'rspec-rails', '2.11.0'
gem 'guard-rspec', '0.5.5'
gem 'guard-spork', '0.3.2'
gem 'spork', '0.9.0'
gem 'ruby-debug19'
gem 'linecache19'
gem 'factory_girl_rails', '1.4.0'
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 'capybara', '1.1.2'
gem 'capybara-webkit'
gem "launchy"
gem 'ZenTest'
#MAC OS Especific
gem 'rb-fsevent', '0.4.3.1', :require => false
gem 'growl', '1.0.3'
#Cucumber
gem 'cucumber-rails', '1.2.1', require: false
gem 'database_cleaner', '0.7.0'
end
group :production do
#gem 'pg', '0.12.2'
end
Thanks for you advanced.
missing this on spec_helper.rb
require "capybara/rspec"
Thanks https://github.com/jnicklas

deploying devise/omniauth on heroku

When running:
heroku run rake db:migrate
I am returned the error:
Running `rake db:migrate` attached to terminal... up, run.1
rake aborted!
no such file to load -- devise
This is the error I see with a "require 'devise'" line in the top of my application.rb file. Previously (without this line), I was being returned a different error when running heroku run rake db:migrate saying "uninitialized constant Devise".
My app is working fine locally. I can't seem to find anyone else with the same problem, so any leads would be appreciated!
(edit): adding Gemfile:
source 'https://rubygems.org'
gem 'rails', '3.2.3'
gem 'bootstrap-sass', '2.0.0'
group :development do
gem 'sqlite3', '1.3.5'
gem 'rspec-rails', '2.9.0'
gem 'guard-rspec', '0.5.5'
gem 'devise'
gem 'omniauth-linkedin'
gem 'nifty-generators', :group => :development
gem 'debugger'
gem 'linkedin', :git => "git://github.com/pengwynn/linkedin.git"
end
group :assets do
gem 'sass-rails', '3.2.4'
gem 'coffee-rails', '3.2.2'
gem 'uglifier', '1.2.3'
gem 'jquery-rails'#, '2.0.0'
end
group :test do
gem 'rspec-rails', '2.9.0'
gem 'capybara', '1.1.2'
gem 'rb-fsevent', '0.4.3.1', :require => false
gem 'growl', '1.0.3'
gem 'guard-spork', '0.3.2'
gem 'spork', '0.9.0'
end
group :production do
gem 'pg', '0.12.2'
end
gem "mocha", :group => :test
The problem is: Heroku compiles your gem file without development or test groups.
to fix it just take what you need from here:
group :development do
gem 'sqlite3', '1.3.5'
gem 'rspec-rails', '2.9.0'
gem 'guard-rspec', '0.5.5'
gem 'devise'
gem 'omniauth-linkedin'
gem 'nifty-generators', :group => :development
gem 'debugger'
gem 'linkedin', :git => "git://github.com/pengwynn/linkedin.git"
end
and move it to anywhere outside groups of development or test, like this:
group :development do
gem 'sqlite3', '1.3.5'
gem 'rspec-rails', '2.9.0'
gem 'guard-rspec', '0.5.5'
gem 'omniauth-linkedin'
gem 'nifty-generators', :group => :development
gem 'debugger'
gem 'linkedin', :git => "git://github.com/pengwynn/linkedin.git"
end
gem 'devise'

Resources