运行带有给定标记的示例

将标记添加到描述块允许你仅运行具有给定标记的那些示例。使用 --tag(或 -t)选项运行与指定标记匹配的示例。标记可以是简单名称或名称:值对。

  • 如果提供了简单名称,则仅运行带有:name => true 的示例。例如,rspec <spec_file> --tag smoke 将运行标记为 Smoke 的示例。

    describe '#Tests' do
      it 'runs the smoke test', :smoke => true do
      end
    
      it 'runs the regression tests', :regression => true do
      end
    
      it 'runs the acceptance tests', :acceptance => true do
      end
    end
    
  • 如果给出 name:value 对,则会运行 name => value 的示例,其中 value 始终为字符串。例如,rspec <spec_file> --tag testId:101 将运行标记为 testId``101 的示例。

    describe '#Tests' do
      it 'runs the test with id 99', :testId => 99 do
      end
    
      it 'runs the test with id 101', :testId => 101 do
      end
    end