您能否将匹配器传递给rspec中的共享示例?

您能否将匹配器传递给rspec中的共享示例?,rspec,Rspec,我有以下情况。我有一个共享的示例,它在一些散列中作为数据传递,在另一个散列中作为预期数据传递。它看起来是这样的: RSpec.describe "shared examples" do shared_examples "matching hash" do |data, expected_data| it 'matches' do expect(data).to include (expected_data) end end it_behaves_like

我有以下情况。我有一个共享的示例,它在一些散列中作为数据传递,在另一个散列中作为预期数据传递。它看起来是这样的:

RSpec.describe "shared examples" do
  shared_examples "matching hash" do |data, expected_data|
    it 'matches' do
      expect(data).to include (expected_data)
    end
  end

  it_behaves_like "matching hash", { foo: '/foo/1', bar: '/bar' }, { foo: '/foo/1' }
end
我现在遇到了一个问题,对于包含URL的哈希中的一些值,我不想检查完整的字符串,而只检查开始。所以我的想法是像平常一样使用匹配器并将其传递到
预期的\u数据中

RSpec.describe "shared examples with passed in matcher" do
  shared_examples "matching hash" do |data, expected_data|
    it 'matches' do
      expect(data).to include (expected_data)
    end
  end

  it_behaves_like "matching hash", { foo: '/foo/1' }, { foo: start_with('/foo/') }
end
可悲的是,这一点在实践中失败了

Failure/Error: it_behaves_like "matching hash", { foo: '/foo/1' }, { foo: start_with('/foo/') }
  `start_with` is not available on an example group (e.g. a `describe` or `context` block). It is only available from within individual examples (e.g. `it` blocks) or from constructs that run in the scope of an example (e.g. `before`, `let`, etc).
在这个特定的例子中,我可以通过传递一个正则表达式来解决这个问题,而不是通过
来传递
start\u,或者调整共享示例来显式地获取模糊数据并通过匹配器进行比较

但对我来说,如果有办法将匹配者传递到共享示例中,那感觉会更好。有没有办法做到这一点,或者这是不可能的