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
Related
I am trying to setup a Rake Task (without rails), and thus created a demo Hello World Task. However, upon running rake -T or rake --tasks nothing is returned, as if the task hasn't been identified. What am I doing wrong here?
Also When I run rake hello_world I get the following error:
➜ ~/GitHub/Cerner/test git:(master) ✗ rake hello_world
rake aborted!
Don't know how to build task 'hello_world' (See the list of available tasks with `rake --tasks`)
/usr/share/rvm/gems/ruby-2.6.6/gems/rake-13.0.6/exe/rake:27:in `<top (required)>'
/home/hsbagga28/gems/bin/ruby_executable_hooks:22:in `eval'
/home/hsbagga28/gems/bin/ruby_executable_hooks:22:in `<main>'
(See full trace by running task with --trace)
[Update] The rakefile:
# frozen_string_literal: true
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
$LOAD_PATH.push File.expand_path('lib', __dir__)
I am trying to connect to mysql and using command rake db:create
. It is showing me error
rake aborted! No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb, Rakefile.rb) /Library/Ruby/Gems/2.0.0/gems/rake-11.3.0/exe/rake:27:in `<top (required)>' (See full trace by running task with --trace)
I also tried rake db:migrate as well but same error.
It looks like your missing a rake file. Add this code in a file called Rakefile at the root of your app.
Edit: Replace YourApp by the name of your app
require File.expand_path('../config/application', __FILE__)
YourApp::Application.load_tasks
I created a Rails 4 app recently and for some reason my rake tasks don't include test. Here's some console action to demonstrate the problem:
> rake test:units
rake aborted!
Don't know how to build task 'test:units'
/Users/clozach/.rvm/gems/ruby-2.1.3#hoverfly/bin/ruby_executable_hooks:15:in `eval'
/Users/clozach/.rvm/gems/ruby-2.1.3#hoverfly/bin/ruby_executable_hooks:15:in `<main>'
(See full trace by running task with --trace)
Fail. :(
> rake test
>
No output. :(
> rake -T --all | grep test
rake db:test:clone #
rake db:test:clone_schema #
rake db:test:clone_structure #
rake db:test:deprecated #
rake db:test:load #
rake db:test:load_schema #
rake db:test:load_structure #
rake db:test:prepare #
rake db:test:purge #
rake log:clear # Truncates all *.log files in log/ to zero bytes (specify which logs with LOGS=test,development)
rake tmp/cache/assets/test #
No test tasks at all! :'(
Any idea why this is the case, and what I can do to fix it?
Take a look into config/application.rb whether the testing framework is actually required there. At the very top, there should be
require "rails/all"
Depending on your setup, you might have each individual component required separately. Make sure that test_unit is among them.
require "rails/test_unit/railtie"
*I want to get a custom Rake task to run in my Sinatra app but I keep getting rake aborted!
Don't know how to build task 'greet'.
Here's the custom Rake task (greet.rake) for testing purpose:
task :greet do
puts "Hello!"
end
I've put the greet.rake in ./lib/tasks (Rails). I'm guessing Rake can't find the correct directory for the file.
How do I get a custom Rake task to run in Sinatra?
I'm using Ruby 2.0.0 and Sinatra 1.4.4.
UPDATE
The Rakefile now looks like this:
require "./app"
require "sinatra/activerecord/rake"
require "./lib/tasks"
When using:
rake greet
I get:
rake aborted!
cannot load such file -- ./lib/tasks
/Users/*/.rvm/gems/ruby-2.0.0-p247#global/gems/activesupport- 4.0.1/lib/active_support/dependencies.rb:229:in `block in require'
/Users/*/.rvm/gems/ruby-2.0.0-p247#global/gems/activesupport- 4.0.1/lib/active_support/dependencies.rb:214:in `load_dependency'
/Users/*/.rvm/gems/ruby-2.0.0-p247#global/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:229:in `require'
/Users/*/Dropbox/Development/Sinatra/sinatra-mp-experiment/Rakefile:3:in `<top (required)>'
(See full trace by running task with --trace)
Create a Rakefile at your Sinatra app's top directory, require the file that contains this task you want to use and you should be good to go.
Edit:
A simple solution is changing your Rakefile to:
require "./app"
require "sinatra/activerecord/rake"
Dir.glob('lib/tasks/*.rake').each { |r| load r}
Now any .rake file under lib/tasks will be loaded.
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.