執行帶有給定標記的示例

將標記新增到描述塊允許你僅執行具有給定標記的那些示例。使用 --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