6
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

rspec: match_array は 多次元配列の順番を検証してしまう

Last updated at Posted at 2015-09-24

match_array は配列の順番を問わずに検証してくれる。

expect([1,2]).to match_array [2,1] # => true

だけど多次元配列 ( 配列の中の配列 ) だとダメだ。

順番を気にしないのは、1階層分だけ。
2階層目以降は検証されてしまう。

expect([[1,2],[3,4]]).to match_array [[2,1],[4,3]] # => false

もし多次元配列をチェックする場合は、各配列の順序を合わせること。

expect([[1,2],[3,4]]).to match_array [[3,4],[1,2]] # => true

だがそれより、何回かに分けた方が良いだろう。

expect([1,2]).to match_array [2,1] # => true
expect([3,4]).to match_array [4,3] # => true

バージョン: Rspec 2.14.8

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

メンター受付

6
4
2

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
6
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?