diff --git a/lib/jasmine/headless.rb b/lib/jasmine/headless.rb index 4bf9cbc..ff6e652 100644 --- a/lib/jasmine/headless.rb +++ b/lib/jasmine/headless.rb @@ -32,3 +32,4 @@ module Jasmine::Headless end require 'jasmine/headless/errors' + diff --git a/lib/jasmine/headless/files_list.rb b/lib/jasmine/headless/files_list.rb index a0fb58f..7887713 100644 --- a/lib/jasmine/headless/files_list.rb +++ b/lib/jasmine/headless/files_list.rb @@ -62,6 +62,8 @@ module Jasmine::Headless def initialize(options = {}) @options = options + srand(@options[:seed]) if @options[:seed] + @required_files = UniqueAssetList.new @potential_files_to_filter = [] diff --git a/lib/jasmine/headless/options.rb b/lib/jasmine/headless/options.rb index e3d6aca..5252725 100644 --- a/lib/jasmine/headless/options.rb +++ b/lib/jasmine/headless/options.rb @@ -17,6 +17,7 @@ module Jasmine :do_list => false, :full_run => true, :enable_cache => true, + :seed => rand(10000), :files => [] } @@ -60,6 +61,8 @@ module Jasmine @options[:full_run] = false when '--list', '-l' @options[:do_list] = true + when '--seed' + @options[:seed] = arg.to_i end end @@ -82,7 +85,8 @@ module Jasmine [ '--report', GetoptLong::REQUIRED_ARGUMENT ], [ '--jasmine-config', '-j', GetoptLong::REQUIRED_ARGUMENT ], [ '--no-full-run', GetoptLong::NO_ARGUMENT ], - [ '--list', '-l', GetoptLong::NO_ARGUMENT ] + [ '--list', '-l', GetoptLong::NO_ARGUMENT ], + [ '--seed', GetoptLong::REQUIRED_ARGUMENT ] ) command_line_args.each { |*args| process_option(*args) } diff --git a/lib/jasmine/headless/runner.rb b/lib/jasmine/headless/runner.rb index 33de5c9..df95b89 100644 --- a/lib/jasmine/headless/runner.rb +++ b/lib/jasmine/headless/runner.rb @@ -73,7 +73,8 @@ module Jasmine files_list = Jasmine::Headless::FilesList.new( :config => jasmine_config, - :only => @options[:files] + :only => @options[:files], + :seed => @options[:seed] ) @_targets = template_writer.write!(files_list) @@ -81,6 +82,9 @@ module Jasmine run_targets.pop if (!@options[:full_run] && files_list.filtered?) || files_list.has_spec_outside_scope? system jasmine_command(run_targets) + + puts "\nTest ordering seed: --seed #{@options[:seed]}" + @_status = $?.exitstatus ensure if @_targets && !runner_filename && (@options[:remove_html_file] || (@_status == 0)) diff --git a/spec/integration/randomization_spec.rb b/spec/integration/randomization_spec.rb new file mode 100644 index 0000000..052752a --- /dev/null +++ b/spec/integration/randomization_spec.rb @@ -0,0 +1,13 @@ +require 'spec_helper' + +describe 'sprockets' do + let(:seed) { 100 } + + it 'should randomize the run order' do + output = %x{bin/jasmine-headless-webkit -j spec/jasmine/success/success.yml --seed #{seed}} + $?.exitstatus.should == 0 + + output.should include("--seed #{seed}") + end +end + diff --git a/spec/lib/jasmine/headless/files_list_spec.rb b/spec/lib/jasmine/headless/files_list_spec.rb index dcd9bfc..0a8f9e5 100644 --- a/spec/lib/jasmine/headless/files_list_spec.rb +++ b/spec/lib/jasmine/headless/files_list_spec.rb @@ -177,13 +177,13 @@ describe Jasmine::Headless::FilesList do end describe '#add_files' do + let(:files_list) { described_class.new(:seed => 100) } + no_default_files! let(:dir) { 'tmp' } before do - srand(100) - FileUtils.mkdir_p dir 10.times do |index| diff --git a/spec/lib/jasmine/headless/options_spec.rb b/spec/lib/jasmine/headless/options_spec.rb index 346bae3..237423d 100644 --- a/spec/lib/jasmine/headless/options_spec.rb +++ b/spec/lib/jasmine/headless/options_spec.rb @@ -92,6 +92,24 @@ describe Jasmine::Headless::Options do end end + context 'specify no seed' do + it 'should have a seed' do + options[:seed].should_not be_nil + end + end + + context 'specify random order seed' do + let(:seed) { 12345 } + + before do + ARGV.replace([ "--seed", seed ]) + end + + it 'should specify the seed' do + options[:seed].should == seed + end + end + after do ARGV.replace(@argv) end diff --git a/spec/lib/jasmine/headless_spec.rb b/spec/lib/jasmine/headless_spec.rb new file mode 100644 index 0000000..51f5efc --- /dev/null +++ b/spec/lib/jasmine/headless_spec.rb @@ -0,0 +1,2 @@ +require 'spec_helper' +