{"id":21988025,"url":"https://github.com/maxivak/test_email_redis","last_synced_at":"2026-04-17T05:02:53.291Z","repository":{"id":59157632,"uuid":"48701880","full_name":"maxivak/test_email_redis","owner":"maxivak","description":"Test emails using Redis","archived":false,"fork":false,"pushed_at":"2017-02-08T09:40:57.000Z","size":33,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-09T21:33:23.701Z","etag":null,"topics":["mail-delivery","testing"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/maxivak.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-12-28T16:38:27.000Z","updated_at":"2017-02-08T09:37:26.000Z","dependencies_parsed_at":"2022-09-13T17:52:11.875Z","dependency_job_id":null,"html_url":"https://github.com/maxivak/test_email_redis","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/maxivak/test_email_redis","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxivak%2Ftest_email_redis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxivak%2Ftest_email_redis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxivak%2Ftest_email_redis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxivak%2Ftest_email_redis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maxivak","download_url":"https://codeload.github.com/maxivak/test_email_redis/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxivak%2Ftest_email_redis/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269827272,"owners_count":24481494,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-11T02:00:10.019Z","response_time":75,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mail-delivery","testing"],"created_at":"2024-11-29T19:15:19.524Z","updated_at":"2026-04-17T05:02:53.285Z","avatar_url":"https://github.com/maxivak.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Test emails using Redis\nSimple gem for testing emails using Redis.\nIt is ready to test for asynchronous emails (using Sidekiq or Resque gems).\n\n## Overview\n\n\n## Usage\n\nGemfile:\n```\ngem 'test_email_redis'\n\n```\n\n### Application\n\nConfig gem:\n```\n# config/initializers/test_email_redis.rb\n\nTestEmailRedis.set_config({\n  redis_prefix: \"myapp_#{Rails.env}\",\n  field_user_id: :to\n})\n\n```\n\nConfigure mail delivery:\n```\n# config/environments/test.rb\n\nRails.application.configure do\n...\n\n    #\n    require 'test_email_redis/test_mail_delivery'\n    ActionMailer::Base.add_delivery_method :my_test_delivery, TestEmailRedis::TestMailDelivery\n    config.action_mailer.delivery_method = :my_test_delivery\n\nend\n\n```\n\n### Tests: RSpec3\n\nRequire helpers in your tests and configure\n```\n# spec_helper.rb or rspec_helper.rb\n\nrequire 'test_email_redis'\nrequire 'test_email_redis/helpers'\n\nTestEmailRedis.set_config({\n  redis_prefix: \"myapp_test\",\n  field_user_id: :to\n})\n\n```\n\n\nTest:\n```\nRSpec.describe \"Register user\", :type =\u003e :request do\n\n  describe 'register user' do\n\n    before :each do\n      # delete all emails if needed\n      TestEmailRedis::Helpers.clean_emails_all\n\n    end\n\n    after :each do\n      TestEmailRedis::Helpers.clean_emails_all\n    end\n\n\n    it 'sends email' do\n       # do smth that sends email\n\n       email = 'myuser@gmail.com'\n\n       #...\n       UsersMailer.welcome(email)\n\n       # check email is received\n       # by default, it will wait till the email is received\n       mail = TestEmailRedis::Helpers.get_last_email_for_user email\n\n       expect(mail).to be_truthy\n\n       # analyze mail content\n       html = mail['parts'][0]['body']\n       text = mail['parts'][1]['body']\n\n       expect(html).to match(/Welcome/)\n\n    end\n\n  end\nend\n\n\n```\n\n\n## Mail delivery\n\nThe gem provides custom mailers:\n* TestMailDelivery - add mail message to Redis\n* TestMailSmtpDelivery - add mail message to Redis and send via SMTP\n\nUse custom mail deliveries:\n```\n# config/environments/test.rb\n\nRails.application.configure do\n\nrequire 'test_email_redis/test_mail_delivery'\nActionMailer::Base.add_delivery_method :my_test_delivery, TestEmailRedis::TestMailDelivery\n# or\n# ActionMailer::Base.add_delivery_method :my_test_delivery, TestEmailRedis::TestMailSmtpDelivery\nconfig.action_mailer.delivery_method = :my_test_delivery\n\nend\n\n```\n\n\n\n## Test Helpers\n\n* TestEmailRedis::Helpers.get_last_email_for_user(user_id) - return the last email for user identified by user_id.\n```\nTestEmailRedis::get_last_email_for_user(user_id, wait=true, opts={})\n\n```\n\n\nExamples:\n\n```\n# do not wait for message\nmail = TestEmailRedis::Helpers.get_last_email_for_user(user_id, false)\n\n\n```\n\n* TestEmailRedis::n_emails_for_user(user_id) - number of emails for user\n* TestEmailRedis::wait_for_new_email_for_user(user_id) - just waits till a new message arrived\n\n* TestEmailRedis::clean_emails_all - delete all emails\n* TestEmailRedis::clean_emails_for_user - delete all emails for the user\n\n\n* TestEmailRedis::add_email_to_redis(mail) - adds email to Redis\n\n\n\n## Config options\n\n* field_user_id - field used to identify user by mail message. By default, :to which means what user_id = mail.to\n\n\n## Redis\n\nData stored in Redis:\n\n```\n\u003credis_prefix\u003e:emails:content - hash with email contents: {mail_id: content, ..}\n\u003credis_prefix\u003e:emails:by_user:\u003cuser_id\u003e - list of mail message IDs for the user: [id1, id2, id3,..]\n```\n\n## Examples\n\n### Example. Get last email\n\n```\nemail = 'myuser@gmail.com'\n\n# emails could be already for the user\nn_old = TestEmailRedis::Helpers.n_emails_for_user email\n\n# do smth which might send email\nUsersMailer.welcome(email)\n\n# wait for a new message\nmail = TestEmailRedis::Helpers.get_last_email_for_user email, true, {n_old_emails: n_old}\n\n# ***WARNING!***\n# Do not use TestEmailRedis::Helpers.get_last_email_for_user(email) - it might return an old email currently available in Redis.\n# It will not work is asynchronous emails are used\n\n```\n\nor if you don't need old emails - just delete them before sending a new email:\n\n```\nemail = 'myuser@gmail.com'\n\n# emails could be already for the user\nTestEmailRedis::Helpers.clean_emails_for_user email\n\n# do smth which might send email\nUsersMailer.welcome(email)\n\n# wait for a new message\nmail = TestEmailRedis::Helpers.get_last_email_for_user email\n\n```\n\n\n### Example. Multiple emails in one test example\n\n\nMultiple emails:\n```\nemail = 'myuser@gmail.com'\n\n# emails could be already for the user\nn_old = TestEmailRedis::Helpers.n_emails_for_user email\n\n# do smth which might send email\nUsersMailer.welcome(email)\n# so smth else\n# send another email\nUsersMailer.newsletter(email)\n\n# for now, two emails has been sent.\n\n# wait for a second message to arrive\nmail = TestEmailRedis::Helpers.get_last_email_for_user email, true, {n_old_emails: n_old+1}\n\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxivak%2Ftest_email_redis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaxivak%2Ftest_email_redis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxivak%2Ftest_email_redis/lists"}