Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Capybara assertion support to Controller, Integration, Mailer, an…
…d View tests This commit introduces framework-specific configuration values: * `config.action_controller.assertions` for `ActionController::TestCase` * `config.action_dispatch.assertions` for `ActionDispatch::IntegrationTest` * `config.action_mailer.assertions` for `ActionMailer::TestCase` * `config.action_view.assertions` for `ActionView::TestCase` When set to `:capybara`, those tests include framework-scoped `CapybaraAssertions` modules that transitively include `Capybara::Minitest::Assertions`, and define the required `#page` method to parse the HTML into a `Capybara::Node::Simple` instance. When set to `:rails_dom_testing`, those tests include a framework-scoped `RailsDomTestingAssetrions` module to preserve the existing behavior. They all default to `:rails_dom_testing`.
- Loading branch information
1 parent
f7ac22a
commit 9f061c7
Showing
28 changed files
with
657 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# frozen_string_literal: true | ||
|
||
require "abstract_unit" | ||
|
||
class ActionMailer::CapybaraAssertionsTest < ActionMailer::TestCase | ||
class TestMailer < ActionMailer::Base | ||
def test(options) | ||
text, html = options.values_at(:text, :html) | ||
|
||
mail subject: "Test e-mail", from: "test@test.host", to: "test <test@test.host>" do |format| | ||
if text.present? | ||
format.text { render plain: text } | ||
end | ||
if html.present? | ||
format.html { render plain: html } | ||
end | ||
end | ||
end | ||
end | ||
|
||
include ActionView::CapybaraAssertions | ||
|
||
tests TestMailer | ||
|
||
test "assertions from last HTML delivery" do | ||
TestMailer.test(html: "<div><p>foo</p><p>bar</p></div>").deliver_now | ||
|
||
within_html_part do | ||
assert_css "div" do |div| | ||
assert_css div, "p", text: "foo" | ||
assert_css div, "p", text: "bar" | ||
end | ||
end | ||
end | ||
|
||
test "assertions from HTML instance" do | ||
mail = TestMailer.test(html: "<div><p>foo</p><p>bar</p></div>", text: "ignored") | ||
|
||
within_html_part mail do | ||
assert_css "div" do |div| | ||
assert_css div, "p", text: "foo" | ||
assert_css div, "p", text: "bar" | ||
end | ||
end | ||
end | ||
|
||
test "assertions from last multi-part delivery" do | ||
TestMailer.test(html: "<div><p>foo</p><p>bar</p></div>", text: "ignored").deliver_now | ||
|
||
within_html_part do | ||
assert_css "div" do |div| | ||
assert_css div, "p", text: "foo" | ||
assert_css div, "p", text: "bar" | ||
end | ||
end | ||
end | ||
|
||
test "assertions from multi-part instance" do | ||
mail = TestMailer.test(html: "<div><p>foo</p><p>bar</p></div>") | ||
|
||
within_html_part mail do | ||
assert_css "div" do |div| | ||
assert_css div, "p", text: "foo" | ||
assert_css div, "p", text: "bar" | ||
end | ||
end | ||
end | ||
|
||
test "fails when no HTML part" do | ||
mail = TestMailer.test(text: "ignored") | ||
|
||
assert_raises ArgumentError, match: "no HTML part in #{mail.inspect}" do | ||
within_html_part mail do | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 0 additions & 81 deletions
81
actionpack/lib/action_dispatch/testing/assertions/capybara.rb
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.