# -*- encoding : utf-8 -*- # Commonly used email steps # # To add your own steps make a custom_email_steps.rb # The provided methods are: # # last_email_address # reset_mailer # open_last_email # visit_in_email # unread_emails_for # mailbox_for # current_email # open_email # read_emails_for # find_email # # General form for email scenarios are: # - clear the email queue (done automatically by email_spec) # - execute steps that sends an email # - check the user received an/no/[0-9] emails # - open the email # - inspect the email contents # - interact with the email (e.g. click links) # # The Cucumber steps below are setup in this order. module EmailHelpers def parse_email_count(amount) case amount when 'um' then 1 when 'nenhum' then 0 else super(amout) end end def current_email_address # Replace with your a way to find your current email. e.g @current_user.email # last_email_address will return the last email address used by email spec to find an email. # Note that last_email_address will be reset after each Scenario. last_email_address || "example@example.com" end end World(EmailHelpers) # # Reset the e-mail queue within a scenario. # This is done automatically before each scenario. # Dado /^(?:que não há emails|que nenhum email foi enviado)$/ do reset_mailer end # # Check how many emails have been sent/received # Então /^(?:eu|ele|"([^\"]*?)") deveria receber (um|nenhum|\d+) emails?$/ do |address, amount| unread_emails_for(address).size.should == parse_email_count(amount) end Então /^(?:eu|ele|"([^\"]*?)") deveria receber (um|nenhum|\d+) emails? com o assunto "([^\"]*?)"$/ do |address, amount, subject| unread_emails_for(address).select { |m| m.subject =~ Regexp.new(Regexp.escape(subject)) }.size.should == parse_email_count(amount) end Então /^(?:eu|ele|"([^\"]*?)") deveria receber (um|nenhum|\d+) emails? com o assunto \/(.*?)\/$/ do |address, amount, subject| unread_emails_for(address).select { |m| m.subject =~ Regexp.new(subject) }.size.should == parse_email_count(amount) end Então /^(?:eu|ele|"([^\"]*?)") deveria receber um email com o corpo:$/ do |address, expected_body| open_email(address, :with_text => expected_body) end # # Accessing emails # # Opens the most recently received email Quando /^(?:eu|ele|"([^\"]*?)") abr(?:e|o|ir) o email$/ do |address| open_email(address) end Quando /^(?:eu|ele|"([^\"]*?)") abr(?:e|o|ir) o email com o assunto "([^\"]*?)"$/ do |address, subject| open_email(address, :with_subject => subject) end Quando /^(?:eu|ele|"([^\"]*?)") abr(?:e|o|ir) o email com o assunto \/(.*?)\/$/ do |address, subject| open_email(address, :with_subject => Regexp.new(subject)) end Quando /^(?:eu|ele|"([^\"]*?)") abr(?:e|o|ir) o email com o texto "([^\"]*?)"$/ do |address, text| open_email(address, :with_text => text) end Quando /^(?:eu|ele|"([^\"]*?)") abr(?:e|o|ir) o email com o texto \/(.*?)\/$/ do |address, text| open_email(address, :with_text => Regexp.new(text)) end # # Inspect the Email Contents # Então /^(?:|eu |ele )deveria ver "([^\"]*?)" no assunto do email$/ do |text| current_email.should have_subject(text) end Então /^(?:|eu |ele )deveria ver \/(.*?)\/ no assunto do email$/ do |text| current_email.should have_subject(Regexp.new(text)) end Então /^(?:|eu |ele )deveria ver "([^\"]*?)" no corpo do email$/ do |text| current_email.default_part_body.to_s.should include(text) end Então /^(?:|eu |ele )deveria ver \/(.*?)\/ no corpo do email$/ do |text| current_email.default_part_body.to_s.should =~ Regexp.new(text) end Então /^(?:|eu |ele )deveria ver que o email foi enviado (?:por|pelo) "([^\"]*?)"$/ do |text| current_email.should be_delivered_from(text) end Então /^(?:|eu |ele )deveria ver "([^\"]*)" no cabeçalo "([^\"]*?)" do email$/ do |text, name| current_email.should have_header(name, text) end Então /^(?:|eu |ele )deveria ver \/(.*)\/ no cabeçalo "([^\"]*?)" do email$/ do |text, name| current_email.should have_header(name, Regexp.new(text)) end Então /^eu deveria ver um email multi\-part$/ do current_email.should be_multipart end Então /^(?:I|they) should see "([^\"]*?)" in the email html part body$/ do |text| current_email.html_part.body.to_s.should include(text) end Então /^(?:I|they) should see "([^\"]*?)" in the email text part body$/ do |text| current_email.text_part.body.to_s.should include(text) end Então /^(?:eu|ele) deveria ver "([^\"]*?)" no corpo html do email$/ do |text| current_email.html_part.body.to_s.should include(text) end Então /^(?:eu|ele) deveria ver "([^\"]*?)" no corpo texto do email$/ do |text| current_email.text_part.body.to_s.should include(text) end # # Inspect the Email Attachments # Então /^(?:eu|ele) deveria ver (um|nenhum|\d+) anexos? no email$/ do |amount| current_email_attachments.size.should == parse_email_count(amount) end Então /^deveria haver (um|nenhum|\d+) anexos? com o nome "([^\"]*?)"$/ do |amount, filename| current_email_attachments.select { |a| a.filename == filename }.size.should == parse_email_count(amount) end Então /^o anexo (\d+) deveria se chamar "([^\"]*?)"$/ do |index, filename| current_email_attachments[(index.to_i - 1)].filename.should == filename end Então /^deveria haver (um|nenhum|\d+) anexos? com a extenção "([^\"]*?)"$/ do |amount, content_type| current_email_attachments.select { |a| a.content_type.include?(content_type) }.size.should == parse_email_count(amount) end Então /^o anexo (\d+) deveria ter a extenção "([^\"]*?)"$/ do |index, content_type| current_email_attachments[(index.to_i - 1)].content_type.should include(content_type) end Então /^nenhum anexo deveria ser vazio$/ do current_email_attachments.each do |attachment| attachment.read.size.should_not == 0 end end Então /^mostre me a lista de anexos do email$/ do EmailSpec::EmailViewer::save_and_open_email_attachments_list(current_email) end # # Interact with Email Contents # Quando /^(?:eu|ele) sigo o link "([^\"]*?)" no email$/ do |link| visit_in_email(link) end Quando /^(?:eu|ele) clico no primeiro link do email$/ do click_first_link_in_email end # # Debugging # These only work with Rails and OSx ATM since EmailViewer uses RAILS_ROOT and OSx's 'open' command. # Patches accepted. ;) # 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