ruby-on-rails - 未初始化的常量 Rake::TestTask
问题描述
我正在尝试run bundle exec rake redmine:plugins NAME=redmine_checklists RAILS_ENV=production
并收到此错误
NameError: uninitialized constant Rake::TestTask /usr/share/redmine/lib/tasks/redmine.rake:163:in
`block (3 levels) in <top (required)>' /usr/share/redmine/lib/tasks/redmine.rake:161:in `block (2
levels) in <top (required)>' /usr/share/redmine/lib/tasks/redmine.rake:117:in `block in <top
(required)>' /usr/share/redmine/lib/tasks/redmine.rake:18:in `<top (required)>'
/var/lib/gems/2.5.0/gems/railties-6.0.3.2/lib/rails/engine.rb:660:in `block in run_tasks_blocks'
/var/lib/gems/2.5.0/gems/railties-6.0.3.2/lib/rails/engine.rb:660:in `each'
/var/lib/gems/2.5.0/gems/railties-6.0.3.2/lib/rails/engine.rb:660:in `run_tasks_blocks'
/var/lib/gems/2.5.0/gems/railties-6.0.3.2/lib/rails/application.rb:518:in `run_tasks_blocks'
/var/lib/gems/2.5.0/gems/railties-6.0.3.2/lib/rails/engine.rb:459:in `load_tasks'
/var/lib/gems/2.5.0/gems/railties-6.0.3.2/lib/rails/railtie.rb:190:in `public_send'
/var/lib/gems/2.5.0/gems/railties-6.0.3.2/lib/rails/railtie.rb:190:in `method_missing'
/usr/share/redmine/Rakefile:6:in `<top (required)>' /var/lib/gems/2.5.0/gems/rake-
13.0.1/exe/rake:27:in `<top (required)>' /var/lib/gems/2.5.0/gems/bundler-
2.1.4/lib/bundler/cli/exec.rb:63:in `load' /var/lib/gems/2.5.0/gems/bundler-
2.1.4/lib/bundler/cli/exec.rb:63:in `kernel_load' /var/lib/gems/2.5.0/gems/bundler-
2.1.4/lib/bundler/cli/exec.rb:28:in `run' /var/lib/gems/2.5.0/gems/bundler-
2.1.4/lib/bundler/cli.rb:476:in `exec' /var/lib/gems/2.5.0/gems/bundler-
2.1.4/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run' /var/lib/gems/2.5.0/gems/bundler-
2.1.4/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
/var/lib/gems/2.5.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor.rb:399:in `dispatch'
/var/lib/gems/2.5.0/gems/bundler-2.1.4/lib/bundler/cli.rb:30:in `dispatch'
/var/lib/gems/2.5.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/base.rb:476:in `start'
/var/lib/gems/2.5.0/gems/bundler-2.1.4/lib/bundler/cli.rb:24:in `start'
/var/lib/gems/2.5.0/gems/bundler-
2.1.4/exe/bundle:46:in `block in <top (required)>' /var/lib/gems/2.5.0/gems/bundler-
2.1.4/lib/bundler/friendly_errors.rb:123:in `with_friendly_errors' /var/lib/gems/2.5.0/gems/bundler-
2.1.4/exe/bundle:34:in `<top (required)>' /usr/local/bin/bundle:23:in `load'
/usr/local/bin/bundle:23:in
`<main>' (See full trace by running task with --trace)
我的/usr/share/redmine/lib/tasks/redmine.rake
namespace :redmine do
namespace :attachments do
desc 'Removes uploaded files left unattached after one day.'
task :prune => :environment do
Attachment.prune
end
desc 'Moves attachments stored at the root of the file directory (ie. created before Redmine 2.3) to their subdirectories'
task :move_to_subdirectories => :environment do
Attachment.move_from_root_to_target_directory
end
desc 'Updates attachment digests to SHA256'
task :update_digests => :environment do
Attachment.update_digests_to_sha256
end
end
namespace :tokens do
desc 'Removes expired tokens.'
task :prune => :environment do
Token.destroy_expired
end
end
namespace :watchers do
desc 'Removes watchers from what they can no longer view.'
task :prune => :environment do
Watcher.prune
end
end
desc 'Fetch changesets from the repositories'
task :fetch_changesets => :environment do
Repository.fetch_changesets
end
desc 'Migrates and copies plugins assets.'
task :plugins do
Rake::Task["redmine:plugins:migrate"].invoke
Rake::Task["redmine:plugins:assets"].invoke
end
desc <<-DESC
FOR EXPERIMENTAL USE ONLY, Moves Redmine data from production database to the development database.
This task should only be used when you need to move data from one DBMS to a different one (eg. MySQL to PostgreSQL).
WARNING: All data in the development database is deleted.
DESC
task :migrate_dbms => :environment do
ActiveRecord::Base.establish_connection :development
target_tables = ActiveRecord::Base.connection.tables
ActiveRecord::Base.remove_connection
ActiveRecord::Base.establish_connection :production
tables = ActiveRecord::Base.connection.tables.sort - %w(schema_migrations plugin_schema_info)
if (tables - target_tables).any?
list = (tables - target_tables).map {|table| "* #{table}"}.join("\n")
abort "The following table(s) are missing from the target database:\n#{list}"
end
tables.each do |table_name|
Source = Class.new(ActiveRecord::Base)
Target = Class.new(ActiveRecord::Base)
Target.establish_connection(:development)
[Source, Target].each do |klass|
klass.table_name = table_name
klass.reset_column_information
klass.inheritance_column = "foo"
klass.record_timestamps = false
end
Target.primary_key = (Target.column_names.include?("id") ? "id" : nil)
source_count = Source.count
puts "Migrating %6d records from #{table_name}..." % source_count
Target.delete_all
offset = 0
while (objects = Source.offset(offset).limit(5000).order("1,2").to_a) && objects.any?
offset += objects.size
Target.transaction do
objects.each do |object|
new_object = Target.new(object.attributes)
new_object.id = object.id if Target.primary_key
new_object.save(:validate => false)
end
end
end
Target.connection.reset_pk_sequence!(table_name) if Target.primary_key
target_count = Target.count
abort "Some records were not migrated" unless source_count == target_count
Object.send(:remove_const, :Target)
Object.send(:remove_const, :Source)
end
end
namespace :plugins do
desc 'Migrates installed plugins.'
task :migrate => :environment do
name = ENV['NAME']
version = nil
version_string = ENV['VERSION']
if version_string
if version_string =~ /^\d+$/
version = version_string.to_i
if name.nil?
abort "The VERSION argument requires a plugin NAME."
end
else
abort "Invalid VERSION #{version_string} given."
end
end
begin
Redmine::Plugin.migrate(name, version)
rescue Redmine::PluginNotFound
abort "Plugin #{name} was not found."
end
Rake::Task["db:schema:dump"].invoke
end
desc 'Copies plugins assets into the public directory.'
task :assets => :environment do
name = ENV['NAME']
begin
Redmine::Plugin.mirror_assets(name)
rescue Redmine::PluginNotFound
abort "Plugin #{name} was not found."
end
end
desc 'Runs the plugins tests.'
task :test do
Rake::Task["redmine:plugins:test:units"].invoke
Rake::Task["redmine:plugins:test:functionals"].invoke
Rake::Task["redmine:plugins:test:integration"].invoke
end
namespace :test do
desc 'Runs the plugins unit tests.'
Rake::TestTask.new :units => "db:test:prepare" do |t|
t.libs << "test"
t.verbose = true
t.pattern = "plugins/#{ENV['NAME'] || '*'}/test/unit/**/*_test.rb"
end
desc 'Runs the plugins functional tests.'
Rake::TestTask.new :functionals => "db:test:prepare" do |t|
t.libs << "test"
t.verbose = true
t.pattern = "plugins/#{ENV['NAME'] || '*'}/test/functional/**/*_test.rb"
end
desc 'Runs the plugins integration tests.'
Rake::TestTask.new :integration => "db:test:prepare" do |t|
t.libs << "test"
t.verbose = true
t.pattern = "plugins/#{ENV['NAME'] || '*'}/test/integration/**/*_test.rb"
end
desc 'Runs the plugins ui tests.'
Rake::TestTask.new :ui => "db:test:prepare" do |t|
t.libs << "test"
t.verbose = true
t.pattern = "plugins/#{ENV['NAME'] || '*'}/test/ui/**/*_test.rb"
end
end
end
end
# Load plugins' rake tasks
Dir[File.join(Rails.root, "plugins/*/lib/tasks/**/*.rake")].sort.each { |ext| load ext }
导轨-v
6.0.3.2
红宝石-v
ruby 2.5.1p57(2018-03-29 修订版 63029)[x86_64-linux-gnu]
宝石清单耙
耙子 (13.0.1, 12.3.1)
我试图从 redmine.rake 中删除 Rake::TestTask 但它导致了更多错误。我不擅长 ruby-on-rails,我只是想安装一个 redmine 插件。
解决方案
您需要将其require "rake/testtask"
添加到 rake 文件中才能使用Rake::TestTask
请参阅文章创建测试 rake 任务
推荐阅读
- node.js - 定义无限循环以从 API 读取数据并与数据库进行比较的最佳位置
- sql - 在另一列中选择具有相同 id 但相同值的行
- coq - 用 list_beq 证明列表的相等性
- magento2 - Magento 2 自定义控制台命令创建具有角色的管理员用户,Laminas 服务定位器问题
- database - 为什么 laradock 为不同的项目使用一个数据库?
- node.js - 错误 [ERR_HTTP_HEADERS_SENT]:发送到客户端后无法设置标头 | NodeJS ExpressJS MySQL
- ruby-on-rails - 如何在 Rails 中加密 csv/xlsx 文件
- python - AES 128 如何在 python 中使用部分密钥进行暴力破解
- php - FFMpeg 将音频文件连接在一起,最后一个文件作为背景
- html - CSS:在英雄图像上方制作浮动导航栏的最佳方法?