When I Ran 'Bundle Exec Rake Test:Prepare' It Errored Out, But 'Bundle Exec Rake Db:Test:Prepare' Goes Through Fine with Warning. What's Going On

Rails: rake db:test:prepare Vs rake test:prepare

According to github and the source code task 'test:prepare' => 'db:test:prepare' is mentioned at the bottom.

Hence it's a shortcut, wrapper, whatever you want to call it. Another question would be why this doesn't up when you do bundle exec rake -T but hey.

LoadError when called rake task with RAILS_ENV=test

The issue is with the Gemfile and the grouping of certain gems to also load in development environment. If they're testing gems, keep them in group :test unless absolutely necessary to move them to development, like factory_gril_rails in example. So having,

group :test do
gem 'rspec'
gem 'rspec-rails', '~> 3.0.0.beta'
...

instead of:

group :development, :test do 
gem 'rspec'
...

worked for me on my machine cloning your project. Hope this helps, give it a try.

p.s: there is also an old issue reported earlier here.

Also, I think you'll not have to require factory_girl_rails in you Gemfile like:

gem 'factory_girl_rails', require: false 

And then require it in your spec_helper:

require 'factory_girl_rails'

This way you're using this gem but you don't need to require it in other places than spec_helper.rb

Cucumber spec can't see column added by latest migration

rake db:migrate
rake db:test:prepare

The test environment does not use the same database used in development. You have to run the command rake db:test:prepare to recreate it after every migration you make that actually changes the database structure.

That command simply creates the test database based on the schema.rb file (or the structure.sql, it depends on the project's configurations), that are created/updated when you run a migration.

Check the info from the rails guides

Error when trying to run rspec: `require': cannot load such file -- rails_helper (LoadError)

There is some problem with rspec V3. But in your case you are using V2.

change

require 'rails_helper'

to

require 'spec_helper'

Other description find here https://teamtreehouse.com/forum/problem-with-rspec

For V3 :

If someone using rspec V3 then similar error occurs when generator not run. So before trying anything run generator.

rails generate rspec:install

If you are getting a huge list of warning on your console. Then you need to remove --warnings from .rspec file.

Why am I asked to run 'rake db:migrate RAILS_ENV=test'?

As of Rails 4.1, the rake db:test:* tasks are deprecated. Instead, your (test|spec)_helper.rb should include:

ActiveRecord::Migration.maintain_test_schema!

This means that your test database will get the correct schema every time your tests run, whether you run them from a Rake task or not.

Rails 4 - rspec test dont pass for Polymorphic Association

The addressable_id column is not in your test database. Run:

bundle exec rake db:test:clone

to sync your database changes to your test database.



Related Topics



Leave a reply



Submit