Edit: Compound matcher answer provided is a much more elegant solution:
expect(@weathers.get_day_today).to eq('Today').or eq('Tonight')
Original Question:
I am testing if a value is either "Today" or "Tonight". Is there a built-in matcher? Or a cleaner method than what I'm doing?
Edit: The following was my attempt to do a custom test, but it doesn't work. Here's an example of what NOT to do.
First, add custom-matcher.
RSpec::Matchers.define :be_this_or_that do |expected|
match do |actual|
actual == expected.first or expected.last
end
end
Second, use it
expect(@weathers.get_day_today).to be_this_or_that(["Today", "Tonight"])
You can try like this:
expect(@weathers.get_day_today).to eq('Today').or eq('Tonight')
for more compound expectations you can visit here.