Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
432 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 Answer

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. .


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...