Rail3 rake test task not running tests - ruby-on-rails

I have a very similar problem to Mr. Limpens, with one major different: I do include the test_unit railtie into my application.rb.
From my application.rb:
require File.expand_path('../boot', __FILE__)
# Pick the frameworks you want:
require 'action_controller/railtie'
require 'dm-rails/railtie'
# require 'action_mailer/railtie'
# require 'active_resource/railtie'
require 'rails/test_unit/railtie'
# 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)
You'll note that I am using DataMapper and initialized my project with the dm-rails bootstrap. I may run my tests manually, like so:
$ ruby -Itest test/unit/test_habit.rb
Loaded suite test/unit/test_habit
Started
.....
Finished in 2.554523 seconds.
5 tests, 7 assertions, 0 failures, 0 errors, 0 skips
Test run options: --seed 15947
but when executing the rake test task no tests are run, like so:
$ rake test --trace
(in /home/blt/Documents/projects/rails3apps/naughtyapp)
** Invoke test (first_time)
** Execute test
** Invoke test:units (first_time)
** Invoke test:prepare (first_time)
** Execute test:prepare
** Execute test:units
** Invoke test:functionals (first_time)
** Invoke test:prepare
** Execute test:functionals
** Invoke test:integration (first_time)
** Invoke test:prepare
** Execute test:integration
Each run 'first_time' is displayed in parenthesis. What must I be doing wrong that my tests don't run?

I think that the rake test tasks are searching for test files matching names like test/unit/**/*_test.rb. So you may just need to change the filename test_habit.rb to habit_test.rb.

Related

Rails activestorage does not create migration files

I make an image-upload for a user profile using the activestorage gem built into rails, but it is not working, the intriguing part is that there are no errors, the migration just does not get created.
What is wrong here, any ideas on how I can fix this?
rails version - 6.0
I added require 'active_storage/engine' to the config/application.rb file already
And then ran rails active_storage:install
What is even more intriguing is that I get the same output without adding the require active_storage/engine to application.rb. And there are no errors
output
** Invoke active_storage:install (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute active_storage:install
** Invoke active_storage:install:migrations (first_time)
** Execute active_storage:install:migrations
** Invoke railties:install:migrations (first_time)
** Invoke db:load_config (first_time)
** Invoke environment
** Execute db:load_config
** Execute railties:install:migrations```
I expect the migration file to be created after this but it is not.

Rake doesn't know how to build task 'db:migrate'

I've created an app using Ruby on Rails and Spree.
After changing my SQlite database to PostgreSQL I needed to migrate my database.
But when I try to run rake db:migrate, rake db:migrate RAILS_ENV=development, bin/rake db:migrate RAILS_ENV=development I get the same error.
rake aborted!
Don't know how to build task 'db:migrate:up' (see --tasks)
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-12.3.0/exe/rake:27:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `eval'
/usr/local/rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `<main>'
(See full trace by running task with --trace)
When I run --trace I get the following response
** Invoke default (first_time)
** Invoke spec (first_time)
** Execute spec
/usr/local/rvm/rubies/ruby-2.3.0/bin/ruby -I/usr/local/rvm/gems/ruby-2.3.0/gems/rspec-core-3.7.0/lib:/usr/local/rvm/gems/ruby-2.3.0/gems/rspec-support-3.7.0/lib /usr/local/rvm/gems/ruby-2.3.0/gems/rspec-core-3.7.0/exe/rspec --pattern spec/\*\*\{,/\*/\*\*\}/\*_spec.rb
Could not load dummy application. Please ensure you have run `bundle exec rake test_app`
** Execute default
Does any of you know what the cause of the problem is and what I should do?
Rakefile
require 'rubygems'
require 'rake'
require 'rake/testtask'
require 'rspec/core/rake_task'
require 'spree/testing_support/common_rake'
RSpec::Core::RakeTask.new
task default: :spec
desc "Generates a dummy app for testing"
task :test_app do
ENV['LIB_NAME'] = 'spree/frontend'
Rake::Task['common:test_app'].invoke
end
I added,
require File.expand_path('../config/application', __FILE__)
and
YouApp::Application.load_tasks
to my rake file.
Credits go to #nattfodd

Manifest.yml empty

Whenever I run rake assets:precompile, I get a manifest.yml file that looks like:
--- {}
Something must be going wrong. Here is my output for rake assets:precompile --trace:
** Invoke assets:precompile (first_time)
** Execute assets:precompile
/Users/user/.rvm/rubies/ruby-1.9.3-p194/bin/ruby /Users/user/.rvm/gems/ruby-1.9.3-p194#global/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets --trace
** Invoke assets:precompile:all (first_time)
** Execute assets:precompile:all
** Invoke assets:precompile:primary (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:precompile:primary
** Invoke assets:precompile:nondigest (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:precompile:nondigest
Can someone help?? Thanks!
UPDATE:
Feel free to look at my code at www.github.com/sambaek/novulty
When I run rake assets:precompile for your application I get the following output
➜ novulty git:(master) ✗ rake assets:precompile
/Users/deefour/.rbenv/versions/1.9.3-p125/bin/ruby /Users/deefour/.rbenv/versions/1.9.3-p125/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
rake aborted!
Undefined variable: "$baseLineHeight".
(in /Users/deefour/.rbenv/versions/1.9.3-p125/gemsets/novulty/gems/bootstrap-sass-2.1.0.1/vendor/assets/stylesheets/bootstrap/_accordion.scss)
Tasks: TOP => assets:precompile:primary
(See full trace by running task with --trace)
rake aborted!
Command failed with status (1): [/Users/deefour/.rbenv/versions/1.9.3-p125/...]
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
rake assets:precompile 12.50s user 1.21s system 99% cpu 13.744 total
I'm not sure what your intention is, but you have
app/asssets/bootstrap.min.css being included in app/assets/application.css
gem 'bootstrap-sass' in your Gemfile which appears to cause bootstrap-sass-2.1.0.1/vendor/assets/stylesheets/bootstrap/_accordion.scss (among other files) to be added to your pipeline even though they're not included in require lines in app/assets/application.css
It seems like you have the bootstrap gem included to use it's Javascript plugins, but are trying to omit the SASS files in favor of the hard-coded, minified CSS file?
In any event, the error I get says that the $baseLineHeight SASS variable is not defined for a line in that gem file's asset - an asset you otherwise appear to ignore (from the best I can tell).
I then did the following
Commented out the bootstrap-sass gem in your Gemfile
#gem 'bootstrap-sass'
Ran bundle
Ran rake assets:clean
Removed the following require lines from your app/assets/application.js because they were coming from the bootstrap-sass gem I removed in 1. above
//= require bootstrap-transition
//= require bootstrap-button
//= require bootstrap-carousel
//= require bootstrap-collapse
//= require bootstrap-tab
Ran rake assets:precompile
This results in the following public/assets/manifest.yml.
https://gist.github.com/d29f70b047c7b0606263
I think you need to either of the following
Use the bootstrap-sass gem as intended. Include the SASS files in your app/assets/application.css (doing this it a bit outside the scope of this question)
Get rid of the bootstrap-sass gem as I have above, and include the necessary Javascript files as assets in your vendor/assets/javascripts directory (which is where app/assets/stylesheets/bootstrap.min.css belongs too - vendor/assets/stylesheets)

Run Rails Tests without Dropping Test Database

Just wondering if there's a way to run Rails tests without dropping the database. I'm currently only executing unit tests and am using the following rake command to do so: rake test:units.
Thanks for the help in advance!
Just in case this is relevant:
Rails 3
Ruby 1.8.7 (MRI)
Oracle 11g Database
activerecord-oracle_enhanced-adapter
In Rails 5 (and possibly earlier versions), just comment-out the following line in spec/rails_helper.rb:
ActiveRecord::Migration.maintain_test_schema!
This will prevent rake test or rspec from attempting to drop your test DB. You'll need to run migrations manually as well.
For Rails 5.2 this behaviour can be modified setting maintain_test_schema to false in test/test_helper.rb before importing rails/test_help:
ActiveRecord::Base.maintain_test_schema = false
require "rails/test_help"
rails/test_help will check the value of maintain_test_schema to decide if it has to drop/create/migrate the test database or not.
After doing some research, I have found that there isn't a way to do this. The test rake tasks will always drop the database, even when providing the TEST= option as Bohdan suggests.
By using the --trace option, this can be proven. Here is the output:
$ rake test:units TEST=test/unit/post_test.rb --trace
(in /Users/johnnyicon/Development/ror/test-app)
** Invoke test:units (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
** 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
** Execute test:prepare
** Execute test:units
Reading through the Ruby on Rails Guides for Testing, it describes what some of these rake tasks mean. The one to pay particular attention to is the db:test:load task, which you see on the 7th line from the bottom of the output as ** Execute db:test:load. The guides say the following about this task:
Recreate the test database from the
current schema.rb
So even if I were to execute the unit tests one by one as Bohdan suggests, the rake task would still recreate the database. Not the answer I was hoping for, but it isn't a problem anymore.
The reason I was asking to begin with was because I did not have access to another database to use for testing, so I was using my development database for testing as well. But since then, I've been able to get another database dedicated for testing.
Thanks anyway Bohdan! I appreciate the help!
This is a rather old post that does the monkey patching of overriding purge/load tasks:
http://www.pervasivecode.com/blog/2007/09/22/making-rails-raketest-not-drop-your-pgsql-database/
For those looking for a way to skip Rails' default behavior, try adding this to your Rakefile:
Rake::Task["db:test:prepare"].clear
Rake::Task["db:test:load"].clear
Rake::Task["db:test:purge"].clear
Could you not write a custom Rake task that monkey patched the Rake db:test:load task to do nothing?

RSpec sees xits but no other tests?

So, whenever I run "rake spec" in my application directory, I see this:
admin#nurvus:~/workspace/spec $ rake spec
(in /Users/admin/workspace/)
DEPRECATION WARNING: Rake tasks in vendor/plugins/abingo/tasks, vendor/plugins/delayed_job/tasks, vendor/plugins/funkytown/tasks, vendor/plugins/funkytown/tasks, vendor/plugins/git_helper/tasks, vendor/plugins/git_helper/tasks, and vendor/plugins/jrails/tasks are deprecated. Use lib/tasks instead. (called from /.rvm/gems/ruby-1.8.7-p299/gems/rails-2.3.8/lib/tasks/rails.rb:10)
** 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: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
** Execute spec
No server is running
Running specs locally:
DEPRECATION WARNING: require "activesupport" is deprecated and will be removed in Rails 3. Use require "active_support" instead. (called from /.rvm/gems/ruby-1.8.7-p299/gems/activesupport-2.3.8/lib/activesupport.rb:2)
DEPRECATION WARNING: require "activerecord" is deprecated and will be removed in Rails 3. Use require "active_record" instead. (called from /.rvm/gems/ruby-1.8.7-p299/gems/activerecord-2.3.8/lib/activerecord.rb:2)
Example disabled: should return the next ordered survey
Example disabled: should not redirect unsupported browser
admin#nurvus:~/workspace/spec $
There are over 2500 tests that just aren't getting run, but it's obviously parsing the files, since the disabled examples are being seen. Any top-level thoughts on this?

Resources