How to use messages method of Howitzer.MailtrapApi Package

Best Howitzer_ruby code snippet using Howitzer.MailtrapApi.messages

mailtrap_spec.rb

Source:mailtrap_spec.rb Github

copy

Full Screen

...7 allow(Howitzer).to receive(:mail_adapter) { 'mailtrap' }8 Howitzer::Email.adapter = 'mailtrap'9 allow(Howitzer).to receive(:mailtrap_inbox_id) { 777_777 }10 allow(Howitzer).to receive(:mailtrap_api_token) { 'fake_api_token' }11 base_url = 'https://mailtrap.io/api/v1/inboxes/777777/messages'12 stub_const('Howitzer::MailtrapApi::Client::BASE_URL', base_url.gsub('/messages', ''))13 FakeWeb.register_uri(:get, "#{base_url}/475265146/attachments", body: attachment.to_s)14 FakeWeb.register_uri(:get, "#{base_url}/32/attachments", body: '[]')15 FakeWeb.register_uri(:get, "#{base_url}?search=#{recipient}", body: "[#{message.to_s.gsub('=>', ':')}]")16 end17 let(:recipient) { 'test@mail.com' }18 let(:mail_subject) { 'Confirmation instructions' }19 let(:message) do20 {21 'id' => 475_265_146,22 'inbox_id' => 777_777,23 'subject' => 'Confirmation instructions',24 'sent_at' => '2017-07-18T08:55:49.389Z',25 'from_email' => 'noreply@test.com',26 'from_name' => '',27 'to_email' => 'test@mail.com',28 'to_name' => '',29 'html_body' => '<p> Test Email! </p>',30 'text_body' => 'Test Email!',31 'created_at' => '2017-07-18T14:14:31.641Z'32 }33 end34 let(:attachment) do35 '[{36 "id": 1737,37 "message_id": 475265146,38 "filename": "Photos.png",39 "attachment_type": "attachment",40 "content_type": "image/png",41 "download_path": "/api/v1/inboxes/777777/messages/475265146/attachments/45120545/download"42 }]'43 end44 let(:email_object) { Howitzer::Email.adapter.new(message) }45 describe '.find' do46 subject { Howitzer::MailAdapters::Mailtrap.find(recipient, mail_subject, wait: 0.01) }47 context 'when message is found' do48 it do49 expect(Howitzer::Email.adapter).to receive(:new).with(message).once50 subject51 end52 end53 context 'when message is not found' do54 let(:mail_subject) { 'Wrong subject' }55 it do...

Full Screen

Full Screen

client_spec.rb

Source:client_spec.rb Github

copy

Full Screen

...35 end36 describe '#find_message' do37 before do38 FakeWeb.register_uri(:get, "https://mailtrap.io/api/v1/inboxes/#{Howitzer.mailtrap_inbox_id}/" \39 "messages?search=#{recipient}", body: message.to_s)40 end41 subject { described_class.new.find_message(recipient, mail_subject) }42 it do43 expect(subject['to_email']).to eql(recipient)44 expect(subject['subject']).to eql(mail_subject)45 end46 end47 describe '#find_attachements' do48 before do49 FakeWeb.register_uri(:get, "https://mailtrap.io/api/v1/inboxes/#{Howitzer.mailtrap_inbox_id}/" \50 "messages?search=#{recipient}", body: message.to_s)51 FakeWeb.register_uri(:get, "https://mailtrap.io/api/v1/inboxes/#{Howitzer.mailtrap_inbox_id}/" \52 'messages/475265146/attachments', body: attachment.to_s)53 end54 let(:found_message) { described_class.new.find_message(recipient, mail_subject) }55 subject { described_class.new.find_attachments(found_message) }56 it do57 subject.each do |attachment|58 expect(attachment['message_id']).to eql found_message['id']59 expect(attachment['filename'].to_s).not_to be_empty60 end61 end62 end63end...

Full Screen

Full Screen

client.rb

Source:client.rb Github

copy

Full Screen

...14 # @param subject [String] this is subject of the message to filter particular message15 # @return [Hash] json message parsed to ruby hash16 def find_message(recipient, subject)17 recipient = recipient.gsub('+', '%2B')18 messages = filter_by_subject(messages(recipient), subject)19 latest_message(messages)20 end21 # Finds attachments for message22 #23 # @param message [Hash] which attachments should be extracted24 # @return [Array] returns array of attachments25 def find_attachments(message)26 JSON.parse(RestClient.get("#{BASE_URL}/messages/#{message['id']}/attachments", 'Api-Token' => @api_token))27 end28 private29 def messages(recipient)30 JSON.parse(RestClient.get("#{BASE_URL}/messages?search=#{recipient}", 'Api-Token' => @api_token))31 end32 def latest_message(messages)33 messages[0]34 end35 def filter_by_subject(messages, subject)36 result_messages = []37 messages.each { |msg| result_messages << msg if msg['subject'] == subject }38 result_messages39 end40 end41 end42end...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Howitzer_ruby automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful