2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-04-25 15:17:43 +08:00
|
|
|
# I like guard, don't get me wrong, but it is just not working right
|
2021-05-21 09:43:47 +08:00
|
|
|
# architecturally it can not do what I want it to do, this is how I want
|
2013-04-25 15:17:43 +08:00
|
|
|
# it to behave
|
|
|
|
|
|
|
|
desc "Run all specs automatically as needed"
|
|
|
|
task "autospec" => :environment do
|
2013-11-02 06:57:50 +08:00
|
|
|
require "autospec/manager"
|
2013-05-13 16:04:03 +08:00
|
|
|
|
2015-05-14 09:24:48 +08:00
|
|
|
debug = ARGV.any? { |a| a == "d" || a == "debug" } || ENV["DEBUG"]
|
2013-11-05 18:01:17 +08:00
|
|
|
force_polling = ARGV.any? { |a| a == "p" || a == "polling" }
|
|
|
|
latency = ((ARGV.find { |a| a =~ /l=|latency=/ } || "").split("=")[1] || 3).to_i
|
2013-05-01 08:29:39 +08:00
|
|
|
|
|
|
|
if force_polling
|
2013-11-02 06:57:50 +08:00
|
|
|
puts "Polling has been forced (slower) - checking every #{latency} #{"second".pluralize(latency)}"
|
|
|
|
else
|
|
|
|
puts "If file watching is not working, you can force polling with: bundle exec rake autospec p l=3"
|
2013-05-01 08:29:39 +08:00
|
|
|
end
|
|
|
|
|
2013-11-05 18:01:17 +08:00
|
|
|
puts "@@@@@@@@@@@@ Running in debug mode" if debug
|
2013-11-02 06:57:50 +08:00
|
|
|
|
2013-11-05 18:01:17 +08:00
|
|
|
Autospec::Manager.run(force_polling: force_polling, latency: latency, debug: debug)
|
2013-04-25 15:17:43 +08:00
|
|
|
end
|
2021-12-23 06:40:15 +08:00
|
|
|
|
|
|
|
desc "Regenerate swagger docs on API spec change"
|
|
|
|
task "autospec:swagger" => :environment do
|
|
|
|
require "listen"
|
|
|
|
require "open3"
|
|
|
|
|
|
|
|
puts "Listening to changes in spec/requests/api to regenerate Swagger docs."
|
|
|
|
listener =
|
|
|
|
Listen.to("spec/requests/api") do |modified, added, removed|
|
|
|
|
puts "API doc file changed."
|
|
|
|
Open3.popen3("spec/regenerate_swagger_docs") do |stdin, stdout, stderr, wait_thr|
|
|
|
|
while line = stdout.gets
|
|
|
|
puts line
|
2023-01-09 20:10:19 +08:00
|
|
|
end
|
2021-12-23 06:40:15 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
listener.start
|
|
|
|
sleep
|
|
|
|
end
|