rspec匹配器数组参数类似于hash_including

bou*_*der 4 ruby rspec ruby-on-rails

在rspec中,您可以测试对方法的调用是否接收到作为哈希的参数,并包含某些键或键值对.那是:

my_object.should_receive(:my_method).with(hash_including(:a => 'alpha'))
Run Code Online (Sandbox Code Playgroud)

有没有什么可以用数组完成类似的匹配?看起来像什么?

my_object.should_receive(:my_method).with(array_including('alpha'))
Run Code Online (Sandbox Code Playgroud)

Mer*_*rvS 6

这个怎么样:

my_obj.should_receive(:my_method) do |arg|
  arg.should be_an_instance_of(Array)
  arg.should include('alpha')
end
Run Code Online (Sandbox Code Playgroud)