câu trả lời chấp thuận không làm việc cho tôi, khi tôi cần thiết để thực hiện nhiệm vụ cào của riêng tôi
Đây là giải pháp của tôi
Đặt ở phía trên cùng của file spec
require 'rake'
Nơi những dòng này khi bạn cần phải thực hiện nhiệm vụ cào tùy chỉnh của bạn, ví dụ cào update_data từ tập tin example.rake
load File.expand_path("../../../lib/tasks/example.rake", __FILE__)
# make sure you set correct relative path
Rake::Task.define_task(:environment)
Rake::Task["update_data"].invoke
môi trường của tôi:
rails (4.0.0)
ruby (2.0.0p195)
rspec-core (2.14.7)
rspec-expectations (2.14.3)
rspec-mocks (2.14.4)
rspec (2.14.1)
rspec-rails (2.14.0)
Nguồn
2013-11-14 11:49:03
cùng mà không RSpec: http://stackoverflow.com/questions/3530/how-do-i-rake-tasks-within -a-ruby-script –