简体   繁体   中英

Is `assert_equal … or assert_equal …` possible in ruby minitest?

I am creating a test that can be expressed as a disjunction of assertions; when the first assertion fails, then it should look at the next. Particularly, an item will be equal to one of two things. Which one, I do not know.

My code looks something like this. It does not work but it might give you an idea of what I am trying to do.

asset_one = Cache.asset_one
asset_two = Cache.asset_two

assert_equal(asset_one.name, Pages.name) or 
assert_equal(asset_two.name, Pages.name)

The Pages.name should match one of the targets. I don't know which one. If it doesn't match the first, then I want it to skip it and try to match the second.

Any help is as always much appreciated.

If you want to match any one of the object having the given name, you can use assert_includes

asset_one = Cache.asset_one
asset_two = Cache.asset_two

assert_includes([asset_one, asset_two].map(&:name), Pages.name)

This should solve your purpose.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM