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

您将看到此输出-

无涯教程网

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标签使子集测试非常容易!

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

来源:LearnFk无涯教程网

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

技术教程推荐

邱岳的产品实战 -〔邱岳〕

程序员进阶攻略 -〔胡峰〕

Kafka核心技术与实战 -〔胡夕〕

ZooKeeper实战与源码剖析 -〔么敬国〕

Kafka核心源码解读 -〔胡夕〕

如何看懂一幅画 -〔罗桂霞〕

WebAssembly入门课 -〔于航〕

Go 语言项目开发实战 -〔孔令飞〕

陈天 · Rust 编程第一课 -〔陈天〕

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