require 'test_helper' require 'rails/dom/testing/assertions/tag_assertions' HTML_TEST_OUTPUT = <
Name:
HTML class AssertTagTest < ActiveSupport::TestCase include Rails::Dom::Testing::Assertions::TagAssertions class FakeResponse attr_accessor :content_type, :body def initialize(content_type, body) @content_type, @body = content_type, body end end setup do @response = FakeResponse.new 'html', HTML_TEST_OUTPUT end def test_assert_tag_tag assert_deprecated do # there is a 'form' tag assert_tag tag: 'form' # there is not an 'hr' tag assert_no_tag tag: 'hr' end end def test_assert_tag_attributes assert_deprecated do # there is a tag with an 'id' of 'bar' assert_tag attributes: { id: "bar" } # there is no tag with a 'name' of 'baz' assert_no_tag attributes: { name: "baz" } end end def test_assert_tag_parent assert_deprecated do # there is a tag with a parent 'form' tag assert_tag parent: { tag: "form" } # there is no tag with a parent of 'input' assert_no_tag parent: { tag: "input" } end end def test_assert_tag_child assert_deprecated do # there is a tag with a child 'input' tag assert_tag child: { tag: "input" } # there is no tag with a child 'strong' tag assert_no_tag child: { tag: "strong" } end end def test_assert_tag_ancestor assert_deprecated do # there is a 'li' tag with an ancestor having an id of 'foo' assert_tag ancestor: { attributes: { id: "foo" } }, tag: "li" # there is no tag of any kind with an ancestor having an href matching 'foo' assert_no_tag ancestor: { attributes: { href: /foo/ } } end end def test_assert_tag_descendant assert_deprecated do # there is a tag with a descendant 'li' tag assert_tag descendant: { tag: "li" } # there is no tag with a descendant 'html' tag assert_no_tag descendant: { tag: "html" } end end def test_assert_tag_sibling assert_deprecated do # there is a tag with a sibling of class 'item' assert_tag sibling: { attributes: { class: "item" } } # there is no tag with a sibling 'ul' tag assert_no_tag sibling: { tag: "ul" } end end def test_assert_tag_after assert_deprecated do # there is a tag following a sibling 'div' tag assert_tag after: { tag: "div" } # there is no tag following a sibling tag with id 'bar' assert_no_tag after: { attributes: { id: "bar" } } end end def test_assert_tag_before assert_deprecated do # there is a tag preceding a tag with id 'bar' assert_tag before: { attributes: { id: "bar" } } # there is no tag preceding a 'form' tag assert_no_tag before: { tag: "form" } end end def test_assert_tag_children_count assert_deprecated do # there is a tag with 2 children assert_tag children: { count: 2 } # in particular, there is a