0

假设你有:

Article.keys.should =~ [:title, :year, :title_length]

在 Rspec 3.0 中

expect(Article.keys).to =~ [:title, :year, :title_length]

除了它失败了:

ArgumentError:
   The expect syntax does not support operator matchers, so you must pass a matcher to `#to`.

关键问题:Rspec 3.0 中的=~操作员匹配器是什么?

4

2 回答 2

4
expect([1, 2, 3]).to match_array([2, 1, 3])

我想这就是你要找的

于 2014-06-19T20:34:40.770 回答
2

值得一提的是Rspec 3.0 Collection membership

expect(array).to match_array(expected_array)
# ...which is the same as:
expect(array).to contain_exactly(individual elements)

文档中的示例:-

expect([1, 2, 3]).to contain_exactly(2, 1, 3)
# is exactly same as below
expect([1, 2, 3]).to match_array([3, 2, 1])
于 2014-06-20T04:06:33.317 回答