Commit 97b2354
Changed files (2)
lib
minbox
spec
minbox
lib/minbox/inbox.rb
@@ -19,7 +19,7 @@ module Minbox
@emails.values
end
- def wait_until(seconds: 5, wait: 0.1)
+ def wait_until(seconds: 10, wait: 0.1)
iterations = (seconds / wait).to_i
iterations.times do
result = yield(self)
@@ -37,7 +37,9 @@ module Minbox
def open(subject:)
wait_until do
emails.find do |email|
- email.subject.match?(subject)
+ x = subject.is_a?(String) ? email.subject == subject : email.subject.match?(subject)
+ Minbox.logger.debug([subject, email.subject, x].inspect)
+ x
end
end
end
@@ -55,8 +57,12 @@ module Minbox
private
def changed(modified, added, removed)
+ Minbox.logger.debug([Thread.current.object_id, modified, added, removed].inspect)
+
added.each do |file|
- @emails[File.basename(file)] = Mail.read(file)
+ mail = Mail.read(file)
+ Minbox.logger.debug("Received: #{mail.subject}")
+ @emails[File.basename(file)] = mail
end
removed.each do |file|
@emails.delete(File.basename(file))
spec/minbox/inbox_spec.rb
@@ -12,7 +12,7 @@ RSpec.describe Minbox::Inbox do
IO.write("tmp/2.eml", Mail.new do
to Faker::Internet.email
from Faker::Internet.email
- subject "goodbye world"
+ subject "[ACTION] goodbye world"
end.to_s)
end
@@ -34,14 +34,14 @@ RSpec.describe Minbox::Inbox do
end
describe "#emails" do
- specify { expect(subject.emails(count: 2).map(&:subject)).to match_array(['goodbye world', 'hello world']) }
+ specify { expect(subject.emails(count: 2).map(&:subject)).to match_array(['[ACTION] goodbye world', 'hello world']) }
end
describe "#wait_until!" do
context "when the condition is satisfied" do
before { subject.wait_until! { |x| x.count == 2 } }
- specify { expect(subject.emails(count: 2).map(&:subject)).to match_array(['goodbye world', 'hello world']) }
+ specify { expect(subject.emails(count: 2).map(&:subject)).to match_array(['[ACTION] goodbye world', 'hello world']) }
end
context "when the condition is not satisfied" do
@@ -55,8 +55,8 @@ RSpec.describe Minbox::Inbox do
describe "#open" do
context "when opening an email by subject" do
- specify { expect(subject.open(subject: 'goodbye world').subject).to eql('goodbye world') }
- specify { expect(subject.open(subject: /goodbye/).subject).to eql('goodbye world') }
+ specify { expect(subject.open(subject: '[ACTION] goodbye world').subject).to eql('[ACTION] goodbye world') }
+ specify { expect(subject.open(subject: /goodbye/).subject).to eql('[ACTION] goodbye world') }
specify { expect(subject.open(subject: /hello/).subject).to eql('hello world') }
specify { expect(subject.open(subject: /world/).subject).to eql('hello world') }
end