capybara-email icon indicating copy to clipboard operation
capybara-email copied to clipboard

Add ability to search for an email by subject

Open ZachBeta opened this issue 11 years ago • 7 comments

Have multiple emails reaching one user. Need to find based on subject.

Investigating.

ZachBeta avatar May 09 '13 19:05 ZachBeta

That's interesting. You could do this with the current API but you have to jump through a hoop or two:

all_emails.find { |e| e.subject ~= /keyword/ }
all_emails.collect { |e| e.subject ~= /keyword/ }

The first will return a single email, the second will return a collection of emails matching

bcardarella avatar May 09 '13 19:05 bcardarella

Should make things a little cleaner in our specs by pushing this logic into the gem.

I also noticed the dissonance between first_email_sent_to and the fact that it grabs the last email. But I figured that might break some other specs, so I left that alone.

ZachBeta avatar May 09 '13 20:05 ZachBeta

I believe it is grabbing the last because the email is pushed onto a queue. I could be wrong, I'll have to double check.

bcardarella avatar May 09 '13 20:05 bcardarella

If that's the case, then I was just being too picky about code formatting :-P

ZachBeta avatar May 09 '13 20:05 ZachBeta

@bcardarella is this still an open issue?

maabernethy avatar Jan 06 '14 20:01 maabernethy

@bcardarella can be closed?

rsocci avatar Apr 04 '14 16:04 rsocci

checking at the source code (https://github.com/dockyard/capybara-email/blob/master/lib/capybara/email/dsl.rb#L42), I found current_emails method, which is returning array of emails. So, I fixed this issue by:

current_emails.first.click_link 'Confirm my account'

AND

current_emails.last.click_link 'Change my password'

# current_email is already a last email so we can directly write:

current_email.click_link "Change my password"

So, I guess, you can reference your emails by array index like:

current_emails[0]
current_emails[1]
and so on ....

Hope this is helpful. And yes, I agree, if gem will implement some way to directly fetch emails with their subject.

Thanks

przbadu avatar Dec 09 '15 07:12 przbadu