2

得到

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

对于以前的代码

class_methods.all.should =~ [:bar, :hello]

我想改成

expect(class_methods.all).to =~ [:bar, :hello]

我也试过

expect(class_methods.all).to match [:bar, :hello]

expect(class_methods.all).to match ([:bar, :hello])

expect(class_methods.all match([:bar, :hello])).to be_true
# this one gives wrong number of arguments
4

3 回答 3

4

=~我相信for 数组的替换是match_array.

expect(class_methods.all).to match_array [:bar, :hello]
于 2013-11-11T16:10:12.370 回答
1

你可以试试:

subject { class_methods.all }

it { should match_array [:bar, :hello] }
于 2013-11-11T22:02:49.130 回答
0

为了清楚起见,根据https://www.relishapp.com/rspec/rspec-expectations/v/3-0/docs/built-in-matchers,而新expect语法支持各种比较运算符(例如<<=等)与 结合使用be,不支持=~or ==。该match方法替换=~了字符串和正则表达式,match_array处理数组的特殊情况(根据其他答案)。

于 2013-11-11T19:07:22.060 回答