The following is my environment:
OS X 10.5
Xcode 3.1.4
rvm 0.1.38
ruby 1.8.9-p399 (via rvm)
rails 2.3.8
I started getting this error when rake tries to run my tests:
bash$ rake
Virtual timer expired
bash$ # End of output!
And with tracing enabled:
bash$ rake --trace
** Invoke default (first_time)
** Invoke test (first_time)
** Execute test
** Invoke test:units (first_time)
** Invoke db:test:prepare (first_time)
** Invoke db:abort_if_pending_migrations (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:abort_if_pending_migrations
** Execute db:test:prepare
** Invoke db:test:load (first_time)
** Invoke db:test:purge (first_time)
** Invoke environment
** Execute db:test:purge
** Execute db:test:load
** Invoke db:schema:load (first_time)
** Invoke environment
** Execute db:schema:load
Virtual timer expired
bash$
It looks like there is an problem in ruby, rev23993 causes Virtual Timer Expired when forking, which in turn triggers the error inside the mysql gem.
The practical workaround seems to be to downgrade the mysql gem from 2.8.1
to version 2.7:
#environment.rb
config.gem 'mysql', :version => '2.7'
Related
I've been trying to set up a test db, but when trying to create, I keep coming across an error that I can't seem to get past when trying to populate the db.
When I execute:
bundle exec rake db:create db:migrate db:test:prepare --trace
create and migrate seem to run without errors when run separately, but test:prepare seems to throw the error.
The error starts with:
** Invoke db:test:prepare (first_time)
** Invoke db:abort_if_pending_migrations (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:abort_if_pending_migrations
** Invoke environment
** Execute db:test:prepare
** Invoke db:test:load (first_time)
** Invoke db:test:purge (first_time)
** Invoke environment
** Invoke db:load_config
** Execute db:test:purge
** Execute db:test:load
** Invoke db:test:load_schema (first_time)
** Invoke db:test:purge
** Execute db:test:load_schema
** Invoke db:schema:load (first_time)
** Invoke environment
** Invoke db:load_config
** Execute db:schema:load
rake aborted!
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation "capabilities" does not exist
LINE 5:
I've looked up, and tried a lot of the results shown on google, but none seem to help. New to this, so I'm completely stumped at this stage.
UPDATE:
I should mention that when doing:
rake db:create RAILS_ENV=test
->payments_test already exists
rake db:migrate RAILS_ENV=test
->rake aborted!
NoMethodError: undefined method `mq' for #<Rails::Application::Configuration:0x0000000508acf0> blah blah blah
I've recently extracted a module to a Rails::Engine gem that contains a "dummy application" for running the tests on. rake spec now behaves differently, and is causing some specs to fail.
First, running rake spec --trace in the gem directory no longer causes this long invocation chain:
** Invoke spec (first_time)
** Invoke test:prepare (first_time)
** Invoke db:test:prepare (first_time)
** Invoke db:abort_if_pending_migrations (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:abort_if_pending_migrations
** Execute db:test:prepare
** Invoke db:test:load (first_time)
** Invoke db:test:purge (first_time)
** Invoke environment
** Invoke db:load_config
** Execute db:test:purge
** Execute db:test:load
** Invoke db:test:load_schema (first_time)
** Invoke db:test:purge
** Execute db:test:load_schema
** Invoke db:schema:load (first_time)
** Invoke environment
** Invoke db:load_config
** Execute db:schema:load
** Execute test:prepare
** Execute spec
Instead just calling:
** Invoke spec (first_time)
** Execute spec
I don't see any code in RSpec::Core::RakeTask that does DB initialization, so this must be a Rails function added by the Rakefile in a Rails root directory.
I considered dealing with that by adding this:
task :my_spec do
ENV['RAILS_ENV'] = 'test'
Rake::Task['db:drop'].invoke
Rake::Task['db:create'].invoke
ENV['SCHEMA'] = '/Users/me/sandbox/my_app/db/schema.rb'
Rake::Task['db:schema:load'].invoke
Rake::Task['spec'].invoke
end
But none of these tasks are loaded by the Rakefile in the gem's root.
How can I get rake spec to initialize the test DB from this directory?
Second, rspec is no longer clearing the DB in between tests, so tests that relied on a pristine DB state are now failing. Perhaps this means I'm writing my tests wrong, but I have considered the "blank slate" idea for tests to be a helpful one when understand test output.
How can I get rake spec to clear the DB in between tests as it does for a normal Rails app?
I am using FactoryGirl in my rails application instead of Fixtures.
When i try to use factory girl in my test and create some test data, it shows like
PG:Error relation "users" doesn't exists (i have a model named User)
But when i run rake db:test:clone, and then run the test, the test is passed. The rake db:test:clone command clones all the table structure from development db to test db, and this fixes the issue.
But is there any way for me to not to run rake db:test:clone when using FactoryGirl?
or what am i missing?
Update :
I found out one other thing, i have another application which uses Rspec and FactoryGirl. In that application below are executed when running rake spec --trace command
** Invoke spec (first_time)
** Invoke db:test:clone_structure (first_time)
** Invoke db:structure:dump (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:structure:dump
** Invoke db:test:load_structure (first_time)
** Invoke db:test:purge (first_time)
** Invoke environment
** Invoke db:load_config
** Execute db:test:purge
** Execute db:test:load_structure
** Invoke db:structure:load (first_time)
** Invoke environment
** Invoke db:load_config
** Execute db:structure:load
But in any of the new application i see the below executed when running rake spec --trace
** Invoke spec (first_time)
** Invoke noop (first_time)
** Execute noop
** Execute spec
Please suggest what am i missing?
regards
Balan
Every time you run a db:migrate, run a db:test:prepare as well, so the database changes are mirrored on your test database as well.
I found the solution, we need to create a rake task customrake.rake under /lib/tasks
and add the line task :spec => 'db:test:prepare', this will make sure rake db:test:prepare is executed before running Specs.
I am running the following comand on my mac os x shell:
RAILS_ENV=test rake spec --trace
** Invoke spec (first_time)
** Invoke db:test:prepare (first_time)
** Invoke db:abort_if_pending_migrations (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:abort_if_pending_migrations
** Execute db:test:prepare
** Invoke db:test:clone_structure (first_time)
** Invoke db:structure:dump (first_time)
** Invoke environment
** Execute db:structure:dump
** Invoke db:test:purge (first_time)
** Invoke environment
** Execute db:test:purge
** Execute db:test:clone_structure
** Execute spec
This command stops here for more than 5 minutes before continuing, so I don't know what is happening to cause this big big delay.
Any ideas on how can I find what is slowing down "Execute spec" ?
Thanks
I've push my app to Heroku however my database(Sqlite3) fails to migrate. I understand that heroku will automatically migrate as a PG. [ I don't have PG install].
I figured if something was wrong, I would of received an error prompt.
This is my result:
pc-name$ heroku rake db:migrate --trace
(in /app)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
** Invoke db:schema:dump (first_time)
** Invoke environment
** Execute db:schema:dump
Also when I try to create-
pc-name$ heroku rake db:create --trace
cwogwtvrpc already exists
(in /app)
** Invoke db:create (first_time)
** Invoke db:load_config (first_time)
** Invoke rails_env (first_time)
** Execute rails_env
** Execute db:load_config
** Execute db:create
Try destroying the app and creating it again :)