Skip to content

Feature | Introduce assert_not_dom and its alias assert_not_select #112

Closed
@joshuay03

Description

@joshuay03

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 would like to work on this if someone can confirm if the feature will be accepted.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions