RSpec使用正则表达式启动匹配变量

是否存在RSpec start_with匹配器的变体,在检查字符串数组时将使用正则表达式匹配而不是相等? (我不介意自己编写;但我不想重新发明轮子。)

具体来说,我希望有一个看起来像这样的规范:

 it 'begins with the standard header' do output = method_under_test # output is an array of Strings expect(output).to start_with([/foo/, /bar/]) end 

如果output[0]匹配/foo/并且output[1]匹配/bar/则此规范应该通过。

假设我确实需要编写自己的匹配器,有没有办法“重载” start_with ,还是需要选择其他名称?

事实certificate,解决方案是使用组合匹配器和别名的组合:

 it 'begins with the standard header' do output = method_under_test # output is an array of Strings expect(output).to start_with( a_string_matching(/foo/), a_string_matching(/bar/) ) end