github.com/cozy/cozy-stack@v0.0.0-20240603063001-31110fa4cae1/tests/system/lib/helpers.rb (about) 1 module Helpers 2 SHARED_WITH_ME_EN = "Inbox of sharings".freeze 3 SHARED_WITH_ME = "Partages reçus".freeze 4 5 @current_dir = File.expand_path "../../tmp", __FILE__ 6 7 class <<self 8 attr_reader :current_dir, :couch 9 10 def setup 11 @couch = Couch.new 12 end 13 14 def scenario(scenario = nil) 15 if scenario 16 @scenario = scenario 17 @current_dir = File.expand_path "../../tmp/#{@scenario}", __FILE__ 18 FileUtils.mkdir_p @current_dir 19 RestClient.log = Logger.new "#{@current_dir}/client.log" 20 end 21 @scenario 22 end 23 24 def start_mailhog 25 `MailHog --version` 26 spawn "MailHog" 27 rescue Errno::ENOENT 28 # Ignored: on our CI environment, MailHog is started as a docker service 29 end 30 31 def cat(filename) 32 puts "----- #{filename} -----" 33 puts File.read "#{@current_dir}/#{filename}" 34 end 35 36 def spawn(cmd, opts = {}) 37 log_file_name = opts[:log] || "#{cmd.downcase}.log" 38 puts "spawn #{cmd} &> #{log_file_name}".green 39 log = "#{@current_dir}/#{log_file_name}" 40 pid = Process.spawn cmd, [:out, :err] => [log, File::WRONLY | File::CREAT, 0o644] 41 if defined? Minitest 42 Minitest.after_run { Process.kill :SIGINT, pid } 43 else 44 at_exit { Process.kill :SIGINT, pid } 45 end 46 pid 47 end 48 49 def cleanup 50 clean_tmp 51 couch.clean_test 52 Email.clear_inbox 53 end 54 55 def clean_tmp 56 tmp = File.expand_path "../../tmp", __FILE__ 57 FileUtils.cd tmp do 58 Dir["*"].each do |f| 59 FileUtils.rm_r f 60 end 61 end 62 end 63 64 def fsdiff(a, b) 65 if ENV['COZY_SWIFTTEST'] 66 puts "fsdiff is not available with COZY_SWIFTTEST".yellow 67 return [] 68 end 69 diff = `LANG=C diff -qr '#{a}' '#{b}'` 70 diff.lines.map(&:chomp) 71 end 72 73 def file_exists_in_fs(path) 74 File.exist?(path) 75 end 76 end 77 end