Permalink
Browse files

add '--order default' option

This allows you to override --order rand in a .rspec file from the CLI.
It actually worked before, but it was completely by accident - this
makes it explicit and less likely to regress in the future.

Related to #403.
  • Loading branch information...
1 parent 024638f commit 9a22066320ee365ce1b2fd100b8fd4ed695d75db @dchelimsky dchelimsky committed Oct 30, 2011
@@ -0,0 +1,29 @@
+Feature: --order (new in rspec-core-2.8)
+
+ Use the `--order` option to tell RSpec how to order the files, groups, and
+ examples. Options are `default` and `rand`:
+
+ Default is:
+
+ * files are ordered based on the underlying file system's order (typically
+ case-sensitive alpha on *nix OS's and case-insenstive alpha in Windows)
+ * groups/examples are loaded in the order in which they are declared
+
+ Use `rand` to randomize the order of files, groups within files, and
+ examples within groups.*
+
+ * Nested groups are always run from top-level to bottom-level in order to avoid
+ executing `before(:all)` and `after(:all)` hooks more than once, but the order
+ of groups at each level is randomized.
+
+ You can also specify a seed
+
+ ## Examples
+
+ --order default
+ --order rand
+ --order rand:123
+ --seed 123 # same as --order rand:123
+
+ The `default` option is only necessary when you have `--order rand` stored in a
+ config file (e.g. `.rspec`) and you want to override it from the command line.
@@ -545,8 +545,13 @@ def randomize?
def order=(type)
order, seed = type.to_s.split(':')
- @order = order
- @seed = seed.to_i if seed
+ if order == 'default'
+ @order = nil
+ @seed = nil
+ else
+ @order = order
+ @seed = seed.to_i if seed
+ end
end
private
@@ -91,6 +91,18 @@
end
end
+ describe '--order default on CLI with --order rand in .rspec' do
+ it "overrides --order rand with --order default" do
+ write_file '.rspec', '--order rand'
+
+ run_command 'rspec spec/order_spec.rb --order default -f doc'
+
+ all_output.should_not match(/Randomized/)
+
+ all_output.should match(/group 1.*group 1 example 1.*group 1 example 2.*group 1-1.*group 1-2.*group 2.*/m)
+ end
+ end
+
def examples(group)
yield split_in_half(all_stdout.scan(/^\s+#{group} example.*$/))
end
@@ -1005,6 +1005,21 @@ def metadata_hash(*args)
config.seed.should eq(123)
end
end
+
+ context 'given "default"' do
+ before do
+ config.order = 'rand:123'
+ config.order = 'default'
+ end
+
+ it "sets the order to nil" do
+ config.order.should be_nil
+ end
+
+ it "sets the seed to nil" do
+ config.seed.should be_nil
+ end
+ end
end
end
end

0 comments on commit 9a22066

Please sign in to comment.