PageRenderTime 220ms CodeModel.GetById 19ms app.highlight 190ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/bundle/jruby/2.1/gems/rspec-core-2.14.8/spec/rspec/core/configuration_spec.rb

https://github.com/delowong/logstash
Ruby | 1561 lines | 1447 code | 114 blank | 0 comment | 15 complexity | 1f548e9492452f0999b5ebdc30a16195 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1require 'spec_helper'
   2require 'tmpdir'
   3
   4module RSpec::Core
   5
   6  describe Configuration do
   7
   8    let(:config) { Configuration.new }
   9
  10    describe "RSpec.configuration with a block" do
  11      before { RSpec.stub(:warn_deprecation) }
  12
  13      it "is deprecated" do
  14        RSpec.should_receive(:warn_deprecation)
  15        RSpec.configuration {}
  16      end
  17    end
  18
  19    describe '#deprecation_stream' do
  20      it 'defaults to standard error' do
  21        expect(config.deprecation_stream).to eq $stderr
  22      end
  23
  24      it 'is configurable' do
  25        io = double 'deprecation io'
  26        config.deprecation_stream = io
  27        expect(config.deprecation_stream).to eq io
  28      end
  29    end
  30
  31    describe "#setup_load_path_and_require" do
  32      include_context "isolate load path mutation"
  33
  34      def absolute_path_to(dir)
  35        File.expand_path("../../../../#{dir}", __FILE__)
  36      end
  37
  38      it 'adds `lib` to the load path' do
  39        lib_dir = absolute_path_to("lib")
  40        $LOAD_PATH.delete(lib_dir)
  41
  42        expect($LOAD_PATH).not_to include(lib_dir)
  43        config.setup_load_path_and_require []
  44        expect($LOAD_PATH).to include(lib_dir)
  45      end
  46
  47      it 'adds the configured `default_path` to the load path' do
  48        config.default_path = 'features'
  49        foo_dir = absolute_path_to("features")
  50
  51        expect($LOAD_PATH).not_to include(foo_dir)
  52        config.setup_load_path_and_require []
  53        expect($LOAD_PATH).to include(foo_dir)
  54      end
  55
  56      it 'stores the required files' do
  57        config.should_receive(:require).with('a/path')
  58        config.setup_load_path_and_require ['a/path']
  59        expect(config.requires).to eq ['a/path']
  60      end
  61
  62      context "when `default_path` refers to a file rather than a directory" do
  63        it 'does not add it to the load path' do
  64          config.default_path = 'Rakefile'
  65          config.setup_load_path_and_require []
  66          expect($LOAD_PATH).not_to include(match(/Rakefile/))
  67        end
  68      end
  69    end
  70
  71    describe "#load_spec_files" do
  72      it "loads files using load" do
  73        config.files_to_run = ["foo.bar", "blah_spec.rb"]
  74        config.should_receive(:load).twice
  75        config.load_spec_files
  76      end
  77
  78      it "loads each file once, even if duplicated in list" do
  79        config.files_to_run = ["a_spec.rb", "a_spec.rb"]
  80        config.should_receive(:load).once
  81        config.load_spec_files
  82      end
  83
  84      context "with rspec-1 loaded" do
  85        before { stub_const("Spec::VERSION::MAJOR", 1) }
  86
  87        it "raises with a helpful message" do
  88          expect {
  89            config.load_spec_files
  90          }.to raise_error(/rspec-1 has been loaded/)
  91        end
  92      end
  93    end
  94
  95    describe "#treat_symbols_as_metadata_keys_with_true_values?" do
  96      it 'defaults to false' do
  97        expect(config.treat_symbols_as_metadata_keys_with_true_values?).to be_false
  98      end
  99
 100      it 'can be set to true' do
 101        config.treat_symbols_as_metadata_keys_with_true_values = true
 102        expect(config.treat_symbols_as_metadata_keys_with_true_values?).to be_true
 103      end
 104    end
 105
 106    describe "#mock_framework" do
 107      it "defaults to :rspec" do
 108        config.should_receive(:require).with('rspec/core/mocking/with_rspec')
 109        config.mock_framework
 110      end
 111    end
 112
 113    describe "#mock_framework="do
 114      it "delegates to mock_with" do
 115        config.should_receive(:mock_with).with(:rspec)
 116        config.mock_framework = :rspec
 117      end
 118    end
 119
 120    shared_examples "a configurable framework adapter" do |m|
 121      it "yields a config object if the framework_module supports it" do
 122        custom_config = Struct.new(:custom_setting).new
 123        mod = Module.new
 124        mod.stub(:configuration => custom_config)
 125
 126        config.send m, mod do |mod_config|
 127          mod_config.custom_setting = true
 128        end
 129
 130        expect(custom_config.custom_setting).to be_true
 131      end
 132
 133      it "raises if framework module doesn't support configuration" do
 134        mod = Module.new
 135
 136        expect {
 137          config.send m, mod do |mod_config|
 138          end
 139        }.to raise_error(/must respond to `configuration`/)
 140      end
 141    end
 142
 143    describe "#mock_with" do
 144      before { config.stub(:require) }
 145
 146      it_behaves_like "a configurable framework adapter", :mock_with
 147
 148      [:rspec, :mocha, :rr, :flexmock].each do |framework|
 149        context "with #{framework}" do
 150          it "requires the adapter for #{framework}" do
 151            config.should_receive(:require).with("rspec/core/mocking/with_#{framework}")
 152            config.mock_with framework
 153          end
 154        end
 155      end
 156
 157      it "allows rspec-mocks to be configured with a provided block" do
 158        mod = Module.new
 159
 160        RSpec::Mocks.configuration.should_receive(:add_stub_and_should_receive_to).with(mod)
 161
 162        config.mock_with :rspec do |c|
 163          c.add_stub_and_should_receive_to mod
 164        end
 165      end
 166
 167      context "with a module" do
 168        it "sets the mock_framework_adapter to that module" do
 169          mod = Module.new
 170          config.mock_with mod
 171          expect(config.mock_framework).to eq(mod)
 172        end
 173      end
 174
 175      it "uses the null adapter when set to any unknown key" do
 176        config.should_receive(:require).with('rspec/core/mocking/with_absolutely_nothing')
 177        config.mock_with :crazy_new_mocking_framework_ive_not_yet_heard_of
 178      end
 179
 180      context 'when there are already some example groups defined' do
 181        it 'raises an error since this setting must be applied before any groups are defined' do
 182          RSpec.world.stub(:example_groups).and_return([double.as_null_object])
 183          expect {
 184            config.mock_with :mocha
 185          }.to raise_error(/must be configured before any example groups are defined/)
 186        end
 187
 188        it 'does not raise an error if the default `mock_with :rspec` is re-configured' do
 189          config.mock_framework # called by RSpec when configuring the first example group
 190          RSpec.world.stub(:example_groups).and_return([double.as_null_object])
 191          config.mock_with :rspec
 192        end
 193
 194        it 'does not raise an error if re-setting the same config' do
 195          groups = []
 196          RSpec.world.stub(:example_groups => groups)
 197          config.mock_with :mocha
 198          groups << double.as_null_object
 199          config.mock_with :mocha
 200        end
 201      end
 202    end
 203
 204    describe "#expectation_framework" do
 205      it "defaults to :rspec" do
 206        config.should_receive(:require).with('rspec/expectations')
 207        config.expectation_frameworks
 208      end
 209    end
 210
 211    describe "#expectation_framework=" do
 212      it "delegates to expect_with=" do
 213        config.should_receive(:expect_with).with(:rspec)
 214        config.expectation_framework = :rspec
 215      end
 216    end
 217
 218    describe "#expect_with" do
 219      before do
 220        stub_const("Test::Unit::Assertions", Module.new)
 221        config.stub(:require)
 222      end
 223
 224      it_behaves_like "a configurable framework adapter", :expect_with
 225
 226      [
 227        [:rspec,  'rspec/expectations'],
 228        [:stdlib, 'test/unit/assertions']
 229      ].each do |framework, required_file|
 230        context "with #{framework}" do
 231          it "requires #{required_file}" do
 232            config.should_receive(:require).with(required_file)
 233            config.expect_with framework
 234          end
 235        end
 236      end
 237
 238      it "supports multiple calls" do
 239        config.expect_with :rspec
 240        config.expect_with :stdlib
 241        expect(config.expectation_frameworks).to eq [RSpec::Matchers, Test::Unit::Assertions]
 242      end
 243
 244      it "raises if block given with multiple args" do
 245        expect {
 246          config.expect_with :rspec, :stdlib do |mod_config|
 247          end
 248        }.to raise_error(/expect_with only accepts/)
 249      end
 250
 251      it "raises ArgumentError if framework is not supported" do
 252        expect do
 253          config.expect_with :not_supported
 254        end.to raise_error(ArgumentError)
 255      end
 256
 257      context 'when there are already some example groups defined' do
 258        it 'raises an error since this setting must be applied before any groups are defined' do
 259          RSpec.world.stub(:example_groups).and_return([double.as_null_object])
 260          expect {
 261            config.expect_with :rspec
 262          }.to raise_error(/must be configured before any example groups are defined/)
 263        end
 264
 265        it 'does not raise an error if the default `expect_with :rspec` is re-configured' do
 266          config.expectation_frameworks # called by RSpec when configuring the first example group
 267          RSpec.world.stub(:example_groups).and_return([double.as_null_object])
 268          config.expect_with :rspec
 269        end
 270
 271        it 'does not raise an error if re-setting the same config' do
 272          groups = []
 273          RSpec.world.stub(:example_groups => groups)
 274          config.expect_with :stdlib
 275          groups << double.as_null_object
 276          config.expect_with :stdlib
 277        end
 278      end
 279    end
 280
 281    describe "#expecting_with_rspec?" do
 282      before do
 283        stub_const("Test::Unit::Assertions", Module.new)
 284        config.stub(:require)
 285      end
 286
 287      it "returns false by default" do
 288        expect(config).not_to be_expecting_with_rspec
 289      end
 290
 291      it "returns true when `expect_with :rspec` has been configured" do
 292        config.expect_with :rspec
 293        expect(config).to be_expecting_with_rspec
 294      end
 295
 296      it "returns true when `expect_with :rspec, :stdlib` has been configured" do
 297        config.expect_with :rspec, :stdlib
 298        expect(config).to be_expecting_with_rspec
 299      end
 300
 301      it "returns true when `expect_with :stdlib, :rspec` has been configured" do
 302        config.expect_with :stdlib, :rspec
 303        expect(config).to be_expecting_with_rspec
 304      end
 305
 306      it "returns false when `expect_with :stdlib` has been configured" do
 307        config.expect_with :stdlib
 308        expect(config).not_to be_expecting_with_rspec
 309      end
 310    end
 311
 312    describe "#files_to_run" do
 313      it "loads files not following pattern if named explicitly" do
 314        config.files_or_directories_to_run = "spec/rspec/core/resources/a_bar.rb"
 315        expect(config.files_to_run).to eq([      "spec/rspec/core/resources/a_bar.rb"])
 316      end
 317
 318      it "prevents repetition of dir when start of the pattern" do
 319        config.pattern = "spec/**/a_spec.rb"
 320        config.files_or_directories_to_run = "spec"
 321        expect(config.files_to_run).to eq(["spec/rspec/core/resources/a_spec.rb"])
 322      end
 323
 324      it "does not prevent repetition of dir when later of the pattern" do
 325        config.pattern = "rspec/**/a_spec.rb"
 326        config.files_or_directories_to_run = "spec"
 327        expect(config.files_to_run).to eq(["spec/rspec/core/resources/a_spec.rb"])
 328      end
 329
 330      context "with <path>:<line_number>" do
 331        it "overrides inclusion filters set on config" do
 332          config.filter_run_including :foo => :bar
 333          config.files_or_directories_to_run = "path/to/file.rb:37"
 334          expect(config.inclusion_filter.size).to eq(1)
 335          expect(config.inclusion_filter[:locations].keys.first).to match(/path\/to\/file\.rb$/)
 336          expect(config.inclusion_filter[:locations].values.first).to eq([37])
 337        end
 338
 339        it "overrides inclusion filters set before config" do
 340          config.force(:inclusion_filter => {:foo => :bar})
 341          config.files_or_directories_to_run = "path/to/file.rb:37"
 342          expect(config.inclusion_filter.size).to eq(1)
 343          expect(config.inclusion_filter[:locations].keys.first).to match(/path\/to\/file\.rb$/)
 344          expect(config.inclusion_filter[:locations].values.first).to eq([37])
 345        end
 346
 347        it "clears exclusion filters set on config" do
 348          config.exclusion_filter = { :foo => :bar }
 349          config.files_or_directories_to_run = "path/to/file.rb:37"
 350          expect(config.exclusion_filter).to be_empty,
 351            "expected exclusion filter to be empty:\n#{config.exclusion_filter}"
 352        end
 353
 354        it "clears exclusion filters set before config" do
 355          config.force(:exclusion_filter => { :foo => :bar })
 356          config.files_or_directories_to_run = "path/to/file.rb:37"
 357          expect(config.exclusion_filter).to be_empty,
 358            "expected exclusion filter to be empty:\n#{config.exclusion_filter}"
 359        end
 360      end
 361
 362      context "with default pattern" do
 363        it "loads files named _spec.rb" do
 364          config.files_or_directories_to_run = "spec/rspec/core/resources"
 365          expect(config.files_to_run).to eq([      "spec/rspec/core/resources/a_spec.rb"])
 366        end
 367
 368        it "loads files in Windows", :if => RSpec.windows_os? do
 369          config.files_or_directories_to_run = "C:\\path\\to\\project\\spec\\sub\\foo_spec.rb"
 370          expect(config.files_to_run).to eq([      "C:/path/to/project/spec/sub/foo_spec.rb"])
 371        end
 372
 373        it "loads files in Windows when directory is specified", :if => RSpec.windows_os? do
 374          config.files_or_directories_to_run = "spec\\rspec\\core\\resources"
 375          expect(config.files_to_run).to eq([      "spec/rspec/core/resources/a_spec.rb"])
 376        end
 377      end
 378
 379      context "with default default_path" do
 380        it "loads files in the default path when run by rspec" do
 381          config.stub(:command) { 'rspec' }
 382          config.files_or_directories_to_run = []
 383          expect(config.files_to_run).not_to be_empty
 384        end
 385
 386        it "loads files in the default path when run with DRB (e.g., spork)" do
 387          config.stub(:command) { 'spork' }
 388          RSpec::Core::Runner.stub(:running_in_drb?) { true }
 389          config.files_or_directories_to_run = []
 390          expect(config.files_to_run).not_to be_empty
 391        end
 392
 393        it "does not load files in the default path when run by ruby" do
 394          config.stub(:command) { 'ruby' }
 395          config.files_or_directories_to_run = []
 396          expect(config.files_to_run).to be_empty
 397        end
 398      end
 399
 400      def specify_consistent_ordering_of_files_to_run
 401        File.stub(:directory?).with('a') { true }
 402
 403        orderings = [
 404          %w[ a/1.rb a/2.rb a/3.rb ],
 405          %w[ a/2.rb a/1.rb a/3.rb ],
 406          %w[ a/3.rb a/2.rb a/1.rb ]
 407        ].map do |files|
 408          Dir.should_receive(:[]).with(/^\{?a/) { files }
 409          yield
 410          config.files_to_run
 411        end
 412
 413        expect(orderings.uniq.size).to eq(1)
 414      end
 415
 416      context 'when the given directories match the pattern' do
 417        it 'orders the files in a consistent ordering, regardless of the underlying OS ordering' do
 418          specify_consistent_ordering_of_files_to_run do
 419            config.pattern = 'a/*.rb'
 420            config.files_or_directories_to_run = 'a'
 421          end
 422        end
 423      end
 424
 425      context 'when the pattern is given relative to the given directories' do
 426        it 'orders the files in a consistent ordering, regardless of the underlying OS ordering' do
 427          specify_consistent_ordering_of_files_to_run do
 428            config.pattern = '*.rb'
 429            config.files_or_directories_to_run = 'a'
 430          end
 431        end
 432      end
 433
 434      context 'when given multiple file paths' do
 435        it 'orders the files in a consistent ordering, regardless of the given order' do
 436          File.stub(:directory?) { false } # fake it into thinking these a full file paths
 437
 438          files = ['a/b/c_spec.rb', 'c/b/a_spec.rb']
 439          config.files_or_directories_to_run = *files
 440          ordering_1 = config.files_to_run
 441
 442          config.files_or_directories_to_run = *(files.reverse)
 443          ordering_2 = config.files_to_run
 444
 445          expect(ordering_1).to eq(ordering_2)
 446        end
 447      end
 448    end
 449
 450    %w[pattern= filename_pattern=].each do |setter|
 451      describe "##{setter}" do
 452        context "with single pattern" do
 453          before { config.send(setter, "**/*_foo.rb") }
 454          it "loads files following pattern" do
 455            file = File.expand_path(File.dirname(__FILE__) + "/resources/a_foo.rb")
 456            config.files_or_directories_to_run = file
 457            expect(config.files_to_run).to include(file)
 458          end
 459
 460          it "loads files in directories following pattern" do
 461            dir = File.expand_path(File.dirname(__FILE__) + "/resources")
 462            config.files_or_directories_to_run = dir
 463            expect(config.files_to_run).to include("#{dir}/a_foo.rb")
 464          end
 465
 466          it "does not load files in directories not following pattern" do
 467            dir = File.expand_path(File.dirname(__FILE__) + "/resources")
 468            config.files_or_directories_to_run = dir
 469            expect(config.files_to_run).not_to include("#{dir}/a_bar.rb")
 470          end
 471        end
 472
 473        context "with multiple patterns" do
 474          it "supports comma separated values" do
 475            config.send(setter, "**/*_foo.rb,**/*_bar.rb")
 476            dir = File.expand_path(File.dirname(__FILE__) + "/resources")
 477            config.files_or_directories_to_run = dir
 478            expect(config.files_to_run).to include("#{dir}/a_foo.rb")
 479            expect(config.files_to_run).to include("#{dir}/a_bar.rb")
 480          end
 481
 482          it "supports comma separated values with spaces" do
 483            config.send(setter, "**/*_foo.rb, **/*_bar.rb")
 484            dir = File.expand_path(File.dirname(__FILE__) + "/resources")
 485            config.files_or_directories_to_run = dir
 486            expect(config.files_to_run).to include("#{dir}/a_foo.rb")
 487            expect(config.files_to_run).to include("#{dir}/a_bar.rb")
 488          end
 489
 490          it "supports curly braces glob syntax" do
 491            config.send(setter, "**/*_{foo,bar}.rb")
 492            dir = File.expand_path(File.dirname(__FILE__) + "/resources")
 493            config.files_or_directories_to_run = dir
 494            expect(config.files_to_run).to include("#{dir}/a_foo.rb")
 495            expect(config.files_to_run).to include("#{dir}/a_bar.rb")
 496          end
 497        end
 498      end
 499    end
 500
 501    describe "path with line number" do
 502      it "assigns the line number as a location filter" do
 503        config.files_or_directories_to_run = "path/to/a_spec.rb:37"
 504        expect(config.filter).to eq({:locations => {File.expand_path("path/to/a_spec.rb") => [37]}})
 505      end
 506    end
 507
 508    context "with full_description set" do
 509      it "overrides filters" do
 510        config.filter_run :focused => true
 511        config.full_description = "foo"
 512        expect(config.filter).not_to have_key(:focused)
 513      end
 514
 515      it 'is possible to access the full description regular expression' do
 516        config.full_description = "foo"
 517        expect(config.full_description).to eq(/foo/)
 518      end
 519    end
 520
 521    context "without full_description having been set" do
 522      it 'returns nil from #full_description' do
 523        expect(config.full_description).to eq nil
 524      end
 525    end
 526
 527    context "with line number" do
 528      it "assigns the file and line number as a location filter" do
 529        config.files_or_directories_to_run = "path/to/a_spec.rb:37"
 530        expect(config.filter).to eq({:locations => {File.expand_path("path/to/a_spec.rb") => [37]}})
 531      end
 532
 533      it "assigns multiple files with line numbers as location filters" do
 534        config.files_or_directories_to_run = "path/to/a_spec.rb:37", "other_spec.rb:44"
 535        expect(config.filter).to eq({:locations => {File.expand_path("path/to/a_spec.rb") => [37],
 536                                                File.expand_path("other_spec.rb") => [44]}})
 537      end
 538
 539      it "assigns files with multiple line numbers as location filters" do
 540        config.files_or_directories_to_run = "path/to/a_spec.rb:37", "path/to/a_spec.rb:44"
 541        expect(config.filter).to eq({:locations => {File.expand_path("path/to/a_spec.rb") => [37, 44]}})
 542      end
 543    end
 544
 545    context "with multiple line numbers" do
 546      it "assigns the file and line numbers as a location filter" do
 547        config.files_or_directories_to_run = "path/to/a_spec.rb:1:3:5:7"
 548        expect(config.filter).to eq({:locations => {File.expand_path("path/to/a_spec.rb") => [1,3,5,7]}})
 549      end
 550    end
 551
 552    it "assigns the example name as the filter on description" do
 553      config.full_description = "foo"
 554      expect(config.filter).to eq({:full_description => /foo/})
 555    end
 556
 557    it "assigns the example names as the filter on description if description is an array" do
 558      config.full_description = [ "foo", "bar" ]
 559      expect(config.filter).to eq({:full_description => Regexp.union(/foo/, /bar/)})
 560    end
 561
 562    it 'is possible to access the full description regular expression' do
 563      config.full_description = "foo","bar"
 564      expect(config.full_description).to eq Regexp.union(/foo/,/bar/)
 565    end
 566
 567    describe "#default_path" do
 568      it 'defaults to "spec"' do
 569        expect(config.default_path).to eq('spec')
 570      end
 571    end
 572
 573    describe "#include" do
 574
 575      module InstanceLevelMethods
 576        def you_call_this_a_blt?
 577          "egad man, where's the mayo?!?!?"
 578        end
 579      end
 580
 581      it_behaves_like "metadata hash builder" do
 582        def metadata_hash(*args)
 583          config.include(InstanceLevelMethods, *args)
 584          config.include_or_extend_modules.last.last
 585        end
 586      end
 587
 588      context "with no filter" do
 589        it "includes the given module into each example group" do
 590          RSpec.configure do |c|
 591            c.include(InstanceLevelMethods)
 592          end
 593
 594          group = ExampleGroup.describe('does like, stuff and junk', :magic_key => :include) { }
 595          expect(group).not_to respond_to(:you_call_this_a_blt?)
 596          expect(group.new.you_call_this_a_blt?).to eq("egad man, where's the mayo?!?!?")
 597        end
 598      end
 599
 600      context "with a filter" do
 601        it "includes the given module into each matching example group" do
 602          RSpec.configure do |c|
 603            c.include(InstanceLevelMethods, :magic_key => :include)
 604          end
 605
 606          group = ExampleGroup.describe('does like, stuff and junk', :magic_key => :include) { }
 607          expect(group).not_to respond_to(:you_call_this_a_blt?)
 608          expect(group.new.you_call_this_a_blt?).to eq("egad man, where's the mayo?!?!?")
 609        end
 610      end
 611
 612    end
 613
 614    describe "#extend" do
 615
 616      module ThatThingISentYou
 617        def that_thing
 618        end
 619      end
 620
 621      it_behaves_like "metadata hash builder" do
 622        def metadata_hash(*args)
 623          config.extend(ThatThingISentYou, *args)
 624          config.include_or_extend_modules.last.last
 625        end
 626      end
 627
 628      it "extends the given module into each matching example group" do
 629        RSpec.configure do |c|
 630          c.extend(ThatThingISentYou, :magic_key => :extend)
 631        end
 632
 633        group = ExampleGroup.describe(ThatThingISentYou, :magic_key => :extend) { }
 634        expect(group).to respond_to(:that_thing)
 635      end
 636
 637    end
 638
 639    describe "#run_all_when_everything_filtered?" do
 640
 641      it "defaults to false" do
 642        expect(config.run_all_when_everything_filtered?).to be_false
 643      end
 644
 645      it "can be queried with question method" do
 646        config.run_all_when_everything_filtered = true
 647        expect(config.run_all_when_everything_filtered?).to be_true
 648      end
 649    end
 650
 651    %w[color color_enabled].each do |color_option|
 652      describe "##{color_option}=" do
 653        context "given true" do
 654          before { config.send "#{color_option}=", true }
 655
 656          context "with config.tty? and output.tty?" do
 657            it "does not set color_enabled" do
 658              output = StringIO.new
 659              config.output_stream = output
 660
 661              config.tty = true
 662              config.output_stream.stub :tty? => true
 663
 664              expect(config.send(color_option)).to be_true
 665              expect(config.send(color_option, output)).to be_true
 666            end
 667          end
 668
 669          context "with config.tty? and !output.tty?" do
 670            it "sets color_enabled" do
 671              output = StringIO.new
 672              config.output_stream = output
 673
 674              config.tty = true
 675              config.output_stream.stub :tty? => false
 676
 677              expect(config.send(color_option)).to be_true
 678              expect(config.send(color_option, output)).to be_true
 679            end
 680          end
 681
 682          context "with config.tty? and !output.tty?" do
 683            it "does not set color_enabled" do
 684              output = StringIO.new
 685              config.output_stream = output
 686
 687              config.tty = false
 688              config.output_stream.stub :tty? => true
 689
 690              expect(config.send(color_option)).to be_true
 691              expect(config.send(color_option, output)).to be_true
 692            end
 693          end
 694
 695          context "with !config.tty? and !output.tty?" do
 696            it "does not set color_enabled" do
 697              output = StringIO.new
 698              config.output_stream = output
 699
 700              config.tty = false
 701              config.output_stream.stub :tty? => false
 702
 703              expect(config.send(color_option)).to be_false
 704              expect(config.send(color_option, output)).to be_false
 705            end
 706          end
 707
 708          context "on windows" do
 709            before do
 710              @original_host  = RbConfig::CONFIG['host_os']
 711              RbConfig::CONFIG['host_os'] = 'mingw'
 712              config.stub(:require)
 713              config.stub(:warn)
 714            end
 715
 716            after do
 717              RbConfig::CONFIG['host_os'] = @original_host
 718            end
 719
 720            context "with ANSICON available" do
 721              around(:each) { |e| with_env_vars('ANSICON' => 'ANSICON', &e) }
 722
 723              it "enables colors" do
 724                config.output_stream = StringIO.new
 725                config.output_stream.stub :tty? => true
 726                config.send "#{color_option}=", true
 727                expect(config.send(color_option)).to be_true
 728              end
 729
 730              it "leaves output stream intact" do
 731                config.output_stream = $stdout
 732                config.stub(:require) do |what|
 733                  config.output_stream = 'foo' if what =~ /Win32/
 734                end
 735                config.send "#{color_option}=", true
 736                expect(config.output_stream).to eq($stdout)
 737              end
 738            end
 739
 740            context "with ANSICON NOT available" do
 741              it "warns to install ANSICON" do
 742                config.stub(:require) { raise LoadError }
 743                config.should_receive(:warn).
 744                  with(/You must use ANSICON/)
 745                config.send "#{color_option}=", true
 746              end
 747
 748              it "sets color_enabled to false" do
 749                config.stub(:require) { raise LoadError }
 750                config.send "#{color_option}=", true
 751                config.color_enabled = true
 752                expect(config.send(color_option)).to be_false
 753              end
 754            end
 755          end
 756        end
 757      end
 758
 759      it "prefers incoming cli_args" do
 760        config.output_stream = StringIO.new
 761        config.output_stream.stub :tty? => true
 762        config.force :color => true
 763        config.color = false
 764        expect(config.color).to be_true
 765      end
 766    end
 767
 768    describe '#formatter=' do
 769      it "delegates to add_formatter (better API for user-facing configuration)" do
 770        config.should_receive(:add_formatter).with('these','options')
 771        config.add_formatter('these','options')
 772      end
 773    end
 774
 775    describe "#add_formatter" do
 776
 777      it "adds to the list of formatters" do
 778        config.add_formatter :documentation
 779        expect(config.formatters.first).to be_an_instance_of(Formatters::DocumentationFormatter)
 780      end
 781
 782      it "finds a formatter by name (w/ Symbol)" do
 783        config.add_formatter :documentation
 784        expect(config.formatters.first).to be_an_instance_of(Formatters::DocumentationFormatter)
 785      end
 786
 787      it "finds a formatter by name (w/ String)" do
 788        config.add_formatter 'documentation'
 789        expect(config.formatters.first).to be_an_instance_of(Formatters::DocumentationFormatter)
 790      end
 791
 792      it "finds a formatter by class" do
 793        formatter_class = Class.new(Formatters::BaseTextFormatter)
 794        config.add_formatter formatter_class
 795        expect(config.formatters.first).to be_an_instance_of(formatter_class)
 796      end
 797
 798      it "finds a formatter by class name" do
 799        stub_const("CustomFormatter", Class.new(Formatters::BaseFormatter))
 800        config.add_formatter "CustomFormatter"
 801        expect(config.formatters.first).to be_an_instance_of(CustomFormatter)
 802      end
 803
 804      it "finds a formatter by class fully qualified name" do
 805        stub_const("RSpec::CustomFormatter", Class.new(Formatters::BaseFormatter))
 806        config.add_formatter "RSpec::CustomFormatter"
 807        expect(config.formatters.first).to be_an_instance_of(RSpec::CustomFormatter)
 808      end
 809
 810      it "requires a formatter file based on its fully qualified name" do
 811        config.should_receive(:require).with('rspec/custom_formatter') do
 812          stub_const("RSpec::CustomFormatter", Class.new(Formatters::BaseFormatter))
 813        end
 814        config.add_formatter "RSpec::CustomFormatter"
 815        expect(config.formatters.first).to be_an_instance_of(RSpec::CustomFormatter)
 816      end
 817
 818      it "raises NameError if class is unresolvable" do
 819        config.should_receive(:require).with('rspec/custom_formatter3')
 820        expect(lambda { config.add_formatter "RSpec::CustomFormatter3" }).to raise_error(NameError)
 821      end
 822
 823      it "raises ArgumentError if formatter is unknown" do
 824        expect(lambda { config.add_formatter :progresss }).to raise_error(ArgumentError)
 825      end
 826
 827      context "with a 2nd arg defining the output" do
 828        it "creates a file at that path and sets it as the output" do
 829          path = File.join(Dir.tmpdir, 'output.txt')
 830          config.add_formatter('doc', path)
 831          expect(config.formatters.first.output).to be_a(File)
 832          expect(config.formatters.first.output.path).to eq(path)
 833        end
 834      end
 835    end
 836
 837    describe "#filter_run_including" do
 838      it_behaves_like "metadata hash builder" do
 839        def metadata_hash(*args)
 840          config.filter_run_including(*args)
 841          config.inclusion_filter
 842        end
 843      end
 844
 845      it "sets the filter with a hash" do
 846        config.filter_run_including :foo => true
 847        expect(config.inclusion_filter[:foo]).to be(true)
 848      end
 849
 850      it "sets the filter with a symbol" do
 851        RSpec.configuration.stub(:treat_symbols_as_metadata_keys_with_true_values? => true)
 852        config.filter_run_including :foo
 853        expect(config.inclusion_filter[:foo]).to be(true)
 854      end
 855
 856      it "merges with existing filters" do
 857        config.filter_run_including :foo => true
 858        config.filter_run_including :bar => false
 859
 860        expect(config.inclusion_filter[:foo]).to be(true)
 861        expect(config.inclusion_filter[:bar]).to be(false)
 862      end
 863    end
 864
 865    describe "#filter_run_excluding" do
 866      it_behaves_like "metadata hash builder" do
 867        def metadata_hash(*args)
 868          config.filter_run_excluding(*args)
 869          config.exclusion_filter
 870        end
 871      end
 872
 873      it "sets the filter" do
 874        config.filter_run_excluding :foo => true
 875        expect(config.exclusion_filter[:foo]).to be(true)
 876      end
 877
 878      it "sets the filter using a symbol" do
 879        RSpec.configuration.stub(:treat_symbols_as_metadata_keys_with_true_values? => true)
 880        config.filter_run_excluding :foo
 881        expect(config.exclusion_filter[:foo]).to be(true)
 882      end
 883
 884      it "merges with existing filters" do
 885        config.filter_run_excluding :foo => true
 886        config.filter_run_excluding :bar => false
 887
 888        expect(config.exclusion_filter[:foo]).to be(true)
 889        expect(config.exclusion_filter[:bar]).to be(false)
 890      end
 891    end
 892
 893    describe "#inclusion_filter" do
 894      it "returns {} even if set to nil" do
 895        config.inclusion_filter = nil
 896        expect(config.inclusion_filter).to eq({})
 897      end
 898    end
 899
 900    describe "#inclusion_filter=" do
 901      it "treats symbols as hash keys with true values when told to" do
 902        RSpec.configuration.stub(:treat_symbols_as_metadata_keys_with_true_values? => true)
 903        config.inclusion_filter = :foo
 904        expect(config.inclusion_filter).to eq({:foo => true})
 905      end
 906
 907      it "overrides any inclusion filters set on the command line or in configuration files" do
 908        config.force(:inclusion_filter => { :foo => :bar })
 909        config.inclusion_filter = {:want => :this}
 910        expect(config.inclusion_filter).to eq({:want => :this})
 911      end
 912    end
 913
 914    describe "#exclusion_filter" do
 915      it "returns {} even if set to nil" do
 916        config.exclusion_filter = nil
 917        expect(config.exclusion_filter).to eq({})
 918      end
 919
 920      describe "the default :if filter" do
 921        it "does not exclude a spec with  { :if => true } metadata" do
 922          expect(config.exclusion_filter[:if].call(true)).to be_false
 923        end
 924
 925        it "excludes a spec with  { :if => false } metadata" do
 926          expect(config.exclusion_filter[:if].call(false)).to be_true
 927        end
 928
 929        it "excludes a spec with  { :if => nil } metadata" do
 930          expect(config.exclusion_filter[:if].call(nil)).to be_true
 931        end
 932      end
 933
 934      describe "the default :unless filter" do
 935        it "excludes a spec with  { :unless => true } metadata" do
 936          expect(config.exclusion_filter[:unless].call(true)).to be_true
 937        end
 938
 939        it "does not exclude a spec with { :unless => false } metadata" do
 940          expect(config.exclusion_filter[:unless].call(false)).to be_false
 941        end
 942
 943        it "does not exclude a spec with { :unless => nil } metadata" do
 944          expect(config.exclusion_filter[:unless].call(nil)).to be_false
 945        end
 946      end
 947    end
 948
 949    describe "#exclusion_filter=" do
 950      it "treats symbols as hash keys with true values when told to" do
 951        RSpec.configuration.stub(:treat_symbols_as_metadata_keys_with_true_values? => true)
 952        config.exclusion_filter = :foo
 953        expect(config.exclusion_filter).to eq({:foo => true})
 954      end
 955
 956      it "overrides any exclusion filters set on the command line or in configuration files" do
 957        config.force(:exclusion_filter => { :foo => :bar })
 958        config.exclusion_filter = {:want => :this}
 959        expect(config.exclusion_filter).to eq({:want => :this})
 960      end
 961    end
 962
 963    describe "line_numbers=" do
 964      before { config.filter_manager.stub(:warn) }
 965
 966      it "sets the line numbers" do
 967        config.line_numbers = ['37']
 968        expect(config.filter).to eq({:line_numbers => [37]})
 969      end
 970
 971      it "overrides filters" do
 972        config.filter_run :focused => true
 973        config.line_numbers = ['37']
 974        expect(config.filter).to eq({:line_numbers => [37]})
 975      end
 976
 977      it "prevents subsequent filters" do
 978        config.line_numbers = ['37']
 979        config.filter_run :focused => true
 980        expect(config.filter).to eq({:line_numbers => [37]})
 981      end
 982    end
 983
 984    describe "line_numbers" do
 985      it "returns the line numbers from the filter" do
 986        config.line_numbers = ['42']
 987        expect(config.line_numbers).to eq [42]
 988      end
 989
 990      it "defaults to empty" do
 991        expect(config.line_numbers).to eq []
 992      end
 993    end
 994
 995    describe "#full_backtrace=" do
 996      context "given true" do
 997        it "clears the backtrace exclusion patterns" do
 998          config.full_backtrace = true
 999          expect(config.backtrace_exclusion_patterns).to eq([])
1000        end
1001      end
1002
1003      context "given false" do
1004        it "restores backtrace clean patterns" do
1005          config.full_backtrace = false
1006          expect(config.backtrace_exclusion_patterns).to eq(RSpec::Core::BacktraceCleaner::DEFAULT_EXCLUSION_PATTERNS)
1007        end
1008      end
1009
1010      it "doesn't impact other instances of config" do
1011        config_1 = Configuration.new
1012        config_2 = Configuration.new
1013
1014        config_1.full_backtrace = true
1015        expect(config_2.backtrace_exclusion_patterns).not_to be_empty
1016      end
1017    end
1018
1019    describe "#backtrace_clean_patterns=" do
1020      it "actually receives the new filter values" do
1021        RSpec.stub(:deprecate)
1022        config = Configuration.new
1023        config.backtrace_clean_patterns = [/.*/]
1024        expect(config.backtrace_cleaner.exclude? "this").to be_true
1025      end
1026    end
1027
1028    describe 'full_backtrace' do
1029      it 'returns true when backtrace patterns is empty' do
1030        config.backtrace_exclusion_patterns = []
1031        expect(config.full_backtrace?).to eq true
1032      end
1033
1034      it 'returns false when backtrace patterns isnt empty' do
1035        config.backtrace_exclusion_patterns = [:lib]
1036        expect(config.full_backtrace?).to eq false
1037      end
1038    end
1039
1040    describe "#backtrace_clean_patterns" do
1041      before { allow(RSpec).to receive(:deprecate) }
1042      it "is deprecated" do
1043        RSpec.should_receive(:deprecate)
1044        config = Configuration.new
1045        config.backtrace_clean_patterns
1046      end
1047
1048      it "can be appended to" do
1049        config = Configuration.new
1050        config.backtrace_clean_patterns << /.*/
1051        expect(config.backtrace_cleaner.exclude? "this").to be_true
1052      end
1053    end
1054
1055    describe ".backtrace_cleaner#exclude? defaults" do
1056      it "returns true for rspec files" do
1057        expect(config.backtrace_cleaner.exclude?("lib/rspec/core.rb")).to be_true
1058      end
1059
1060      it "returns true for spec_helper" do
1061        expect(config.backtrace_cleaner.exclude?("spec/spec_helper.rb")).to be_true
1062      end
1063
1064      it "returns true for java files (for JRuby)" do
1065        expect(config.backtrace_cleaner.exclude?("org/jruby/RubyArray.java:2336")).to be_true
1066      end
1067
1068      it "returns true for files within installed gems" do
1069        expect(config.backtrace_cleaner.exclude?('ruby-1.8.7-p334/gems/mygem-2.3.0/lib/mygem.rb')).to be_true
1070      end
1071
1072      it "returns false for files in projects containing 'gems' in the name" do
1073        expect(config.backtrace_cleaner.exclude?('code/my-gems-plugin/lib/plugin.rb')).to be_false
1074      end
1075
1076      it "returns false for something in the current working directory" do
1077        expect(config.backtrace_cleaner.exclude?("#{Dir.getwd}/arbitrary")).to be_false
1078      end
1079    end
1080
1081    describe "#debug=true" do
1082      before do
1083        if defined?(Debugger)
1084          @orig_debugger = Debugger
1085          Object.send(:remove_const, :Debugger)
1086        else
1087          @orig_debugger = nil
1088        end
1089        config.stub(:require)
1090        Object.const_set("Debugger", debugger)
1091      end
1092
1093      after do
1094        Object.send(:remove_const, :Debugger)
1095        Object.const_set("Debugger", @orig_debugger) if @orig_debugger
1096      end
1097
1098      let(:debugger) { double('Debugger').as_null_object }
1099
1100      it "requires 'ruby-debug'" do
1101        config.should_receive(:require).with('ruby-debug')
1102        config.debug = true
1103      end
1104
1105      it "starts the debugger" do
1106        debugger.should_receive(:start)
1107        config.debug = true
1108      end
1109    end
1110
1111    describe "#debug=false" do
1112      it "does not require 'ruby-debug'" do
1113        config.should_not_receive(:require).with('ruby-debug')
1114        config.debug = false
1115      end
1116    end
1117
1118    describe "#debug?" do
1119      it 'returns true if the debugger has been loaded' do
1120        stub_const("Debugger", Object.new)
1121        expect(config.debug?).to be_true
1122      end
1123
1124      it 'returns false if the debugger has not been loaded' do
1125        hide_const("Debugger")
1126        expect(config.debug?).to be_false
1127      end
1128    end
1129
1130    describe "#output=" do
1131      it "sets the output" do
1132        output = double("output")
1133        config.output = output
1134        expect(config.output).to equal(output)
1135      end
1136    end
1137
1138    describe "#libs=" do
1139      include_context "isolate load path mutation"
1140
1141      it "adds directories to the LOAD_PATH" do
1142        $LOAD_PATH.should_receive(:unshift).with("a/dir")
1143        config.libs = ["a/dir"]
1144      end
1145    end
1146
1147    describe "libs" do
1148      include_context "isolate load path mutation"
1149
1150      it 'records paths added to the load path' do
1151        config.libs = ["a/dir"]
1152        expect(config.libs).to eq ["a/dir"]
1153      end
1154    end
1155
1156    describe "#requires=" do
1157      before { RSpec.should_receive :deprecate }
1158
1159      it "requires the configured files" do
1160        config.should_receive(:require).with('foo').ordered
1161        config.should_receive(:require).with('bar').ordered
1162        config.requires = ['foo', 'bar']
1163      end
1164
1165      it "stores require paths" do
1166        config.should_receive(:require).with("a/path")
1167        config.requires = ["a/path"]
1168        expect(config.requires).to eq ['a/path']
1169      end
1170    end
1171
1172    describe "#add_setting" do
1173      describe "with no modifiers" do
1174        context "with no additional options" do
1175          before do
1176            config.add_setting :custom_option
1177          end
1178
1179          it "defaults to nil" do
1180            expect(config.custom_option).to be_nil
1181          end
1182
1183          it "adds a predicate" do
1184            expect(config.custom_option?).to be_false
1185          end
1186
1187          it "can be overridden" do
1188            config.custom_option = "a value"
1189            expect(config.custom_option).to eq("a value")
1190          end
1191        end
1192
1193        context "with :default => 'a value'" do
1194          before do
1195            config.add_setting :custom_option, :default => 'a value'
1196          end
1197
1198          it "defaults to 'a value'" do
1199            expect(config.custom_option).to eq("a value")
1200          end
1201
1202          it "returns true for the predicate" do
1203            expect(config.custom_option?).to be_true
1204          end
1205
1206          it "can be overridden with a truthy value" do
1207            config.custom_option = "a new value"
1208            expect(config.custom_option).to eq("a new value")
1209          end
1210
1211          it "can be overridden with nil" do
1212            config.custom_option = nil
1213            expect(config.custom_option).to eq(nil)
1214          end
1215
1216          it "can be overridden with false" do
1217            config.custom_option = false
1218            expect(config.custom_option).to eq(false)
1219          end
1220        end
1221      end
1222
1223      context "with :alias => " do
1224        it "is deprecated" do
1225          RSpec::should_receive(:deprecate).with(/:alias option/, :replacement => ":alias_with")
1226          config.add_setting :custom_option
1227          config.add_setting :another_custom_option, :alias => :custom_option
1228        end
1229      end
1230
1231      context "with :alias_with => " do
1232        before do
1233          config.add_setting :custom_option, :alias_with => :another_custom_option
1234        end
1235
1236        it "delegates the getter to the other option" do
1237          config.another_custom_option = "this value"
1238          expect(config.custom_option).to eq("this value")
1239        end
1240
1241        it "delegates the setter to the other option" do
1242          config.custom_option = "this value"
1243          expect(config.another_custom_option).to eq("this value")
1244        end
1245
1246        it "delegates the predicate to the other option" do
1247          config.custom_option = true
1248          expect(config.another_custom_option?).to be_true
1249        end
1250      end
1251    end
1252
1253    describe "#configure_group" do
1254      it "extends with 'extend'" do
1255        mod = Module.new
1256        group = ExampleGroup.describe("group", :foo => :bar)
1257
1258        config.extend(mod, :foo => :bar)
1259        config.configure_group(group)
1260        expect(group).to be_a(mod)
1261      end
1262
1263      it "extends with 'module'" do
1264        mod = Module.new
1265        group = ExampleGroup.describe("group", :foo => :bar)
1266
1267        config.include(mod, :foo => :bar)
1268        config.configure_group(group)
1269        expect(group.included_modules).to include(mod)
1270      end
1271
1272      it "requires only one matching filter" do
1273        mod = Module.new
1274        group = ExampleGroup.describe("group", :foo => :bar)
1275
1276        config.include(mod, :foo => :bar, :baz => :bam)
1277        config.configure_group(group)
1278        expect(group.included_modules).to include(mod)
1279      end
1280
1281      it "includes each one before deciding whether to include the next" do
1282        mod1 = Module.new do
1283          def self.included(host)
1284            host.metadata[:foo] = :bar
1285          end
1286        end
1287        mod2 = Module.new
1288
1289        group = ExampleGroup.describe("group")
1290
1291        config.include(mod1)
1292        config.include(mod2, :foo => :bar)
1293        config.configure_group(group)
1294        expect(group.included_modules).to include(mod1)
1295        expect(group.included_modules).to include(mod2)
1296      end
1297
1298      module IncludeOrExtendMeOnce
1299        def self.included(host)
1300          raise "included again" if host.instance_methods.include?(:foobar)
1301          host.class_eval { def foobar; end }
1302        end
1303
1304        def self.extended(host)
1305          raise "extended again" if host.respond_to?(:foobar)
1306          def host.foobar; end
1307        end
1308      end
1309
1310      it "doesn't include a module when already included in ancestor" do
1311        config.include(IncludeOrExtendMeOnce, :foo => :bar)
1312
1313        group = ExampleGroup.describe("group", :foo => :bar)
1314        child = group.describe("child")
1315
1316        config.configure_group(group)
1317        config.configure_group(child)
1318      end
1319
1320      it "doesn't extend when ancestor is already extended with same module" do
1321        config.extend(IncludeOrExtendMeOnce, :foo => :bar)
1322
1323        group = ExampleGroup.describe("group", :foo => :bar)
1324        child = group.describe("child")
1325
1326        config.configure_group(group)
1327        config.configure_group(child)
1328      end
1329    end
1330
1331    describe "#alias_example_to" do
1332      it_behaves_like "metadata hash builder" do
1333        after do
1334          RSpec::Core::ExampleGroup.module_eval do
1335            class << self
1336              undef :my_example_method if method_defined? :my_example_method
1337            end
1338          end
1339        end
1340        def metadata_hash(*args)
1341          config.alias_example_to :my_example_method, *args
1342          group = ExampleGroup.describe("group")
1343          example = group.my_example_method("description")
1344          example.metadata
1345        end
1346      end
1347    end
1348
1349    describe "#reset" do
1350      it "clears the reporter" do
1351        expect(config.reporter).not_to be_nil
1352        config.reset
1353        expect(config.instance_variable_get("@reporter")).to be_nil
1354      end
1355
1356      it "clears the formatters" do
1357        config.add_formatter "doc"
1358        config.reset
1359        expect(config.formatters).to be_empty
1360      end
1361    end
1362
1363    describe "#force" do
1364      it "forces order" do
1365        config.force :order => "default"
1366        config.order = "rand"
1367        expect(config.order).to eq("default")
1368      end
1369
1370      it "forces order and seed with :order => 'rand:37'" do
1371        config.force :order => "rand:37"
1372        config.order = "default"
1373        expect(config.order).to eq("rand")
1374        expect(config.seed).to eq(37)
1375      end
1376
1377      it "forces order and seed with :seed => '37'" do
1378        config.force :seed => "37"
1379        config.order = "default"
1380        expect(config.seed).to eq(37)
1381        expect(config.order).to eq("rand")
1382      end
1383
1384      it 'can set random ordering' do
1385        config.force :seed => "rand:37"
1386        RSpec.stub(:configuration => config)
1387        list = [1, 2, 3, 4].extend(Extensions::Ordered::Examples)
1388        Kernel.should_receive(:rand).and_return(3, 1, 4, 2)
1389        expect(list.ordered).to eq([2, 4, 1, 3])
1390      end
1391
1392      it "forces 'false' value" do
1393        config.add_setting :custom_option
1394        config.custom_option = true
1395        expect(config.custom_option?).to be_true
1396        config.force :custom_option => false
1397        expect(config.custom_option?).to be_false
1398        config.custom_option = true
1399        expect(config.custom_option?).to be_false
1400      end
1401    end
1402
1403    describe '#seed' do
1404      it 'returns the seed as an int' do
1405        config.seed = '123'
1406        expect(config.seed).to eq(123)
1407      end
1408    end
1409
1410    describe '#randomize?' do
1411      context 'with order set to :random' do
1412        before { config.order = :random }
1413
1414        it 'returns true' do
1415          expect(config.randomize?).to be_true
1416        end
1417      end
1418
1419      context 'with order set to nil' do
1420        before { config.order = nil }
1421
1422        it 'returns false' do
1423          expect(config.randomize?).to be_false
1424        end
1425      end
1426    end
1427
1428    describe '#order=' do
1429      context 'given "random:123"' do
1430        before { config.order = 'random:123' }
1431
1432        it 'sets order to "random"' do
1433          expect(config.order).to eq('random')
1434        end
1435
1436        it 'sets seed to 123' do
1437          expect(config.seed).to eq(123)
1438        end
1439
1440        it 'sets up random ordering' do
1441          RSpec.stub(:configuration => config)
1442          list = [1, 2, 3, 4].extend(Extensions::Ordered::Examples)
1443          Kernel.should_receive(:rand).and_return(3, 1, 4, 2)
1444          expect(list.ordered).to eq([2, 4, 1, 3])
1445        end
1446      end
1447
1448      context 'given "default"' do
1449        before do
1450          config.order = 'rand:123'
1451          config.order = 'default'
1452        end
1453
1454        it "sets the order to nil" do
1455          expect(config.order).to be_nil
1456        end
1457
1458        it "sets the seed to nil" do
1459          expect(config.seed).to be_nil
1460        end
1461
1462        it 'clears the random ordering' do
1463          RSpec.stub(:configuration => config)
1464          list = [1, 2, 3, 4].extend(Extensions::Ordered::Examples)
1465          Kernel.should_not_receive(:rand)
1466          expect(list.ordered).to eq([1, 2, 3, 4])
1467        end
1468      end
1469    end
1470
1471    describe "#order_examples" do
1472      before { RSpec.stub(:configuration => config) }
1473
1474      it 'sets a block that determines the ordering of a collection extended with Extensions::Ordered::Examples' do
1475        examples = [1, 2, 3, 4]
1476        examples.extend Extensions::Ordered::Examples
1477        config.order_examples { |examples_to_order| examples_to_order.reverse }
1478        expect(examples.ordered).to eq([4, 3, 2, 1])
1479      end
1480
1481      it 'sets #order to "custom"' do
1482        config.order_examples { |examples| examples.reverse }
1483   

Large files files are truncated, but you can click here to view the full file