Commit 0c5c4eb

mokha <mokha@cisco.com>
2019-04-15 23:11:20
remove deleted files from inbox
1 parent 2f9959c
Changed files (2)
lib
minbox
spec
lib/minbox/inbox.rb
@@ -11,16 +11,19 @@ module Minbox
         added.each do |file|
           @emails[File.basename(file)] = Mail.read(file)
         end
+        removed.each do |file|
+          @emails.delete(File.basename(file))
+        end
       end.start
     end
 
     def emails(count: 0)
-      wait_until { |x| @emails.keys.count >= count } if count > 0
+      wait_until { |x| x.count >= count } if count > 0
 
       @emails.keys
     end
 
-    def wait_until(seconds: 10, wait: 0.1)
+    def wait_until(seconds: 5, wait: 0.1)
       iterations = (seconds / wait).to_i
       iterations.times do
         return true if yield(self)
spec/minbox/inbox_spec.rb
@@ -4,8 +4,6 @@ RSpec.describe Minbox::Inbox do
   subject! { described_class.instance }
 
   before do
-    subject.empty!
-
     IO.write("tmp/1.eml", Mail.new do
       to Faker::Internet.email
       from Faker::Internet.email
@@ -41,7 +39,9 @@ RSpec.describe Minbox::Inbox do
 
   describe "#wait_until!" do
     context "when the condition is satisfied" do
-      specify { expect(subject.emails(count: 2)).to match_array(['1.eml', '2.eml']) }
+      before { subject.wait_until! { |x| x.count == 2 } }
+
+      specify { expect(subject.emails).to match_array(['1.eml', '2.eml']) }
     end
 
     context "when the condition is not satisfied" do