![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Easily test ActionMailer and Mail messages in your Capybara integration tests
Add this line to your application's Gemfile:
gem 'capybara-email'
And then execute:
$ bundle
Or install it yourself as:
$ gem install capybara-email
In your spec_helper.rb
require capybara/email/rspec
.
require 'capybara/email/rspec'
Example:
feature 'Emailer' do
background do
# will clear the message queue
clear_emails
visit email_trigger_path
# Will find an email sent to test@example.com
# and set `current_email`
open_email('test@example.com')
end
scenario 'following a link' do
current_email.click_link 'your profile'
expect(page).to have_content 'Profile page'
end
scenario 'testing for content' do
expect(current_email).to have_content 'Hello Joe!'
end
scenario 'testing for attachments' do
expect(current_email.attachments.first.filename).to eq 'filename.csv'
end
scenario 'testing for a custom header' do
expect(current_email.headers).to include 'header-key'
end
scenario 'testing for a custom header value' do
expect(current_email.header('header-key')).to eq 'header_value'
end
scenario 'view the email body in your browser' do
# the `launchy` gem is required
current_email.save_and_open
end
end
Require capybara/email
in your features/support/env.rb
require 'capybara/email'
Once you have required capybara-email
, gaining access to usable methods
is easy as adding this module to your Cucumber World
:
World(Capybara::Email::DSL)
I recommend adding this to a support file such as features/support/capybara_email.rb
require 'capybara/email'
World(Capybara::Email::DSL)
Example:
Scenario: Email is sent to winning user
Given "me@example.com" is playing a game
When that user picks a winning piece
Then "me@example.com" receives an email with "You've Won!" as the subject
Then /^"([^"]*)" receives an email with "([^"]*)" as the subject$/ do |email_address, subject|
open_email(email_address)
expect(current_email.subject).to eq subject
end
Require capybara/email
at the top of test/test_helper.rb
require 'capybara/email'
Include Capybara::Email::DSL
in your test class
class ActionDispatch::IntegrationTest
include Capybara::Email::DSL
end
Example:
class EmailTriggerControllerTest < ActionDispatch::IntegrationTest
def setup
# will clear the message queue
clear_emails
visit email_trigger_path
# Will find an email sent to `test@example.com`
# and set `current_email`
open_email('test@example.com')
end
test 'following a link' do
current_email.click_link 'your profile'
expect(page).to have_content 'Profile page'
end
test 'testing for content' do
expect(current_email).to have_content 'Hello Joe!'
end
test 'testing for a custom header' do
expect(current_email.headers).to include 'header-key'
end
test 'testing for a custom header value' do
expect(current_email.header('header-key')).to eq 'header_value'
end
test 'view the email body in your browser' do
# the `launchy` gem is required
current_email.save_and_open
end
end
The current_email
method will delegate all necessary method calls to
Mail::Message
. So if you need to access the subject of an email:
current_email.subject
Check out API for the mail
gem for details on what methods are
available.
When testing, it's common to want to open an email and click through to your application. To do this, you'll probably need to update your test environment, as well as Capybara's configuration.
By default, Capybara's app_host
is set to
http://example.com.
You should update this so that it points to the
same host as your test environment. In our example, we'll update both to
http://localhost:3001
:
# tests/test_helper.rb
ActionDispatch::IntegrationTest do
Capybara.server_port = 3001
Capybara.app_host = 'http://localhost:3001'
end
# config/environments/test.rb
config.action_mailer.default_url_options = { host: 'localhost',
port: 3001 }
Sending emails asynchronously will cause #open_email
to not open the
correct email or not find any email at all depending on the state of the
email queue. We recommend forcing a sleep prior to trying to read any
email after an asynchronous event:
click_link 'Send email'
sleep 0.1
open_email 'test@example.com'
We are very thankful for the many contributors
This gem follows Semantic Versioning
Stable branches are created based upon each minor version. Please make pull requests to specific branches rather than master.
Please make sure you include tests!
Don't use tabs to indent, two spaces are the standard.
DockYard, Inc. © 2014
FAQs
Unknown package
We found that capybara-email demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.