123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- module EmailHelpers
- def current_email_address
-
-
-
- last_email_address || "example@example.com"
- end
- end
- World(EmailHelpers)
- Given /^(?:a clear email queue|no emails have been sent)$/ do
- reset_mailer
- end
- Then /^(?:I|they|"([^"]*?)") should receive (an|no|\d+) emails?$/ do |address, amount|
- unread_emails_for(address).size.should == parse_email_count(amount)
- end
- Then /^(?:I|they|"([^"]*?)") should have (an|no|\d+) emails?$/ do |address, amount|
- mailbox_for(address).size.should == parse_email_count(amount)
- end
- Then /^(?:I|they|"([^"]*?)") should receive (an|no|\d+) emails? with subject "([^"]*?)"$/ do |address, amount, subject|
-
-
-
-
-
-
- unread_emails_for(address).select { |m| m.subject =~ Regexp.new(Regexp.escape(subject)) }.size.should == parse_email_count(amount)
- end
- Then /^(?:I|they|"([^"]*?)") should receive (an|no|\d+) emails? with subject \/([^"]*?)\/$/ do |address, amount, subject|
- unread_emails_for(address).select { |m| m.subject =~ Regexp.new(subject) }.size.should == parse_email_count(amount)
- end
- Then /^(?:I|they|"([^"]*?)") should receive an email with the following body:$/ do |address, expected_body|
- open_email(address, :with_text => expected_body)
- end
- #
- # Accessing emails
- #
- # Opens the most recently received email
- When /^(?:I|they|"([^"]*?)") opens? the email$/ do |address|
- open_email(address)
- end
- When /^(?:I|they|"([^"]*?)") opens? the email with subject "([^"]*?)"$/ do |address, subject|
- open_email(address, :with_subject => subject)
- end
- When /^(?:I|they|"([^"]*?)") opens? the email with subject \/([^"]*?)\/$/ do |address, subject|
- open_email(address, :with_subject => Regexp.new(subject))
- end
- When /^(?:I|they|"([^"]*?)") opens? the email with text "([^"]*?)"$/ do |address, text|
- open_email(address, :with_text => text)
- end
- When /^(?:I|they|"([^"]*?)") opens? the email with text \/([^"]*?)\/$/ do |address, text|
- open_email(address, :with_text => Regexp.new(text))
- end
- Then /^(?:I|they) should see "([^"]*?)" in the email subject$/ do |text|
- current_email.should have_subject(text)
- end
- Then /^(?:I|they) should see \/([^"]*?)\/ in the email subject$/ do |text|
- current_email.should have_subject(Regexp.new(text))
- end
- Then /^(?:I|they) should see "([^"]*?)" in the email body$/ do |text|
- current_email.default_part_body.to_s.should include(text)
- end
- Then /^(?:I|they) should see \/([^"]*?)\/ in the email body$/ do |text|
- current_email.default_part_body.to_s.should =~ Regexp.new(text)
- end
- Then /^(?:I|they) should see the email delivered from "([^"]*?)"$/ do |text|
- current_email.should be_delivered_from(text)
- end
- Then /^(?:I|they) should see "([^\"]*)" in the email "([^"]*?)" header$/ do |text, name|
- current_email.should have_header(name, text)
- end
- Then /^(?:I|they) should see \/([^\"]*)\/ in the email "([^"]*?)" header$/ do |text, name|
- current_email.should have_header(name, Regexp.new(text))
- end
- Then /^I should see it is a multi\-part email$/ do
- current_email.should be_multipart
- end
- Then /^(?:I|they) should see "([^"]*?)" in the email html part body$/ do |text|
- current_email.html_part.body.to_s.should include(text)
- end
- Then /^(?:I|they) should see "([^"]*?)" in the email text part body$/ do |text|
- current_email.text_part.body.to_s.should include(text)
- end
- Then /^(?:I|they) should see (an|no|\d+) attachments? with the email$/ do |amount|
- current_email_attachments.size.should == parse_email_count(amount)
- end
- Then /^there should be (an|no|\d+) attachments? named "([^"]*?)"$/ do |amount, filename|
- current_email_attachments.select { |a| a.filename == filename }.size.should == parse_email_count(amount)
- end
- Then /^attachment (\d+) should be named "([^"]*?)"$/ do |index, filename|
- current_email_attachments[(index.to_i - 1)].filename.should == filename
- end
- Then /^there should be (an|no|\d+) attachments? of type "([^"]*?)"$/ do |amount, content_type|
- current_email_attachments.select { |a| a.content_type.include?(content_type) }.size.should == parse_email_count(amount)
- end
- Then /^attachment (\d+) should be of type "([^"]*?)"$/ do |index, content_type|
- current_email_attachments[(index.to_i - 1)].content_type.should include(content_type)
- end
- Then /^all attachments should not be blank$/ do
- current_email_attachments.each do |attachment|
- attachment.read.size.should_not == 0
- end
- end
- Then /^show me a list of email attachments$/ do
- EmailSpec::EmailViewer::save_and_open_email_attachments_list(current_email)
- end
- When /^(?:I|they|"([^"]*?)") clicks in the link? "([^"]*?)" in the email$/ do |address, link|
- visit_in_email(link, address)
- end
- When /^(?:I|they) click the first link in the email$/ do
- click_first_link_in_email
- end
- Then /^save and open current email$/ do
- EmailSpec::EmailViewer::save_and_open_email(current_email)
- end
- Then /^save and open all text emails$/ do
- EmailSpec::EmailViewer::save_and_open_all_text_emails
- end
- Then /^save and open all html emails$/ do
- EmailSpec::EmailViewer::save_and_open_all_html_emails
- end
- Then /^save and open all raw emails$/ do
- EmailSpec::EmailViewer::save_and_open_all_raw_emails
- end
|