Best Howitzer_ruby code snippet using Howitzer.adapter
mailtrap_spec.rb
Source:mailtrap_spec.rb
...3require 'howitzer/log'4require 'howitzer/exceptions'5RSpec.describe 'Mailtrap Email Adapter' do6 before do7 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 do56 expect { subject }.to raise_error(57 Howitzer::EmailNotFoundError,58 "Message with subject '#{mail_subject}' for recipient '#{recipient}' was not found."59 )60 end61 end62 end63 describe '#plain_text_body' do64 it { expect(email_object.plain_text_body).to eql message['text_body'] }65 end66 describe '#html_body' do67 it { expect(email_object.html_body).to eql message['html_body'] }68 end69 describe '#text' do70 it { expect(email_object.text).to eql message['text_body'] }71 end72 describe '#mail_from' do73 it { expect(email_object.mail_from).to eql message['from_email'] }74 end75 describe '#recipients' do76 subject { email_object.recipients }77 it { is_expected.to be_a_kind_of Array }78 context 'when one recipient' do79 it { is_expected.to include message['to_email'] }80 end81 context 'when more than one recipient' do82 let(:second_recipient) { 'second_tester@gmail.com' }83 let(:message_with_multiple_recipients) { message.merge('to_email' => "#{recipient}, #{second_recipient}") }84 let(:email_object) { Howitzer::Email.adapter.new(message_with_multiple_recipients) }85 it { is_expected.to eql [recipient, second_recipient] }86 end87 end88 describe '#received_time' do89 it { expect(email_object.received_time).to eql Time.parse(message['created_at']).to_s }90 end91 describe '#sender_email' do92 it { expect(email_object.sender_email).to eql message['from_email'] }93 end94 describe '#mime_part' do95 context 'when has attachments' do96 it { expect(email_object.mime_part).not_to be_empty }97 end98 context 'when no attachments' do99 let(:another_message) { message.merge('id' => 32) }100 let(:email_object) { Howitzer::Email.adapter.new(another_message) }101 it { expect(email_object.mime_part).to be_empty }102 end103 end104 describe '#mime_part!' do105 context 'when has attachments' do106 it { expect(email_object.mime_part!).not_to be_empty }107 end108 context 'when no attachments' do109 let(:another_message) { message.merge('id' => 32) }110 let(:email_object) { Howitzer::Email.adapter.new(another_message) }111 it do112 expect { email_object.mime_part! }.to raise_error(Howitzer::NoAttachmentsError, 'No attachments were found.')113 end114 end115 end116end...
email.rb
Source:email.rb
...4 # This class describes single email5 class Email6 include ::RSpec::Matchers7 attr_reader :message8 # @return [<MailAdapters::Abstract>] a mail adapter class9 def self.adapter10 return @adapter if @adapter11 self.adapter = Howitzer.mail_adapter.to_sym12 @adapter13 end14 class << self15 attr_reader :adapter_name16 protected17 # DSL method to specify a subject pattern directly in an email class18 # @param value [String] an email subject with optional placeholders (strings started with : symbol)19 # @example20 # class WelcomeEmail < Howitzer::Email21 # subject 'Welcome on board :name'22 # end23 #24 # WelcomeEmail.find_by_recipient('john.smith@example.com', name: 'John')25 # @!visibility public26 def subject(value)27 define_singleton_method(:subject_value) { value }28 private_class_method :subject_value29 end30 # DSL method to specify a custom wait email time directly in an email class31 # @param value [Integer] an wait time for a particular email.32 # If it is ommitted, default Howitzer.mail_wait_time will be used.33 # @example34 # class WelcomeEmail < Howitzer::Email35 # wait_time 10.minutes36 # end37 # @!visibility public38 def wait_time(value)39 define_singleton_method(:wait_time_value) { value }40 private_class_method :wait_time_value41 end42 end43 wait_time Howitzer.try(:mail_wait_time)44 # Specifies a mail adapter45 # @param adapter_name [String, Symbol] an email adapter name46 # @raise [NoMailAdapterError] when the adapter name is not String or Symbol47 def self.adapter=(adapter_name)48 @adapter_name = adapter_name49 case adapter_name50 when Symbol, String51 require "howitzer/mail_adapters/#{adapter_name}"52 @adapter = MailAdapters.const_get(adapter_name.to_s.capitalize.to_s)53 else54 raise Howitzer::NoMailAdapterError55 end56 end57 # Searches a mail by a recepient58 # @param recipient [String] recepient's email address59 # @param params [Hash] placeholders with appropriate values60 # @raise [NoEmailSubjectError] when a subject is not specified for the email class61 # @return [Email] an instance of the email message62 # @see .subject63 def self.find_by_recipient(recipient, params = {})64 if defined?(subject_value).nil? || subject_value.nil?65 raise Howitzer::NoEmailSubjectError, "Please specify email subject. For example:\n" \66 "class SomeEmail < Howitzer::Email\n " \67 "subject âsome subject textâ\nend"68 end69 new(adapter.find(recipient, expand_subject(params), wait: wait_time_value))70 end71 def initialize(message)72 @message = message73 end74 # @return [String, nil] a plain text of the email message75 def plain_text_body76 message.plain_text_body77 end78 # @return [String, nil] a html body of the email message79 def html_body80 message.html_body81 end82 # @return [String, nil] a mail text83 def text...
spyke.rb
Source:spyke.rb
...21 c.request :json22 c.response :json23 c.use TestTokenAuthentication24 c.use JSONParser25 c.adapter Faraday.default_adapter26end...
adapter
Using AI Code Generation
1def self.use(adapter_name)2 Howitzer::Web::Adapter.send(:include, Howitzer::Adapters::Watir)3def self.current=(adapter)4def self.browser=(browser)5def self.driver=(driver)6def self.context=(context)7def self.contexts=(contexts)8def self.context=(context)9def self.contexts=(contexts)10def self.context=(context)11def self.contexts=(contexts)12def self.context=(context)
adapter
Using AI Code Generation
1section = MySection.new(page, :xpath, '//div[@id="my_section"]')2section = MySection.new(page, :xpath, '//div[@id="my_section"]')3section = MySection.new(page, :xpath, '//div[@id="my_section"]')
adapter
Using AI Code Generation
1def self.use(adapter_name)2 Howitzer::Web::Adapter.send(:include, Howitzer::Adapters::Watir)3def self.current=(adapter)4def self.browser=(browser)5def self.driver=(driver)6def self.context=(context)7def self.contexts=(contexts)8def self.context=(context)9def self.contexts=(contexts)10def self.context=(context)11def self.contexts=(contexts)12def self.context=(context)
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!