Permalink
Browse files

use assert_equal and assert_operator

  • Loading branch information...
tenderlove committed Jan 6, 2012
1 parent a0dc9ca commit 6548fc66178dd3d46e3a575e6937659c07293764
Showing with 8 additions and 5 deletions.
  1. +8 −5 actionpack/lib/action_dispatch/testing/assertions/selector.rb
@@ -270,7 +270,7 @@ def assert_select(*args, &block)
end
text.strip! unless NO_STRIP.include?(match.name)
unless match_with.is_a?(Regexp) ? (text =~ match_with) : (text == match_with.to_s)
- content_mismatch ||= build_message(message, "<?> expected but was\n<?>.", match_with, text)
+ content_mismatch ||= sprintf("<%s> expected but was\n<%s>.", match_with, text)
true
end
end
@@ -279,7 +279,7 @@ def assert_select(*args, &block)
html = match.children.map(&:to_s).join
html.strip! unless NO_STRIP.include?(match.name)
unless match_with.is_a?(Regexp) ? (html =~ match_with) : (html == match_with.to_s)
- content_mismatch ||= build_message(message, "<?> expected but was\n<?>.", match_with, html)
+ content_mismatch ||= sprintf("<%s> expected but was\n<%s>.", match_with, html)
true
end
end
@@ -289,12 +289,15 @@ def assert_select(*args, &block)
message ||= content_mismatch if matches.empty?
# Test minimum/maximum occurrence.
min, max, count = equals[:minimum], equals[:maximum], equals[:count]
+
+ # FIXME: minitest provides messaging when we use assert_operator,
+ # so is this custom message really needed?
message = message || %(Expected #{count_description(min, max, count)} matching "#{selector.to_s}", found #{matches.size}.)
if count
- assert matches.size == count, message
+ assert_equal matches.size, count, message

This comment has been minimized.

Show comment Hide comment
@abence

abence Mar 26, 2014

I believe this line should be

assert_equal count, assert_equal matches.size, message

Because the actual and expected parameters are swapped.

@abence

abence Mar 26, 2014

I believe this line should be

assert_equal count, assert_equal matches.size, message

Because the actual and expected parameters are swapped.

This comment has been minimized.

Show comment Hide comment
@robin850

robin850 Mar 26, 2014

Member

@abence : Yes you are right, this has been fixed in 9fccb3c so it will be included in the next non-security release of Rails. :-)

@robin850

robin850 Mar 26, 2014

Member

@abence : Yes you are right, this has been fixed in 9fccb3c so it will be included in the next non-security release of Rails. :-)

This comment has been minimized.

Show comment Hide comment
@abence

abence Mar 26, 2014

Cool thanks for letting me know. Then nothing else to do here :-)
BTW is there a quick way to figure out this sort of pending changes on a file without reading each commit? (maybe its a noob question). Something like blame but not in the past but in the future.

@abence

abence Mar 26, 2014

Cool thanks for letting me know. Then nothing else to do here :-)
BTW is there a quick way to figure out this sort of pending changes on a file without reading each commit? (maybe its a noob question). Something like blame but not in the past but in the future.

This comment has been minimized.

Show comment Hide comment
@robin850

robin850 Mar 26, 2014

Member

You can always watch the repository and read every single issue (but this is a lot of work). Otherwise, Godfrey Chan created an awesome newsletter with the last highlights on Rails master and in the Rails world in general. :-)

@robin850

robin850 Mar 26, 2014

Member

You can always watch the repository and read every single issue (but this is a lot of work). Otherwise, Godfrey Chan created an awesome newsletter with the last highlights on Rails master and in the Rails world in general. :-)

This comment has been minimized.

Show comment Hide comment
@abence

abence Mar 26, 2014

Yeah a bit more search on issues would have answer my original problem. But never mind at least I was digging in the source files what is a good thing. :-)
Thanks for the tip. I'm signing up right now.

@abence

abence Mar 26, 2014

Yeah a bit more search on issues would have answer my original problem. But never mind at least I was digging in the source files what is a good thing. :-)
Thanks for the tip. I'm signing up right now.

else
- assert matches.size >= min, message if min
- assert matches.size <= max, message if max
+ assert_operator matches.size, :>=, min, message if min
+ assert_operator matches.size, :<=, max, message if max
end
# If a block is given call that block. Set @selected to allow

0 comments on commit 6548fc6

Please sign in to comment.