Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
412 views
in Technique[技术] by (71.8m points)

ruby - Run RSpec tasks in a specific order

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.

I've tried something like this:

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.

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Check this http://blog.davidchelimsky.net/2012/01/04/rspec-28-is-released/

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

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.

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:

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...