Tag: rake task

无法启动子进程

当我尝试在Chrome(selenium / Ruby)上运行测试时,我收到以下错误。 有人可以帮忙解决这个问题吗? 错误: – 背景:登录到app#tests \ integration \ channels.feature:3 [6100:7920:1028/134946:错误:child_process_launcher.cc(533)]无法启动子进程[6100:9520:1028/134946:错误:child_process_launcher .cc(533)]无法启动子进程[6100:9520:1028/134946:错误:child_process_launcher.cc(533)]无法启动子进程[6100:9520:1028/134949:错误:child_process_launcher.cc(533) )]无法启动子进程[6100:9520:1028/134955:错误:child_process_launcher.cc(533)]无法启动子进程[6100:9520:1028/135006:错误:child_process_launcher.cc(533)]失败启动子进程耙子中止! 以下是安装的gem: – * LOCAL GEMS * bigdecimal (default: 1.2.0) builder (3.2.2) bundle (0.0.1) bundler (1.13.6, 1.11.2) childprocess (0.5.0) cucumber (2.4.0, 1.3.2) cucumber-core (1.5.0) cucumber-wire (0.0.1) debase (0.2.1, 0.1.4) debase-ruby_core_source (0.9.2) diff-lcs (1.2.5) ffi (1.9.14 x86-mingw32) gherkin (4.0.0, 2.12.2 x86-mingw32) io-console (default: […]

Rails 3.1:如何仅为Web应用程序运行初始化程序(rails server / unicorn / etc)

我的webapp需要加密其会话数据。 我设置的是: config/initializers/encryptor.rb: require ‘openssl’ require ‘myapp/encryptor’ MyApp::Encryptor.config[ :random_key ] = OpenSSL::Random.random_bytes( 128 ) Session.delete_all app/models/session.rb: require ‘attr_encrypted’ class Session proc { MyApp::Encryptor.config[ :random_key ] }, :marshal => true # Rest of model stuff end 一切都很好,并保证会话数据安全。 这是问题所在:当我运行自定义rake任务时,它会加载初始化程序并清除所有会话。 不好! 我可以在初始化程序中放置什么来确保它仅用于webapp初始化? 或者,我可以在初始化程序中添加什么来使其不用于rake任务? 更新:好的,我现在所做的是添加MYAPP_IN_RAKE = true unless defined? MYAPP_IN_RAKE MYAPP_IN_RAKE = true unless defined? MYAPP_IN_RAKE到我的.rake文件。 然后在我的初始化程序中我做: unless defined?( […]

如何从rake文件中运行ruby类?

我想从sample.rake文件中运行ruby类。 考虑myruby.rb是一个ruby文件。 我想从像ruby myruby.rb这样的ruby myruby.rb运行它

删除CSV文件中的空格

我有一个额外的空格字符串: First,Last,Email ,Mobile Phone ,Company,Title ,Street,City,State,Zip,Country, Birthday,Gender ,Contact Type 我想解析这一行并删除空格。 我的代码看起来像: namespace :db do task :populate_contacts_csv => :environment do require ‘csv’ csv_text = File.read(‘file_upload_example.csv’) csv = CSV.parse(csv_text, :headers => true) csv.each do |row| puts “First Name: #{row[‘First’]} \nLast Name: #{row[‘Last’]} \nEmail: #{row[‘Email’]}” end end end

如何在rake任务中包含ActionMailer类?

我想在我的rake任务中使用ActionMailer,以便在特定时间向人们发送电子邮件。 我在app / mailers文件夹中编写了一个mailer类,如下所示: class AlertsMailer < ActionMailer::Base default from: 'x@y.com' def mail_alert(email_addresses, subject, url) @url = '#{url}' mail(to: email_addresses, subject: 'Alert') do |format| format.html { render '/alerts/list' } end end end 然后我在rake任务中包含以下行: AlertsMailer.mail_alert(email_addresses, subject) 当我尝试运行rake任务时: rake update_db 我收到以下错误: uninitialized constant AlertsMailer 我想我必须以某种方式在我的rake任务中加载邮件程序类,但我不知道该怎么做。 请帮忙。

使用Rspec测试rake任务不接受参数

根据Stephen Hagemann的这篇文章,我正试图为我的一个rake任务编写一个Rspec测试。 lib/tasks/retry.rake : namespace :retry do task :message, [:message_id] => [:environment] do |t, args| TextMessage.new.resend!(args[:message_id]) end end spec/tasks/retry_spec.rb : require ‘rails_helper’ require ‘rake’ describe ‘retry namespace rake task’ do describe ‘retry:message’ do before do load File.expand_path(“../../../lib/tasks/retry.rake”, __FILE__) Rake::Task.define_task(:environment) end it ‘should call the resend action on the message with the specified message_id’ do message_id […]