public
Fork of dchelimsky/rspec
Description: Behaviour Driven Development framework for Ruby
Homepage: http://rspec.info
Clone URL: git://github.com/seangeo/rspec.git
Added --loadby random option that randomizes the test order.
seangeo (author)
Wed Apr 02 02:09:42 -0700 2008
commit  b7520eac216d6c26bdd3f0154260212944252911
tree    455db6daa883032155d508329ab2a5c3f8366f89
parent  cd2176712f8575d1e69f29a9a315f707074f7cd5
...
61
62
63
64
 
65
66
67
...
61
62
63
 
64
65
66
67
0
@@ -61,7 +61,7 @@ module Spec
0
                                              "If this option is used it must come before the others"],
0
         :backtrace => ["-b", "--backtrace", "Output full backtrace"],
0
         :loadby => ["-L", "--loadby STRATEGY", "Specify the strategy by which spec files should be loaded.",
0
-                                               "STRATEGY can currently only be 'mtime' (File modification time)",
0
+                                               "STRATEGY can currently be 'mtime' (File modification time) or random",
0
                                                "By default, spec files are loaded in alphabetical order if --loadby",
0
                                                "is not specified."],
0
         :reverse => ["-R", "--reverse", "Run examples in reverse order"],
...
2
3
4
5
 
 
6
7
8
...
2
3
4
 
5
6
7
8
9
0
@@ -2,7 +2,8 @@ module Spec
0
   module Runner
0
     class Options
0
       FILE_SORTERS = {
0
-        'mtime' => lambda {|file_a, file_b| File.mtime(file_b) <=> File.mtime(file_a)}
0
+        'mtime' => lambda {|file_a, file_b| File.mtime(file_b) <=> File.mtime(file_a)},
0
+       'random' => lambda {|file_a, file_b| rand <=> rand }
0
       }
0
 
0
       EXAMPLE_FORMATTERS = { # Load these lazily for better speed
...
355
356
357
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
358
359
360
...
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
0
@@ -355,6 +355,23 @@ describe "OptionParser" do
0
     end
0
   end
0
   
0
+  it "should accept the random comparator when --loadby random" do
0
+    options = parse(["--loadby", "random"])
0
+    options.class.should_receive(:rand).and_return(0.2, 0.1)
0
+
0
+    runner = Spec::Runner::ExampleGroupRunner.new(options)
0
+    Spec::Runner::ExampleGroupRunner.should_receive(:new).
0
+      with(options).
0
+      and_return(runner)
0
+    runner.should_receive(:load_files).with(["option_parser_spec.rb", "command_line_spec.rb"])
0
+    
0
+    Dir.chdir(File.dirname(__FILE__)) do
0
+      options.files << 'command_line_spec.rb'
0
+      options.files << 'option_parser_spec.rb'
0
+      options.run_examples
0
+    end
0
+  end
0
+  
0
   it "should use the standard runner by default" do
0
     runner = ::Spec::Runner::ExampleGroupRunner.new(@parser.options)
0
     ::Spec::Runner::ExampleGroupRunner.should_receive(:new).

Comments