在 RSpec 2 中使用 OR 的相等性 [英] Equality using OR in RSpec 2

查看:34
本文介绍了在 RSpec 2 中使用 OR 的相等性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面这个例子的正确写法是什么?玩家的分数应该等于 5 或​​ 8.

What is the correct way to write the following example? The player's score should equal 5 or 8.

it "should equal 5 or 8" do
  player.score.should == 5 or 8
end

谢谢!

蒂姆

推荐答案

5 or 8 将一直产生结果 5 而不是你所期望的.您可以使用 Rspec 的满足匹配器.

5 or 8 will produce result 5 all the time and not do what you expect. You can use Rspec's satisfy matcher.

 player.score.should satisfy {|s| [5,8].include?(s)}

这篇关于在 RSpec 2 中使用 OR 的相等性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆