我使用rb notify来监视Rails项目的Rspec测试中的一个目录。如果找不到文件,则inotify将继续无休止地循环。有没有办法让它在10秒后放弃。
@notifier = INotify::Notifier.new
@notifier.watch(DownloadHelpers::PATH.to_s, :create) do |file|
puts "Check: #{file.name}"
if file.name.eql?(File.basename(@filename.to_s))
@pdf = PdfReader.new(@filename)
# Check PDF
expect(@pdf.page_count).to eq(1)
expect(@pdf.pages[1]).to have_text("CONTRACTORS")
@notifier.stop # Stops the infinite loop watch
end
end
visit "/#/contractors_report"
within "#heading" do
expect(page).to have_text("Contractors")
end
click_on("pdf-btn")
@notifier.run # Make sure we finish our thread