提交 642bcd2d 编写于 作者: J Jeremy Kemper

Ruby 1.9 compat: force assert_select text encoding to the encoding of the...

Ruby 1.9 compat: force assert_select text encoding to the encoding of the regexp it's matching against.
上级 8af98c3f
...@@ -263,12 +263,15 @@ def assert_select(*args, &block) ...@@ -263,12 +263,15 @@ def assert_select(*args, &block)
if match_with = equals[:text] if match_with = equals[:text]
matches.delete_if do |match| matches.delete_if do |match|
text = "" text = ""
text.force_encoding(match_with.encoding) if text.respond_to?(:force_encoding)
stack = match.children.reverse stack = match.children.reverse
while node = stack.pop while node = stack.pop
if node.tag? if node.tag?
stack.concat node.children.reverse stack.concat node.children.reverse
else else
text << node.content content = node.content
content.force_encoding(match_with.encoding) if content.respond_to?(:force_encoding)
text << content
end end
end end
text.strip! unless NO_STRIP.include?(match.name) text.strip! unless NO_STRIP.include?(match.name)
......
...@@ -345,10 +345,17 @@ def test_assert_select_rjs_with_unicode ...@@ -345,10 +345,17 @@ def test_assert_select_rjs_with_unicode
page.replace "test", "<div id=\"1\">\343\203\201\343\202\261\343\203\203\343\203\210</div>" page.replace "test", "<div id=\"1\">\343\203\201\343\202\261\343\203\203\343\203\210</div>"
end end
assert_select_rjs do assert_select_rjs do
assert_select "#1", :text => "\343\203\201\343\202\261\343\203\203\343\203\210" str = "#1"
assert_select "#1", "\343\203\201\343\202\261\343\203\203\343\203\210" assert_select str, :text => "\343\203\201\343\202\261\343\203\203\343\203\210"
assert_select "#1", Regexp.new("\343\203\201..\343\203\210",0,'U') assert_select str, "\343\203\201\343\202\261\343\203\203\343\203\210"
assert_raises(AssertionFailedError) { assert_select "#1", Regexp.new("\343\203\201.\343\203\210",0,'U') } if str.respond_to?(:force_encoding)
str.force_encoding(Encoding::UTF_8)
assert_select str, /\343\203\201..\343\203\210/u
assert_raises(AssertionFailedError) { assert_select str, /\343\203\201.\343\203\210/u }
else
assert_select str, Regexp.new("\343\203\201..\343\203\210",0,'U')
assert_raises(AssertionFailedError) { assert_select str, Regexp.new("\343\203\201.\343\203\210",0,'U') }
end
end end
end end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册