Commit 802fb95
Changed files (2)
lib
minbox
spec
minbox
lib/minbox/inbox.rb
@@ -18,6 +18,16 @@ module Minbox
@emails.keys
end
+ def until(seconds: 10, wait: 0.1)
+ iterations = (seconds / wait).to_i
+ iterations.times do
+ return if yield(self)
+
+ sleep wait
+ end
+ raise "timeout: #{seconds} seconds elapsed."
+ end
+
def open(id)
@emails[id]
end
spec/minbox/inbox_spec.rb
@@ -37,11 +37,20 @@ RSpec.describe Minbox::Inbox do
end
describe "#emails" do
- let(:results) { subject.emails }
-
before { Process.wait(create_emails) }
- specify { expect(results).to match_array(['1.eml', '2.eml']) }
+ specify { expect(subject.emails).to match_array(['1.eml', '2.eml']) }
+ end
+
+ describe "#until" do
+ before do
+ create_emails
+ subject.until do |inbox|
+ inbox.count == 2
+ end
+ end
+
+ specify { expect(subject.emails).to match_array(['1.eml', '2.eml']) }
end
describe "#open" do