{"id":13880277,"url":"https://github.com/DavyJonesLocker/capybara-email","last_synced_at":"2025-07-16T16:31:28.786Z","repository":{"id":2630093,"uuid":"3617188","full_name":"DavyJonesLocker/capybara-email","owner":"DavyJonesLocker","description":"Test your ActionMailer and Mailer messages with Capybara","archived":false,"fork":false,"pushed_at":"2021-07-30T18:24:53.000Z","size":127,"stargazers_count":341,"open_issues_count":4,"forks_count":53,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-07-07T21:38:54.120Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/DavyJonesLocker.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-03-04T09:34:56.000Z","updated_at":"2025-06-02T01:59:17.000Z","dependencies_parsed_at":"2022-07-10T19:20:02.639Z","dependency_job_id":null,"html_url":"https://github.com/DavyJonesLocker/capybara-email","commit_stats":null,"previous_names":["dockyard/capybara-email"],"tags_count":24,"template":false,"template_full_name":null,"purl":"pkg:github/DavyJonesLocker/capybara-email","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DavyJonesLocker%2Fcapybara-email","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DavyJonesLocker%2Fcapybara-email/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DavyJonesLocker%2Fcapybara-email/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DavyJonesLocker%2Fcapybara-email/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DavyJonesLocker","download_url":"https://codeload.github.com/DavyJonesLocker/capybara-email/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DavyJonesLocker%2Fcapybara-email/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265524632,"owners_count":23782016,"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","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":[],"created_at":"2024-08-06T08:02:54.619Z","updated_at":"2025-07-16T16:31:28.452Z","avatar_url":"https://github.com/DavyJonesLocker.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"# CapybaraEmail #\n\n[![Build Status](https://travis-ci.org/DavyJonesLocker/capybara-email.svg?branch=master)](https://travis-ci.org/DavyJonesLocker/capybara-email)\n[![Code Climate](https://d3s6mut3hikguw.cloudfront.net/github/dockyard/capybara-email.svg)](https://codeclimate.com/github/dockyard/capybara-email)\n\nEasily test [ActionMailer](https://github.com/rails/rails/tree/master/actionmailer) and [Mail](https://github.com/mikel/mail) messages in your Capybara integration tests\n\n## Installation ##\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'capybara-email'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install capybara-email\n\n## Usage ##\n\n### RSpec ###\n\nIn your `spec_helper.rb` require `capybara/email/rspec`.\n\n```ruby\nrequire 'capybara/email/rspec'\n```\n\nExample:\n\n```ruby\nfeature 'Emailer' do\n  background do\n    # will clear the message queue\n    clear_emails\n    visit email_trigger_path\n    # Will find an email sent to test@example.com\n    # and set `current_email`\n    open_email('test@example.com')\n  end\n\n  scenario 'following a link' do\n    current_email.click_link 'your profile'\n    expect(page).to have_content 'Profile page'\n  end\n\n  scenario 'testing for content' do\n    expect(current_email).to have_content 'Hello Joe!'\n  end\n\n  scenario 'testing for attachments' do\n    expect(current_email.attachments.first.filename).to eq 'filename.csv'\n  end\n\n  scenario 'testing for a custom header' do\n    expect(current_email.headers).to include 'header-key'\n  end\n\n  scenario 'testing for a custom header value' do\n    expect(current_email.header('header-key')).to eq 'header_value'\n  end\n\n  scenario 'view the email body in your browser' do\n    # the `launchy` gem is required\n    current_email.save_and_open\n  end\nend\n```\n\n### Cucumber ###\nRequire `capybara/email` in your `features/support/env.rb`\n\n    require 'capybara/email'\n\nOnce you have required `capybara-email`, gaining access to usable methods\nis easy as adding this module to your Cucumber `World`:\n\n    World(Capybara::Email::DSL)\n\nI recommend adding this to a support file such as `features/support/capybara_email.rb`\n\n```ruby\nrequire 'capybara/email'\nWorld(Capybara::Email::DSL)\n```\n\nExample:\n\n```ruby\nScenario: Email is sent to winning user\n  Given \"me@example.com\" is playing a game\n  When that user picks a winning piece\n  Then \"me@example.com\" receives an email with \"You've Won!\" as the subject\n\nThen /^\"([^\"]*)\" receives an email with \"([^\"]*)\" as the subject$/ do |email_address, subject|\n  open_email(email_address)\n  expect(current_email.subject).to eq subject\nend\n```\n\n### Test::Unit ###\n\nRequire `capybara/email` at the top of `test/test_helper.rb`\n\n```ruby\n  require 'capybara/email'\n```\n\nInclude `Capybara::Email::DSL` in your test class\n\n```ruby\nclass ActionDispatch::IntegrationTest\n  include Capybara::Email::DSL\nend\n```\n\nExample:\n\n```ruby\nclass EmailTriggerControllerTest \u003c ActionDispatch::IntegrationTest\n  def setup\n    # will clear the message queue\n    clear_emails\n    visit email_trigger_path\n\n    # Will find an email sent to `test@example.com`\n    # and set `current_email`\n    open_email('test@example.com')\n  end\n\n  test 'testing any email is sent' do\n    expect(all_emails).not_to be_empty\n  end\n\n  test 'following a link' do\n    current_email.click_link 'your profile'\n    expect(page).to have_content 'Profile page'\n  end\n\n  test 'testing for content' do\n    expect(current_email).to have_content 'Hello Joe!'\n  end\n\n  test 'testing for a custom header' do\n    expect(current_email.headers).to include 'header-key'\n  end\n\n  test 'testing for a custom header value' do\n    expect(current_email.header('header-key')).to eq 'header_value'\n  end\n\n  test 'view the email body in your browser' do\n    # the `launchy` gem is required\n    current_email.save_and_open\n  end\nend\n```\n\n### CurrentEmail API ###\n\nThe `current_email` method will delegate all necessary method calls to\n`Mail::Message`. So if you need to access the subject of an email:\n\n```ruby\ncurrent_email.subject\n```\n\nCheck out API for the `mail` gem for details on what methods are\navailable.\n\n## Setting your test host\nWhen testing, it's common to want to open an email and click through to your\napplication. To do this, you'll probably need to update your test\nenvironment, as well as Capybara's configuration.\n\nBy default, Capybara's `app_host` is set to\n`http://example.com.` You should update this so that it points to the\nsame host as your test environment. In our example, we'll update both to\n`http://localhost:3001`:\n\n```ruby\n# tests/test_helper.rb\nActionDispatch::IntegrationTest do\n  Capybara.server_port = 3001\n  Capybara.app_host = 'http://localhost:3001'\nend\n\n# config/environments/test.rb\nconfig.action_mailer.default_url_options = { host: 'localhost', \n                                             port: 3001 }\n```\n\n## Sending Emails with JavaScript ##\nSending emails asynchronously will cause `#open_email` to not open the\ncorrect email or not find any email at all depending on the state of the\nemail queue. We recommend forcing a sleep prior to trying to read any\nemail after an asynchronous event:\n\n```ruby\nclick_link 'Send email'\nsleep 0.1\nopen_email 'test@example.com'\n```\n\n## Authors ##\n\n[Brian Cardarella](http://twitter.com/bcardarella)\n\n[We are very thankful for the many contributors](https://github.com/dockyard/capybara-email/graphs/contributors)\n\n## Versioning ##\n\nThis gem follows [Semantic Versioning](http://semver.org)\n\n## Want to help? ##\n\nStable branches are created based upon each minor version. Please make\npull requests to specific branches rather than master.\n\nPlease make sure you include tests!\n\nDon't use tabs to indent, two spaces are the standard.\n\n## Legal ##\n\n[DockYard](http://dockyard.com), Inc. \u0026copy; 2014\n\n[@dockyard](http://twitter.com/dockyard)\n\n[Licensed under the MIT license](http://www.opensource.org/licenses/mit-license.php)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDavyJonesLocker%2Fcapybara-email","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FDavyJonesLocker%2Fcapybara-email","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDavyJonesLocker%2Fcapybara-email/lists"}