Description
There are occasions when you need to assert that there were no specific elements rendered, currently this can be achieved with any of:
assert_select "element[attribute_1=?][attribute_2=?]", value_1, value_2, false
assert_select "element[attribute_1=?][attribute_2=?]", value_1, value_2, 0
assert_select "element[attribute_1=?][attribute_2=?]", value_1, value_2, 0..0
assert_select "element[attribute_1=?][attribute_2=?]", value_1, value_2, count: 0
assert_select "element[attribute_1=?][attribute_2=?]", value_1, value_2, maximum: 0
One downside of this is that it's not clear until you get to the end of the line that the assertion is for the inverse / lack of. This isn't as much of an issue when using Integer
, Range
, :count
or :maximum
with positive integers, as the assertion itself is for existence.
I'd like to propose introducing assert_not_dom
and its alias assert_not_select
which return true
if no elements are found ie they are an optional drop in replacement for my examples above:
assert_not_select "element[attribute_1=?][attribute_2=?]", value_1, value_2
I believe this pattern is consistent with other test helper pairs provided by ActiveSupport
(assert_not
, assert_not_nil
, assert_no_match
etc.).
Some vanity metrics:
- I found a few uses these negated assertions in the wild
- The monolith I work on has ~750 uses of these negated assertions. We also prefer
assert_not
overassert !
.
I would like to work on this if someone can confirm if the feature will be accepted.