rails-dom-testing 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/rails/dom/testing/assertions/dom_assertions.rb +2 -1
- data/lib/rails/dom/testing/assertions/selector_assertions.rb +10 -12
- data/lib/rails/dom/testing/assertions/selector_assertions/html_selector.rb +1 -0
- data/lib/rails/dom/testing/assertions/selector_assertions/substitution_context.rb +19 -17
- data/lib/rails/dom/testing/version.rb +1 -1
- data/test/dom_assertions_test.rb +7 -0
- data/test/selector_assertions_test.rb +21 -0
- data/test/test_helper.rb +1 -0
- metadata +3 -5
- data/CHANGELOG.md +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44d4f14bd073cd6863e98c91e68cdd0841b79f03
|
4
|
+
data.tar.gz: 52bfa7441b482a26893322386ec0774542153804
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75a264e23323a077ae8a5d73e3f356689b7eb48d7a35e75cecce81c74423ba8b638d75dca49c593252acd18de4de6e3f1b6cd0b3e8db9e669a421b0e76339a1c
|
7
|
+
data.tar.gz: 36b2b12547bca87796e856f01684af0895a97239f649fa7e40cf66c4f49732b23965d425ce38b87f3acd8ff7703a94c528488e888342b856063141bd5d5a3df6
|
data/README.md
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
This gem is responsible for comparing HTML doms and asserting that DOM elements are present in Rails applications.
|
5
5
|
Doms are compared via `assert_dom_equal` and `assert_dom_not_equal`.
|
6
6
|
Elements are asserted via `assert_select`, `assert_select_encoded`, `assert_select_email` and a subset of the dom can be selected with `css_select`.
|
7
|
+
The gem is developed for Rails 4.2 and above, and will not work on previous versions.
|
7
8
|
|
8
9
|
|
9
10
|
## Installation
|
@@ -40,7 +40,8 @@ module Rails
|
|
40
40
|
|
41
41
|
if child.element?
|
42
42
|
child.name == other_child.name &&
|
43
|
-
equal_attribute_nodes?(child.attribute_nodes, other_child.attribute_nodes)
|
43
|
+
equal_attribute_nodes?(child.attribute_nodes, other_child.attribute_nodes) &&
|
44
|
+
compare_doms(child, other_child)
|
44
45
|
else
|
45
46
|
child.to_s == other_child.to_s
|
46
47
|
end
|
@@ -61,8 +61,11 @@ module Rails
|
|
61
61
|
root = args.size == 1 ? document_root_element : args.shift
|
62
62
|
selector = args.first
|
63
63
|
|
64
|
-
|
64
|
+
begin
|
65
65
|
nodeset(root).css(selector)
|
66
|
+
rescue Nokogiri::CSS::SyntaxError => e
|
67
|
+
ActiveSupport::Deprecation.warn("The assertion was not run because of an invalid css selector.\n#{e}", caller(2))
|
68
|
+
return
|
66
69
|
end
|
67
70
|
end
|
68
71
|
|
@@ -167,10 +170,14 @@ module Rails
|
|
167
170
|
selector = HTMLSelector.new(root, args)
|
168
171
|
|
169
172
|
matches = nil
|
170
|
-
|
173
|
+
|
174
|
+
begin
|
171
175
|
matches = selector.select
|
172
176
|
|
173
177
|
assert_size_match!(matches.size, selector.equality_tests, selector.source, selector.message)
|
178
|
+
rescue Nokogiri::CSS::SyntaxError => e
|
179
|
+
ActiveSupport::Deprecation.warn("The assertion was not run because of an invalid css selector.\n#{e}", caller(2))
|
180
|
+
return
|
174
181
|
end
|
175
182
|
|
176
183
|
nest_selection(matches, &block) if block_given? && !matches.empty?
|
@@ -278,15 +285,6 @@ module Rails
|
|
278
285
|
raise NotImplementedError, "Implementing document_root_element makes assert_select work without needing to specify an element to select from."
|
279
286
|
end
|
280
287
|
|
281
|
-
def catch_invalid_selector
|
282
|
-
begin
|
283
|
-
yield
|
284
|
-
rescue Nokogiri::CSS::SyntaxError => e
|
285
|
-
ActiveSupport::Deprecation.warn("The assertion was not run because of an invalid css selector.\n#{e}")
|
286
|
-
return
|
287
|
-
end
|
288
|
-
end
|
289
|
-
|
290
288
|
# +equals+ must contain :minimum, :maximum and :count keys
|
291
289
|
def assert_size_match!(size, equals, css_selector, message = nil)
|
292
290
|
min, max, count = equals[:minimum], equals[:maximum], equals[:count]
|
@@ -310,7 +308,7 @@ module Rails
|
|
310
308
|
elsif previous_selection
|
311
309
|
previous_selection
|
312
310
|
else
|
313
|
-
document_root_element
|
311
|
+
nodeset document_root_element
|
314
312
|
end
|
315
313
|
end
|
316
314
|
|
@@ -1,28 +1,30 @@
|
|
1
1
|
class SubstitutionContext
|
2
|
-
def initialize
|
3
|
-
@substitute =
|
2
|
+
def initialize
|
3
|
+
@substitute = '?'
|
4
4
|
@regexes = []
|
5
5
|
end
|
6
6
|
|
7
|
-
def
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
last_id.to_s # avoid implicit conversions of Fixnum to String
|
7
|
+
def substitute!(selector, values)
|
8
|
+
while !values.empty? && substitutable?(values.first) && selector.index(@substitute)
|
9
|
+
selector.sub! @substitute, substitution_id_for(values.shift)
|
10
|
+
end
|
12
11
|
end
|
13
12
|
|
14
|
-
def
|
15
|
-
@regexes
|
13
|
+
def match(matches, attribute, substitution_id)
|
14
|
+
matches.find_all { |node| node[attribute] =~ @regexes[substitution_id] }
|
16
15
|
end
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
private
|
18
|
+
def substitution_id_for(value)
|
19
|
+
if value.is_a?(Regexp)
|
20
|
+
@regexes << value
|
21
|
+
@regexes.size - 1
|
22
|
+
else
|
23
|
+
value
|
24
|
+
end.inspect # Nokogiri doesn't like arbitrary values without quotes, hence inspect.
|
25
|
+
end
|
21
26
|
|
22
|
-
|
23
|
-
|
24
|
-
selector.sub!(@substitute, add_regex(values.shift))
|
27
|
+
def substitutable?(value)
|
28
|
+
value.is_a?(String) || value.is_a?(Regexp)
|
25
29
|
end
|
26
|
-
selector
|
27
|
-
end
|
28
30
|
end
|
data/test/dom_assertions_test.rb
CHANGED
@@ -40,6 +40,14 @@ class AssertSelectTest < ActiveSupport::TestCase
|
|
40
40
|
assert_nothing_raised { assert_select "p", false }
|
41
41
|
end
|
42
42
|
|
43
|
+
def test_equality_false_with_substitution
|
44
|
+
render_html %{<a></a>}
|
45
|
+
|
46
|
+
assert_nothing_raised do
|
47
|
+
assert_select %{a[href="http://example.org?query=value"]}, false
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
43
51
|
def test_equality_false_message
|
44
52
|
render_html %Q{<div id="1"></div><div id="2"></div>}
|
45
53
|
assert_failure(/Expected exactly 0 elements matching \"div\", found 2/) { assert_select "div", false }
|
@@ -127,6 +135,18 @@ class AssertSelectTest < ActiveSupport::TestCase
|
|
127
135
|
end
|
128
136
|
end
|
129
137
|
|
138
|
+
def test_assert_select_root_html
|
139
|
+
render_html '<a></a>'
|
140
|
+
|
141
|
+
assert_select 'a'
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_assert_select_root_xml
|
145
|
+
render_xml '<rss version="2.0"></rss>'
|
146
|
+
|
147
|
+
assert_select 'rss'
|
148
|
+
end
|
149
|
+
|
130
150
|
def test_nested_assert_select
|
131
151
|
render_html %Q{<div id="1">foo</div><div id="2">foo</div>}
|
132
152
|
assert_select "div" do |elements|
|
@@ -233,6 +253,7 @@ class AssertSelectTest < ActiveSupport::TestCase
|
|
233
253
|
</channel>
|
234
254
|
</rss>
|
235
255
|
EOF
|
256
|
+
|
236
257
|
assert_select "channel item description" do
|
237
258
|
|
238
259
|
assert_select_encoded do
|
data/test/test_helper.rb
CHANGED
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.
|
4
|
+
version: 1.0.3
|
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: 2014-
|
12
|
+
date: 2014-09-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
@@ -103,7 +103,6 @@ executables: []
|
|
103
103
|
extensions: []
|
104
104
|
extra_rdoc_files: []
|
105
105
|
files:
|
106
|
-
- CHANGELOG.md
|
107
106
|
- LICENSE.txt
|
108
107
|
- README.md
|
109
108
|
- lib/rails-dom-testing.rb
|
@@ -138,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
137
|
version: '0'
|
139
138
|
requirements: []
|
140
139
|
rubyforge_project:
|
141
|
-
rubygems_version: 2.
|
140
|
+
rubygems_version: 2.2.2
|
142
141
|
signing_key:
|
143
142
|
specification_version: 4
|
144
143
|
summary: This gem can compare doms and assert certain elements exists in doms using
|
@@ -148,4 +147,3 @@ test_files:
|
|
148
147
|
- test/selector_assertions_test.rb
|
149
148
|
- test/tag_assertions_test.rb
|
150
149
|
- test/test_helper.rb
|
151
|
-
has_rdoc:
|