=~expect语法的rspec错误不支持运算符匹配器

=~expect语法的rspec错误不支持运算符匹配器,rspec,Rspec,得到 因为代码是 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, :he

得到

因为代码是

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]


我相信数组的
=~
的替换是可行的

需要明确的是,per,而新的
expect
语法支持多种比较运算符(例如
),您可以尝试:

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

it { should match_array [:bar, :hello] }