RSpec 是否有内置匹配器来查看字符串是一个值还是另一个值?
Does RSpec have a built in matcher for seeing if a String is one value or another?
编辑:提供的复合匹配器答案是一个更优雅的解决方案:
expect(@weathers.get_day_today).to eq('Today').or eq('Tonight')
原题:
我正在测试一个值是 "Today" 还是 "Tonight"。是否有内置的匹配器?或者比我正在做的更清洁的方法?
编辑: 以下是我尝试进行自定义测试,但它不起作用。这是一个不该做的例子。
首先,添加自定义匹配器。
RSpec::Matchers.define :be_this_or_that do |expected|
match do |actual|
actual == expected.first or expected.last
end
end
二、使用
expect(@weathers.get_day_today).to be_this_or_that(["Today", "Tonight"])
你可以这样试试:
expect(@weathers.get_day_today).to eq('Today').or eq('Tonight')
更多复合期望,您可以访问 here。
编辑:提供的复合匹配器答案是一个更优雅的解决方案:
expect(@weathers.get_day_today).to eq('Today').or eq('Tonight')
原题:
我正在测试一个值是 "Today" 还是 "Tonight"。是否有内置的匹配器?或者比我正在做的更清洁的方法?
编辑: 以下是我尝试进行自定义测试,但它不起作用。这是一个不该做的例子。
首先,添加自定义匹配器。
RSpec::Matchers.define :be_this_or_that do |expected|
match do |actual|
actual == expected.first or expected.last
end
end
二、使用
expect(@weathers.get_day_today).to be_this_or_that(["Today", "Tonight"])
你可以这样试试:
expect(@weathers.get_day_today).to eq('Today').or eq('Tonight')
更多复合期望,您可以访问 here。