4

We have an assertion in rails tests assert_in_array that is used to check if an element exists in an array. Is there any reverse assertion for it like assert_not_in_array?

3 Answers 3

14

There is no such assertion, however you could do this:

assert (not array.include? element)
Sign up to request clarification or add additional context in comments.

Comments

5

You might be looking for refute_includes

 refute_includes array_of_user_ids, user.id

http://apidock.com/ruby/v1_9_3_392/MiniTest/Assertions/refute_includes

Comments

2

another method is using assert_not_includes

so expanding on the answer from @drhenner, one could use:

assert_not_includes array_of_user_ids, user.id

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.