1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #14728 from stomar/assertion-msg

Remove surplus period from assertion messages
This commit is contained in:
Yves Senn 2014-04-15 08:57:43 +02:00
commit 81678075f8
2 changed files with 16 additions and 14 deletions

View file

@ -267,7 +267,7 @@ module ActionDispatch
text.strip! unless NO_STRIP.include?(match.name) text.strip! unless NO_STRIP.include?(match.name)
text.sub!(/\A\n/, '') if match.name == "textarea" text.sub!(/\A\n/, '') if match.name == "textarea"
unless match_with.is_a?(Regexp) ? (text =~ match_with) : (text == match_with.to_s) unless match_with.is_a?(Regexp) ? (text =~ match_with) : (text == match_with.to_s)
content_mismatch ||= sprintf("<%s> expected but was\n<%s>.", match_with, text) content_mismatch ||= sprintf("<%s> expected but was\n<%s>", match_with, text)
true true
end end
end end
@ -276,7 +276,7 @@ module ActionDispatch
html = match.children.map(&:to_s).join html = match.children.map(&:to_s).join
html.strip! unless NO_STRIP.include?(match.name) html.strip! unless NO_STRIP.include?(match.name)
unless match_with.is_a?(Regexp) ? (html =~ match_with) : (html == match_with.to_s) unless match_with.is_a?(Regexp) ? (html =~ match_with) : (html == match_with.to_s)
content_mismatch ||= sprintf("<%s> expected but was\n<%s>.", match_with, html) content_mismatch ||= sprintf("<%s> expected but was\n<%s>", match_with, html)
true true
end end
end end
@ -289,7 +289,7 @@ module ActionDispatch
# FIXME: minitest provides messaging when we use assert_operator, # FIXME: minitest provides messaging when we use assert_operator,
# so is this custom message really needed? # so is this custom message really needed?
message = message || %(Expected #{count_description(min, max, count)} matching "#{selector.to_s}", found #{matches.size}.) message = message || %(Expected #{count_description(min, max, count)} matching "#{selector.to_s}", found #{matches.size})
if count if count
assert_equal count, matches.size, message assert_equal count, matches.size, message
else else

View file

@ -79,13 +79,13 @@ class AssertSelectTest < ActionController::TestCase
def test_assert_select def test_assert_select
render_html %Q{<div id="1"></div><div id="2"></div>} render_html %Q{<div id="1"></div><div id="2"></div>}
assert_select "div", 2 assert_select "div", 2
assert_failure(/Expected at least 1 element matching \"p\", found 0/) { assert_select "p" } assert_failure(/\AExpected at least 1 element matching \"p\", found 0\.$/) { assert_select "p" }
end end
def test_equality_integer def test_equality_integer
render_html %Q{<div id="1"></div><div id="2"></div>} render_html %Q{<div id="1"></div><div id="2"></div>}
assert_failure(/Expected exactly 3 elements matching \"div\", found 2/) { assert_select "div", 3 } assert_failure(/\AExpected exactly 3 elements matching \"div\", found 2\.$/) { assert_select "div", 3 }
assert_failure(/Expected exactly 0 elements matching \"div\", found 2/) { assert_select "div", 0 } assert_failure(/\AExpected exactly 0 elements matching \"div\", found 2\.$/) { assert_select "div", 0 }
end end
def test_equality_true_false def test_equality_true_false
@ -100,13 +100,14 @@ class AssertSelectTest < ActionController::TestCase
def test_equality_false_message def test_equality_false_message
render_html %Q{<div id="1"></div><div id="2"></div>} render_html %Q{<div id="1"></div><div id="2"></div>}
assert_failure(/Expected exactly 0 elements matching \"div\", found 2/) { assert_select "div", false } assert_failure(/\AExpected exactly 0 elements matching \"div\", found 2\.$/) { assert_select "div", false }
end end
def test_equality_string_and_regexp def test_equality_string_and_regexp
render_html %Q{<div id="1">foo</div><div id="2">foo</div>} render_html %Q{<div id="1">foo</div><div id="2">foo</div>}
assert_nothing_raised { assert_select "div", "foo" } assert_nothing_raised { assert_select "div", "foo" }
assert_raise(Assertion) { assert_select "div", "bar" } assert_raise(Assertion) { assert_select "div", "bar" }
assert_failure(/\A<bar> expected but was\n<foo>\.$/) { assert_select "div", "bar" }
assert_nothing_raised { assert_select "div", :text=>"foo" } assert_nothing_raised { assert_select "div", :text=>"foo" }
assert_raise(Assertion) { assert_select "div", :text=>"bar" } assert_raise(Assertion) { assert_select "div", :text=>"bar" }
assert_nothing_raised { assert_select "div", /(foo|bar)/ } assert_nothing_raised { assert_select "div", /(foo|bar)/ }
@ -124,6 +125,7 @@ class AssertSelectTest < ActionController::TestCase
assert_raise(Assertion) { assert_select "p", html } assert_raise(Assertion) { assert_select "p", html }
assert_nothing_raised { assert_select "p", :html=>html } assert_nothing_raised { assert_select "p", :html=>html }
assert_raise(Assertion) { assert_select "p", :html=>text } assert_raise(Assertion) { assert_select "p", :html=>text }
assert_failure(/\A<#{text}> expected but was\n<#{html}>\.$/) { assert_select "p", :html=>text }
# No stripping for pre. # No stripping for pre.
render_html %Q{<pre>\n<em>"This is <strong>not</strong> a big problem,"</em> he said.\n</pre>} render_html %Q{<pre>\n<em>"This is <strong>not</strong> a big problem,"</em> he said.\n</pre>}
text = "\n\"This is not a big problem,\" he said.\n" text = "\n\"This is not a big problem,\" he said.\n"
@ -144,29 +146,29 @@ class AssertSelectTest < ActionController::TestCase
def test_counts def test_counts
render_html %Q{<div id="1">foo</div><div id="2">foo</div>} render_html %Q{<div id="1">foo</div><div id="2">foo</div>}
assert_nothing_raised { assert_select "div", 2 } assert_nothing_raised { assert_select "div", 2 }
assert_failure(/Expected exactly 3 elements matching \"div\", found 2/) do assert_failure(/\AExpected exactly 3 elements matching \"div\", found 2\.$/) do
assert_select "div", 3 assert_select "div", 3
end end
assert_nothing_raised { assert_select "div", 1..2 } assert_nothing_raised { assert_select "div", 1..2 }
assert_failure(/Expected between 3 and 4 elements matching \"div\", found 2/) do assert_failure(/\AExpected between 3 and 4 elements matching \"div\", found 2\.$/) do
assert_select "div", 3..4 assert_select "div", 3..4
end end
assert_nothing_raised { assert_select "div", :count=>2 } assert_nothing_raised { assert_select "div", :count=>2 }
assert_failure(/Expected exactly 3 elements matching \"div\", found 2/) do assert_failure(/\AExpected exactly 3 elements matching \"div\", found 2\.$/) do
assert_select "div", :count=>3 assert_select "div", :count=>3
end end
assert_nothing_raised { assert_select "div", :minimum=>1 } assert_nothing_raised { assert_select "div", :minimum=>1 }
assert_nothing_raised { assert_select "div", :minimum=>2 } assert_nothing_raised { assert_select "div", :minimum=>2 }
assert_failure(/Expected at least 3 elements matching \"div\", found 2/) do assert_failure(/\AExpected at least 3 elements matching \"div\", found 2\.$/) do
assert_select "div", :minimum=>3 assert_select "div", :minimum=>3
end end
assert_nothing_raised { assert_select "div", :maximum=>2 } assert_nothing_raised { assert_select "div", :maximum=>2 }
assert_nothing_raised { assert_select "div", :maximum=>3 } assert_nothing_raised { assert_select "div", :maximum=>3 }
assert_failure(/Expected at most 1 element matching \"div\", found 2/) do assert_failure(/\AExpected at most 1 element matching \"div\", found 2\.$/) do
assert_select "div", :maximum=>1 assert_select "div", :maximum=>1
end end
assert_nothing_raised { assert_select "div", :minimum=>1, :maximum=>2 } assert_nothing_raised { assert_select "div", :minimum=>1, :maximum=>2 }
assert_failure(/Expected between 3 and 4 elements matching \"div\", found 2/) do assert_failure(/\AExpected between 3 and 4 elements matching \"div\", found 2\.$/) do
assert_select "div", :minimum=>3, :maximum=>4 assert_select "div", :minimum=>3, :maximum=>4
end end
end end
@ -204,7 +206,7 @@ class AssertSelectTest < ActionController::TestCase
end end
end end
assert_failure(/Expected at least 1 element matching \"#4\", found 0\./) do assert_failure(/\AExpected at least 1 element matching \"#4\", found 0\.$/) do
assert_select "div" do assert_select "div" do
assert_select "#4" assert_select "#4"
end end