RSpec - Tags标签

RSpec - Tags标签 首页 / RSpec入门教程 / RSpec - Tags标签

RSpec Tags提供了一种在规范文件中运行特定测试的简便方法。假设您只想运行指定测试方法,则可以使用Tags标签实现。

describe "How to run specific Examples with Tags" do 
   it 'is a slow test', :slow=> true do 
      sleep 10 
      puts 'This test is slow!' 
   end 
   
   it 'is a fast test', :fast=> true do 
      puts 'This test is fast!' 
   end 
end

现在,将上面的代码保存在一个名为tag_spec.rb的新文件中。在命令行中,运行以下命令: rspec --tag slow tag_spec.rb

链接:https://www.learnfk.comhttps://www.learnfk.com/rspec/rspec-tags.html

来源:LearnFk无涯教程网

您将看到此输出-

This test is slow! 
. 
Finished in 10 seconds (files took 0.11601 seconds to load) 
1 example, 0 failures

然后,运行以下命令:rspec --tag fast tag_spec.rb

Run options: include {:fast=>true} 
This test is fast! 
. 
Finished in 0.001 seconds (files took 0.11201 seconds to load) 
1 example, 0 failures

如您所见,RSpec标签使子集测试非常容易!

无涯教程网

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

深入浅出gRPC -〔李林锋〕

从0开始学架构 -〔李运华〕

职场求生攻略 -〔臧萌〕

分布式数据库30讲 -〔王磊〕

动态规划面试宝典 -〔卢誉声〕

手机摄影 -〔@随你们去〕

小马哥讲Spring AOP编程思想 -〔小马哥〕

LangChain 实战课 -〔黄佳〕

手把手带你写一个 MiniTomcat -〔郭屹〕

好记忆不如烂笔头。留下您的足迹吧 :)