Ruby RSpec使用正则表达式使用matcher变量启动_

Ruby RSpec使用正则表达式使用matcher变量启动_,ruby,regex,rspec,matcher,Ruby,Regex,Rspec,Matcher,是否有RSpecstart\u withmatcher的变体,在检查字符串数组时使用正则表达式匹配而不是相等?(我不介意自己写;但我不想重新发明轮子。) 具体来说,我想要一个如下所示的规范: 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

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

具体来说,我想要一个如下所示的规范:

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
如果
输出[0]
匹配
/foo/
输出[1]
匹配
/bar/
,则此规范应通过


假设我确实需要编写自己的匹配器,那么有没有一种方法可以“重载”
开始,或者我需要选择一个不同的名称?

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

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

您可能需要使用不同的名称编写自己的matcher。