按特定顺序运行 RSpec 任务 [英] Run RSpec tasks in a specific order

查看:27
本文介绍了按特定顺序运行 RSpec 任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一堆 RSpec Rake 任务定义了当我运行整个测试套件时我希望以特定顺序运行.

I have a bunch of RSpec Rake tasks defined that I'd like to run in a specific order when I run the entire suite of tests.

我尝试过这样的事情:

task :run_in_order => [:one, :two, :three] do 
  puts "Run suite of tests"
end

它运行第一个测试然后停止并且不运行其余的任务.

And it runs the first test and then stops and doesn't run the rest of the tasks.

因此,如果使用 Rake 语法,则它不起作用.有没有办法记录 RSpec Rake 任务的任务依赖关系?

So if using Rake syntax it doesn't work. Is there a way to note task dependencies for RSpec Rake tasks?

推荐答案

检查这个 http://blog.davidchelimsky.net/2012/01/04/rspec-28-is-released/

–order rand 我们添加了一个带有两个支持值的 --order 选项:rand和默认.

–order rand We added an --order option with two supported values: rand and default.

rspec --order random(或 rand)告诉 RSpec 在一个随机顺序,然后随机运行每组中的示例命令.我们以这种方式实现它(而不是完全随机化每个例子)因为我们不想重新运行昂贵的before(:all) 钩子.公平的权衡,因为由此产生的随机化是在暴露顺序依赖错误方面同样有效.

rspec --order random (or rand) tells RSpec to run the groups in a random order, and then run the examples within each group in random order. We implemented it this way (rather than complete randomization of every example) because we don’t want to re-run expensive before(:all) hooks. A fair tradeoff, as the resulting randomization is just as effective at exposing order-dependency bugs.

当您使用 --order random 时,RSpec 会打印出它的随机数用于种子随机发生器.当你认为你找到了一个订单依赖错误,您可以传递种子,订单将保持一致:

When you use --order random, RSpec prints out the random number it used to seed the randomizer. When you think you’ve found an order-dependency bug, you can pass the seed along and the order will remain consistent:

--订购兰特:3455--order default 告诉 RSpec 加载组和示例,因为它们在每个文件中声明

--order rand:3455 --order default tells RSpec to load groups and examples as they are declared in each file

基本上,您应该在规范文件中对测试进行排序,然后使用 --order default 选项执行它..

Basically you should order your tests in a spec file an then execute it with --order default option. .

这篇关于按特定顺序运行 RSpec 任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆