LoginSignup
17
17

More than 5 years have passed since last update.

Rspecでリストのチェック

Last updated at Posted at 2012-06-06

リストに必要な要素が過不足なく含まれていることをチェックするとき,いちいちリストをソートしなくても=~を使えばよい

array1.should =~ array2

マッチしなかった場合は足りない/余計な要素を別途表示してくれるので,そういう点でもsortして==より=~の方がよい.

# test
[:zero, :one, :three].should =~ [:one, :two]

# log
Failure/Error: [:zero, :one, :three].should =~ [:one, :two]
  expected collection contained:  [:one, :two]
  actual collection contained:    [:one, :three, :zero]
  the missing elements were:      [:two]
  the extra elements were:        [:three, :zero]
17
17
6

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
17
17