rails-dom-testing 1.0.9 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ceb2764b69e17058e7a8b7f0d0baf51285ba8f44
4
- data.tar.gz: edd0ef0b233fd1557841dcbee14e13ea77123c3e
3
+ metadata.gz: 61edc9fa5e40088f189be03e372c57a555e4794f
4
+ data.tar.gz: 6c0cde2f592e0fb52435d686c814907ef203ed97
5
5
  SHA512:
6
- metadata.gz: 2120964efb7a0514522dc818f3aacc0e29299eb98e486289837ed9c37ee3abfa8e04437e8a69f39409a60335b0c0b24bcf64b6df379b347361b4bd0d550daaac
7
- data.tar.gz: '08af44a82eef741e961ac56a730b3a25fce4fadcbd0186bf9846aec08971ceb100e0bae2bfcef19397c2b4437132b790d4140b075308ca0e7d32b0b5ecf1d09c'
6
+ metadata.gz: 529f62430db89db452a82c13ee2aa575c8e288a50923c6e954941805589431d4bb03a228eb6b9828afbe0ffb26f796d3007a948abaa08fc2b07b1364b5953526
7
+ data.tar.gz: 574f7c7d88a42632d46efa89ac038d0f154584aef74dc314075f09e9327d33e8d7fa42304864b74fa466bc01aa8eb3fe80112d3f094d02344d79b618d376117a
data/README.md CHANGED
@@ -1,5 +1,4 @@
1
1
  # Rails::Dom::Testing
2
- [![Build Status](https://travis-ci.org/rails/rails-dom-testing.svg)](https://travis-ci.org/rails/rails-dom-testing)
3
2
 
4
3
  This gem is responsible for comparing HTML doms and asserting that DOM elements are present in Rails applications.
5
4
  Doms are compared via `assert_dom_equal` and `assert_dom_not_equal`.
@@ -56,7 +55,7 @@ assert_select_encoded '#out-of-your-element'
56
55
  assert_select_email '#you-got-mail'
57
56
  ```
58
57
 
59
- The documentation in [selector_assertions.rb](https://github.com/kaspth/rails-dom-testing/blob/master/lib/rails/dom/testing/assertions/selector_assertions.rb) goes into a lot more detail of how selector assertions can be used.
58
+ The documentation in [selector_assertions.rb](https://github.com/rails/rails-dom-testing/blob/master/lib/rails/dom/testing/assertions/selector_assertions.rb) goes into a lot more detail of how selector assertions can be used.
60
59
 
61
60
  ## Read more
62
61
 
@@ -67,10 +66,12 @@ Under the hood the doms are parsed with Nokogiri and you'll generally be working
67
66
  Read more about Nokogiri:
68
67
  - [Nokogiri](http://nokogiri.org)
69
68
 
70
- ## Contributing
69
+ ## Contributing to Rails::Dom::Testing
71
70
 
72
- 1. Fork it
73
- 2. Create your feature branch (`git checkout -b my-new-feature`)
74
- 3. Commit your changes (`git commit -am 'Add some feature'`)
75
- 4. Push to the branch (`git push origin my-new-feature`)
76
- 5. Create new Pull Request
71
+ Rails::Dom::Testing is work of many contributors. You're encouraged to submit pull requests, propose
72
+ features and discuss issues.
73
+
74
+ See [CONTRIBUTING](CONTRIBUTING.md).
75
+
76
+ ## License
77
+ Rails::Dom::Testing is released under the [MIT License](MIT-LICENSE).
@@ -7,13 +7,11 @@ module Rails
7
7
  module Assertions
8
8
  autoload :DomAssertions, 'rails/dom/testing/assertions/dom_assertions'
9
9
  autoload :SelectorAssertions, 'rails/dom/testing/assertions/selector_assertions'
10
- autoload :TagAssertions, 'rails/dom/testing/assertions/tag_assertions'
11
10
 
12
11
  extend ActiveSupport::Concern
13
12
 
14
13
  include DomAssertions
15
14
  include SelectorAssertions
16
- include TagAssertions
17
15
  end
18
16
  end
19
17
  end
@@ -166,13 +166,14 @@ module Rails
166
166
 
167
167
  selector = HTMLSelector.new(args, @selected) { nodeset document_root_element }
168
168
 
169
- if selecting_no_body?(selector)
169
+ if selector.selecting_no_body?
170
170
  assert true
171
171
  return
172
172
  end
173
173
 
174
174
  selector.select.tap do |matches|
175
- assert_size_match!(matches.size, selector.tests, selector.selector, selector.message)
175
+ assert_size_match!(matches.size, selector.tests,
176
+ selector.css_selector, selector.message)
176
177
 
177
178
  nest_selection(matches, &block) if block_given? && !matches.empty?
178
179
  end
@@ -219,7 +220,9 @@ module Rails
219
220
  end
220
221
 
221
222
  content = nodeset(element || @selected).map do |elem|
222
- elem.children.select(&:cdata?).map(&:content)
223
+ elem.children.select do |child|
224
+ child.cdata? || (child.text? && !child.blank?)
225
+ end.map(&:content)
223
226
  end.join
224
227
 
225
228
  selected = Nokogiri::HTML::DocumentFragment.parse(content)
@@ -282,12 +285,6 @@ module Rails
282
285
  end
283
286
  end
284
287
 
285
- def selecting_no_body?(html_selector)
286
- # Nokogiri gives the document a body element. Which means we can't
287
- # run an assertion expecting there to not be a body.
288
- html_selector.selector == 'body' && html_selector.tests[:count] == 0
289
- end
290
-
291
288
  def nest_selection(selection)
292
289
  # Set @selected to allow nested assert_select.
293
290
  # Can be nested several levels deep.
@@ -2,12 +2,12 @@ require 'active_support/core_ext/module/attribute_accessors'
2
2
  require_relative 'substitution_context'
3
3
 
4
4
  class HTMLSelector #:nodoc:
5
- attr_reader :selector, :tests, :message
5
+ attr_reader :css_selector, :tests, :message
6
6
 
7
7
  def initialize(values, previous_selection = nil, &root_fallback)
8
8
  @values = values
9
9
  @root = extract_root(previous_selection, root_fallback)
10
- @selector = extract_selector
10
+ extract_selectors
11
11
  @tests = extract_equality_tests
12
12
  @message = @values.shift
13
13
 
@@ -16,8 +16,14 @@ class HTMLSelector #:nodoc:
16
16
  end
17
17
  end
18
18
 
19
+ def selecting_no_body? #:nodoc:
20
+ # Nokogiri gives the document a body element. Which means we can't
21
+ # run an assertion expecting there to not be a body.
22
+ @selector == 'body' && @tests[:count] == 0
23
+ end
24
+
19
25
  def select
20
- filter @root.css(selector, context)
26
+ filter @root.css(@selector, context)
21
27
  end
22
28
 
23
29
  private
@@ -67,16 +73,15 @@ class HTMLSelector #:nodoc:
67
73
  end
68
74
  end
69
75
 
70
- def extract_selector
76
+ def extract_selectors
71
77
  selector = @values.shift
72
78
 
73
79
  unless selector.is_a? String
74
80
  raise ArgumentError, "Expecting a selector as the first argument"
75
81
  end
76
82
 
77
- selector = selector.dup
78
- context.substitute!(selector, @values)
79
- selector
83
+ @css_selector = context.substitute!(selector, @values.dup, true)
84
+ @selector = context.substitute!(selector, @values)
80
85
  end
81
86
 
82
87
  def extract_equality_tests
@@ -3,10 +3,14 @@ class SubstitutionContext
3
3
  @substitute = '?'
4
4
  end
5
5
 
6
- def substitute!(selector, values)
6
+ def substitute!(selector, values, format_for_presentation = false)
7
+ selector = selector.dup
8
+
7
9
  while !values.empty? && substitutable?(values.first) && selector.index(@substitute)
8
- selector.sub! @substitute, matcher_for(values.shift)
10
+ selector.sub! @substitute, matcher_for(values.shift, format_for_presentation)
9
11
  end
12
+
13
+ selector
10
14
  end
11
15
 
12
16
  def match(matches, attribute, matcher)
@@ -14,8 +18,13 @@ class SubstitutionContext
14
18
  end
15
19
 
16
20
  private
17
- def matcher_for(value)
18
- value.to_s.inspect # Nokogiri doesn't like arbitrary values without quotes, hence inspect.
21
+ def matcher_for(value, format_for_presentation)
22
+ # Nokogiri doesn't like arbitrary values without quotes, hence inspect.
23
+ if format_for_presentation
24
+ value.inspect # Avoid to_s so Regexps aren't put in quotes.
25
+ else
26
+ value.to_s.inspect
27
+ end
19
28
  end
20
29
 
21
30
  def substitutable?(value)
@@ -1,7 +1,7 @@
1
1
  module Rails
2
2
  module Dom
3
3
  module Testing
4
- VERSION = "1.0.9"
4
+ VERSION = "2.0.0"
5
5
  end
6
6
  end
7
7
  end
@@ -18,11 +18,6 @@ class AssertSelectTest < ActiveSupport::TestCase
18
18
  # Test assert select.
19
19
  #
20
20
 
21
- def test_frozen_selector_substitution
22
- render_html %Q{<div id="1">foo</div><div id="2">foo</div>}
23
- assert_select "div:match('id', ?)".freeze, /\d+/
24
- end
25
-
26
21
  def test_assert_select
27
22
  render_html %Q{<div id="1"></div><div id="2"></div>}
28
23
  assert_select "div", 2
@@ -237,6 +232,16 @@ class AssertSelectTest < ActiveSupport::TestCase
237
232
  end
238
233
  end
239
234
 
235
+ def test_nested_assert_select_with_match_failure_shows_nice_regex
236
+ render_html %Q{<div id="1">foo</div>}
237
+
238
+ error = assert_raises Minitest::Assertion do
239
+ assert_select "div:match('id', ?)", /wups/
240
+ end
241
+
242
+ assert_match %Q{div:match('id', /wups/)}, error.message
243
+ end
244
+
240
245
  def test_feed_item_encoded
241
246
  render_xml <<-EOF
242
247
  <rss version="2.0">
@@ -250,9 +255,7 @@ class AssertSelectTest < ActiveSupport::TestCase
250
255
  </item>
251
256
  <item>
252
257
  <description>
253
- <![CDATA[
254
- <p>Test 2</p>
255
- ]]>
258
+ &lt;p&gt;Test 2&lt;/p&gt;
256
259
  </description>
257
260
  </item>
258
261
  </channel>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-dom-testing
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.9
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rafael Mendonça França
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-12-18 00:00:00.000000000 Z
12
+ date: 2016-05-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '1.6'
20
+ version: 1.6.0
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: '1.6'
27
+ version: 1.6.0
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: activesupport
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -34,7 +34,7 @@ dependencies:
34
34
  version: 4.2.0
35
35
  - - "<"
36
36
  - !ruby/object:Gem::Version
37
- version: '5.0'
37
+ version: '6.0'
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -44,21 +44,7 @@ dependencies:
44
44
  version: 4.2.0
45
45
  - - "<"
46
46
  - !ruby/object:Gem::Version
47
- version: '5.0'
48
- - !ruby/object:Gem::Dependency
49
- name: rails-deprecated_sanitizer
50
- requirement: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: 1.0.1
55
- type: :runtime
56
- prerelease: false
57
- version_requirements: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: 1.0.1
47
+ version: '6.0'
62
48
  - !ruby/object:Gem::Dependency
63
49
  name: bundler
64
50
  requirement: !ruby/object:Gem::Requirement
@@ -110,7 +96,6 @@ executables: []
110
96
  extensions: []
111
97
  extra_rdoc_files: []
112
98
  files:
113
- - LICENSE.txt
114
99
  - README.md
115
100
  - lib/rails-dom-testing.rb
116
101
  - lib/rails/dom/testing/assertions.rb
@@ -119,11 +104,9 @@ files:
119
104
  - lib/rails/dom/testing/assertions/selector_assertions/count_describable.rb
120
105
  - lib/rails/dom/testing/assertions/selector_assertions/html_selector.rb
121
106
  - lib/rails/dom/testing/assertions/selector_assertions/substitution_context.rb
122
- - lib/rails/dom/testing/assertions/tag_assertions.rb
123
107
  - lib/rails/dom/testing/version.rb
124
108
  - test/dom_assertions_test.rb
125
109
  - test/selector_assertions_test.rb
126
- - test/tag_assertions_test.rb
127
110
  - test/test_helper.rb
128
111
  homepage: https://github.com/rails/rails-dom-testing
129
112
  licenses:
@@ -145,12 +128,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
128
  version: '0'
146
129
  requirements: []
147
130
  rubyforge_project:
148
- rubygems_version: 2.6.12
131
+ rubygems_version: 2.5.1
149
132
  signing_key:
150
133
  specification_version: 4
151
134
  summary: Dom and Selector assertions for Rails applications
152
135
  test_files:
153
136
  - test/dom_assertions_test.rb
154
137
  - test/selector_assertions_test.rb
155
- - test/tag_assertions_test.rb
156
138
  - test/test_helper.rb
@@ -1,22 +0,0 @@
1
- Copyright (c) 2013 Kasper Timm Hansen
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,155 +0,0 @@
1
- require 'active_support/deprecation'
2
- require 'rails/deprecated_sanitizer/html-scanner'
3
-
4
- module Rails
5
- module Dom
6
- module Testing
7
- module Assertions
8
- # Pair of assertions to testing elements in the HTML output of the response.
9
- module TagAssertions
10
- # Asserts that there is a tag/node/element in the body of the response
11
- # that meets all of the given conditions. The +conditions+ parameter must
12
- # be a hash of any of the following keys (all are optional):
13
- #
14
- # * <tt>:tag</tt>: the node type must match the corresponding value
15
- # * <tt>:attributes</tt>: a hash. The node's attributes must match the
16
- # corresponding values in the hash.
17
- # * <tt>:parent</tt>: a hash. The node's parent must match the
18
- # corresponding hash.
19
- # * <tt>:child</tt>: a hash. At least one of the node's immediate children
20
- # must meet the criteria described by the hash.
21
- # * <tt>:ancestor</tt>: a hash. At least one of the node's ancestors must
22
- # meet the criteria described by the hash.
23
- # * <tt>:descendant</tt>: a hash. At least one of the node's descendants
24
- # must meet the criteria described by the hash.
25
- # * <tt>:sibling</tt>: a hash. At least one of the node's siblings must
26
- # meet the criteria described by the hash.
27
- # * <tt>:after</tt>: a hash. The node must be after any sibling meeting
28
- # the criteria described by the hash, and at least one sibling must match.
29
- # * <tt>:before</tt>: a hash. The node must be before any sibling meeting
30
- # the criteria described by the hash, and at least one sibling must match.
31
- # * <tt>:children</tt>: a hash, for counting children of a node. Accepts
32
- # the keys:
33
- # * <tt>:count</tt>: either a number or a range which must equal (or
34
- # include) the number of children that match.
35
- # * <tt>:less_than</tt>: the number of matching children must be less
36
- # than this number.
37
- # * <tt>:greater_than</tt>: the number of matching children must be
38
- # greater than this number.
39
- # * <tt>:only</tt>: another hash consisting of the keys to use
40
- # to match on the children, and only matching children will be
41
- # counted.
42
- # * <tt>:content</tt>: the textual content of the node must match the
43
- # given value. This will not match HTML tags in the body of a
44
- # tag--only text.
45
- #
46
- # Conditions are matched using the following algorithm:
47
- #
48
- # * if the condition is a string, it must be a substring of the value.
49
- # * if the condition is a regexp, it must match the value.
50
- # * if the condition is a number, the value must match number.to_s.
51
- # * if the condition is +true+, the value must not be +nil+.
52
- # * if the condition is +false+ or +nil+, the value must be +nil+.
53
- #
54
- # # Assert that there is a "span" tag
55
- # assert_tag tag: "span"
56
- #
57
- # # Assert that there is a "span" tag with id="x"
58
- # assert_tag tag: "span", attributes: { id: "x" }
59
- #
60
- # # Assert that there is a "span" tag using the short-hand
61
- # assert_tag :span
62
- #
63
- # # Assert that there is a "span" tag with id="x" using the short-hand
64
- # assert_tag :span, attributes: { id: "x" }
65
- #
66
- # # Assert that there is a "span" inside of a "div"
67
- # assert_tag tag: "span", parent: { tag: "div" }
68
- #
69
- # # Assert that there is a "span" somewhere inside a table
70
- # assert_tag tag: "span", ancestor: { tag: "table" }
71
- #
72
- # # Assert that there is a "span" with at least one "em" child
73
- # assert_tag tag: "span", child: { tag: "em" }
74
- #
75
- # # Assert that there is a "span" containing a (possibly nested)
76
- # # "strong" tag.
77
- # assert_tag tag: "span", descendant: { tag: "strong" }
78
- #
79
- # # Assert that there is a "span" containing between 2 and 4 "em" tags
80
- # # as immediate children
81
- # assert_tag tag: "span",
82
- # children: { count: 2..4, only: { tag: "em" } }
83
- #
84
- # # Get funky: assert that there is a "div", with an "ul" ancestor
85
- # # and an "li" parent (with "class" = "enum"), and containing a
86
- # # "span" descendant that contains text matching /hello world/
87
- # assert_tag tag: "div",
88
- # ancestor: { tag: "ul" },
89
- # parent: { tag: "li",
90
- # attributes: { class: "enum" } },
91
- # descendant: { tag: "span",
92
- # child: /hello world/ }
93
- #
94
- # <b>Please note</b>: +assert_tag+ and +assert_no_tag+ only work
95
- # with well-formed XHTML. They recognize a few tags as implicitly self-closing
96
- # (like br and hr and such) but will not work correctly with tags
97
- # that allow optional closing tags (p, li, td). <em>You must explicitly
98
- # close all of your tags to use these assertions.</em>
99
- def assert_tag(*opts)
100
- ActiveSupport::Deprecation.warn("assert_tag is deprecated and will be removed at Rails 5. Use assert_select to get the same feature.")
101
-
102
- opts = opts.size > 1 ? opts.last.merge({ tag: opts.first.to_s }) : opts.first
103
- tag = _find_tag(opts)
104
-
105
- assert tag, "expected tag, but no tag found matching #{opts.inspect} in:\n#{@response.body.inspect}"
106
- end
107
-
108
- # Identical to +assert_tag+, but asserts that a matching tag does _not_
109
- # exist. (See +assert_tag+ for a full discussion of the syntax.)
110
- #
111
- # # Assert that there is not a "div" containing a "p"
112
- # assert_no_tag tag: "div", descendant: { tag: "p" }
113
- #
114
- # # Assert that an unordered list is empty
115
- # assert_no_tag tag: "ul", descendant: { tag: "li" }
116
- #
117
- # # Assert that there is not a "p" tag with between 1 to 3 "img" tags
118
- # # as immediate children
119
- # assert_no_tag tag: "p",
120
- # children: { count: 1..3, only: { tag: "img" } }
121
- def assert_no_tag(*opts)
122
- ActiveSupport::Deprecation.warn("assert_no_tag is deprecated and will be removed at Rails 5. Use assert_select to get the same feature.")
123
-
124
- opts = opts.size > 1 ? opts.last.merge({ tag: opts.first.to_s }) : opts.first
125
- tag = _find_tag(opts)
126
-
127
- assert !tag, "expected no tag, but found tag matching #{opts.inspect} in:\n#{@response.body.inspect}"
128
- end
129
-
130
- def find_tag(conditions)
131
- ActiveSupport::Deprecation.warn("find_tag is deprecated and will be removed at Rails 5 without replacement.")
132
-
133
- _find_tag(conditions)
134
- end
135
-
136
- def find_all_tag(conditions)
137
- ActiveSupport::Deprecation.warn("find_all_tag is deprecated and will be removed at Rails 5 without replacement. Use assert_select to get the same feature.")
138
-
139
- html_scanner_document.find_all(conditions)
140
- end
141
-
142
- private
143
- def _find_tag(conditions)
144
- html_scanner_document.find(conditions)
145
- end
146
-
147
- def html_scanner_document
148
- xml = @response.content_type =~ /xml$/
149
- @html_scanner_document ||= HTML::Document.new(@response.body, false, xml)
150
- end
151
- end
152
- end
153
- end
154
- end
155
- end
@@ -1,218 +0,0 @@
1
- require 'test_helper'
2
- require 'rails/dom/testing/assertions/tag_assertions'
3
-
4
- HTML_TEST_OUTPUT = <<HTML
5
- <html>
6
- <body>
7
- <a href="/"><img src="/images/button.png" /></a>
8
- <div id="foo">
9
- <ul>
10
- <li class="item">hello</li>
11
- <li class="item">goodbye</li>
12
- </ul>
13
- </div>
14
- <div id="bar">
15
- <form action="/somewhere">
16
- Name: <input type="text" name="person[name]" id="person_name" />
17
- </form>
18
- </div>
19
- </body>
20
- </html>
21
- HTML
22
-
23
- class AssertTagTest < ActiveSupport::TestCase
24
- include Rails::Dom::Testing::Assertions::TagAssertions
25
-
26
- class FakeResponse
27
- attr_accessor :content_type, :body
28
-
29
- def initialize(content_type, body)
30
- @content_type, @body = content_type, body
31
- end
32
- end
33
-
34
- setup do
35
- @response = FakeResponse.new 'html', HTML_TEST_OUTPUT
36
- end
37
-
38
- def test_assert_tag_tag
39
- assert_deprecated do
40
- # there is a 'form' tag
41
- assert_tag tag: 'form'
42
- # there is not an 'hr' tag
43
- assert_no_tag tag: 'hr'
44
- end
45
- end
46
-
47
- def test_assert_tag_attributes
48
- assert_deprecated do
49
- # there is a tag with an 'id' of 'bar'
50
- assert_tag attributes: { id: "bar" }
51
- # there is no tag with a 'name' of 'baz'
52
- assert_no_tag attributes: { name: "baz" }
53
- end
54
- end
55
-
56
- def test_assert_tag_parent
57
- assert_deprecated do
58
- # there is a tag with a parent 'form' tag
59
- assert_tag parent: { tag: "form" }
60
- # there is no tag with a parent of 'input'
61
- assert_no_tag parent: { tag: "input" }
62
- end
63
- end
64
-
65
- def test_assert_tag_child
66
- assert_deprecated do
67
- # there is a tag with a child 'input' tag
68
- assert_tag child: { tag: "input" }
69
- # there is no tag with a child 'strong' tag
70
- assert_no_tag child: { tag: "strong" }
71
- end
72
- end
73
-
74
- def test_assert_tag_ancestor
75
- assert_deprecated do
76
- # there is a 'li' tag with an ancestor having an id of 'foo'
77
- assert_tag ancestor: { attributes: { id: "foo" } }, tag: "li"
78
- # there is no tag of any kind with an ancestor having an href matching 'foo'
79
- assert_no_tag ancestor: { attributes: { href: /foo/ } }
80
- end
81
- end
82
-
83
- def test_assert_tag_descendant
84
- assert_deprecated do
85
- # there is a tag with a descendant 'li' tag
86
- assert_tag descendant: { tag: "li" }
87
- # there is no tag with a descendant 'html' tag
88
- assert_no_tag descendant: { tag: "html" }
89
- end
90
- end
91
-
92
- def test_assert_tag_sibling
93
- assert_deprecated do
94
- # there is a tag with a sibling of class 'item'
95
- assert_tag sibling: { attributes: { class: "item" } }
96
- # there is no tag with a sibling 'ul' tag
97
- assert_no_tag sibling: { tag: "ul" }
98
- end
99
- end
100
-
101
- def test_assert_tag_after
102
- assert_deprecated do
103
- # there is a tag following a sibling 'div' tag
104
- assert_tag after: { tag: "div" }
105
- # there is no tag following a sibling tag with id 'bar'
106
- assert_no_tag after: { attributes: { id: "bar" } }
107
- end
108
- end
109
-
110
- def test_assert_tag_before
111
- assert_deprecated do
112
- # there is a tag preceding a tag with id 'bar'
113
- assert_tag before: { attributes: { id: "bar" } }
114
- # there is no tag preceding a 'form' tag
115
- assert_no_tag before: { tag: "form" }
116
- end
117
- end
118
-
119
- def test_assert_tag_children_count
120
- assert_deprecated do
121
- # there is a tag with 2 children
122
- assert_tag children: { count: 2 }
123
- # in particular, there is a <ul> tag with two children (a nameless pair of <li>s)
124
- assert_tag tag: 'ul', children: { count: 2 }
125
- # there is no tag with 4 children
126
- assert_no_tag children: { count: 4 }
127
- end
128
- end
129
-
130
- def test_assert_tag_children_less_than
131
- assert_deprecated do
132
- # there is a tag with less than 5 children
133
- assert_tag children: { less_than: 5 }
134
- # there is no 'ul' tag with less than 2 children
135
- assert_no_tag children: { less_than: 2 }, tag: "ul"
136
- end
137
- end
138
-
139
- def test_assert_tag_children_greater_than
140
- assert_deprecated do
141
- # there is a 'body' tag with more than 1 children
142
- assert_tag children: { greater_than: 1 }, tag: "body"
143
- # there is no tag with more than 10 children
144
- assert_no_tag children: { greater_than: 10 }
145
- end
146
- end
147
-
148
- def test_assert_tag_children_only
149
- assert_deprecated do
150
- # there is a tag containing only one child with an id of 'foo'
151
- assert_tag children: { count: 1,
152
- only: { attributes: { id: "foo" } } }
153
- # there is no tag containing only one 'li' child
154
- assert_no_tag children: { count: 1, only: { tag: "li" } }
155
- end
156
- end
157
-
158
- def test_assert_tag_content
159
- assert_deprecated do
160
- # the output contains the string "Name"
161
- assert_tag content: /Name/
162
- # the output does not contain the string "test"
163
- assert_no_tag content: /test/
164
- end
165
- end
166
-
167
- def test_assert_tag_multiple
168
- assert_deprecated do
169
- # there is a 'div', id='bar', with an immediate child whose 'action'
170
- # attribute matches the regexp /somewhere/.
171
- assert_tag tag: "div", attributes: { id: "bar" },
172
- child: { attributes: { action: /somewhere/ } }
173
-
174
- # there is no 'div', id='foo', with a 'ul' child with more than
175
- # 2 "li" children.
176
- assert_no_tag tag: "div", attributes: { id: "foo" },
177
- child: { tag: "ul",
178
- children: { greater_than: 2, only: { tag: "li" } } }
179
- end
180
- end
181
-
182
- def test_assert_tag_children_without_content
183
- assert_deprecated do
184
- # there is a form tag with an 'input' child which is a self closing tag
185
- assert_tag tag: "form",
186
- children: { count: 1,
187
- only: { tag: "input" } }
188
-
189
- # the body tag has an 'a' child which in turn has an 'img' child
190
- assert_tag tag: "body",
191
- children: { count: 1,
192
- only: { tag: "a",
193
- children: { count: 1,
194
- only: { tag: "img" } } } }
195
- end
196
- end
197
-
198
- def test_assert_tag_attribute_matching
199
- assert_deprecated do
200
- @response.body = '<input type="text" name="my_name">'
201
- assert_tag tag: 'input',
202
- attributes: { name: /my/, type: 'text' }
203
- assert_no_tag tag: 'input',
204
- attributes: { name: 'my', type: 'text' }
205
- assert_no_tag tag: 'input',
206
- attributes: { name: /^my$/, type: 'text' }
207
- end
208
- end
209
-
210
- def test_assert_tag_content_matching
211
- assert_deprecated do
212
- @response.body = "<p>hello world</p>"
213
- assert_tag tag: "p", content: "hello world"
214
- assert_tag tag: "p", content: /hello/
215
- assert_no_tag tag: "p", content: "hello"
216
- end
217
- end
218
- end