я только что сделал это в Rspec 2 - В моем случае у меня есть смеси упорядоченных и неупорядоченных тестов в файле один спецификации, поэтому я использовал следующее:
# order by a number at start of the description (default 0) and then random
# note 'describe' groups always sort after 'it' examples
RSpec.configure do |config|
config.order_groups_and_examples do |list|
list.sort_by { |item| [item.description.sub(/^(\d*).*/, '\1').to_i, rand] }
end
end
В сочетании с группировкой с использованием описания, это решило мои требования (большинство тестов я не заботился о заказе, но несколько я хотел по порядку или в конце). Например:
it "1: starts when asked to"
it "1: should do something"
it "waves happily"
it "snores loudly"
describe "9: at the end" do
it "stops when asked to"
end
describe "4: some grouping" do
it "does another thing"
it "has weight"
end
describe "4: another group" do
it "waddles like a duck"
it "quacks like a duck"
end
выполняется в следующем порядке:
# next two in random order
it "waves happily"
it "snores loudly"
# next two in random order
it "1: should do something"
it "1: starts when asked to"
# next two describe blocks in random order, and their examples within then in random order
describe "2: another group" do
it "waddles like a duck"
it "quacks like a duck"
end
describe "2: some grouping" do
it "does another thing"
it "has weight"
end
# NOTE: an it "9: something" example without a surrounding
# describe block would run before all the describe blocks.
# this will run at the end
describe "9: at the end" do
it "stops when asked to"
end