Unit testing RSpec测试提供支持规范的gem

Unit testing RSpec测试提供支持规范的gem,unit-testing,rspec,rubygems,Unit Testing,Rspec,Rubygems,我有一个support spec函数,它处理对动作、格式和关联的测试路由。此代码已移动到我们的后端gem。使主应用程序中的路由测试更加干净。由于有两个项目正在使用它,我正在尝试向模块中添加更健壮的单元测试 我想在gem中编写一个RSpec测试来测试gem提供的RSpec代码 在我们的gem(/lib//spec/support/file.rb)中,它执行以下操作 def test_route(....) ... if routable specify 'message' do

我有一个support spec函数,它处理对动作、格式和关联的测试路由。此代码已移动到我们的后端gem。使主应用程序中的路由测试更加干净。由于有两个项目正在使用它,我正在尝试向模块中添加更健壮的单元测试

我想在gem中编写一个RSpec测试来测试gem提供的RSpec代码

在我们的gem(
/lib//spec/support/file.rb
)中,它执行以下操作

def test_route(....)
  ...
  if routable
    specify 'message' do
      expect (method => url).to route_to(controller, route_hash)
    end
  else
    specify 'other message' do
      expect (method => url).not_to be_routable
    end
  end
end
在gemrspec(
/spec/lib/spec/support/test\u route\u spec.rb
)中, 我试图删除
:define\u example\u method
函数,但没有任何结果:

context 'context message' do
  before do
    allow(RSpec::Core::ExampleGroup).to receive(:define_example_group).with(name)
  end
  specify do
     # /b/1/a.json should be routable
     test_route(:a, :b, :index, :json, true)
     # expect something....
  end
end
我最后得出以下结论:

`specify` is not available from within an example (e.g. an `it` block)...
它来自于方法\缺少的方法


任何指导或指示都将不胜感激。

好的。因此,在尝试模拟RSpec的部分内容时使用RSpec,尤其是在一个specify中尝试模拟specify只是一个死脑筋的想法。最后生成了一个specify_包装(message,&block),调用specify message,&block并模拟包装并对其执行预期。