rspec-core 2.7.1 → 2.8.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. data/README.md +1 -1
  2. data/features/command_line/order.feature +29 -0
  3. data/features/command_line/tag.feature +10 -9
  4. data/features/configuration/default_path.feature +2 -2
  5. data/features/filtering/exclusion_filters.feature +1 -1
  6. data/features/filtering/run_all_when_everything_filtered.feature +1 -1
  7. data/features/subject/attribute_of_subject.feature +1 -1
  8. data/lib/rspec/core.rb +148 -12
  9. data/lib/rspec/core/command_line.rb +2 -2
  10. data/lib/rspec/core/configuration.rb +300 -155
  11. data/lib/rspec/core/configuration_options.rb +34 -53
  12. data/lib/rspec/core/deprecation.rb +4 -0
  13. data/lib/rspec/core/drb_options.rb +72 -0
  14. data/lib/rspec/core/example.rb +58 -24
  15. data/lib/rspec/core/example_group.rb +10 -5
  16. data/lib/rspec/core/extensions.rb +1 -0
  17. data/lib/rspec/core/extensions/ordered.rb +16 -0
  18. data/lib/rspec/core/filter_manager.rb +170 -0
  19. data/lib/rspec/core/formatters/base_formatter.rb +3 -1
  20. data/lib/rspec/core/formatters/base_text_formatter.rb +6 -0
  21. data/lib/rspec/core/formatters/snippet_extractor.rb +1 -1
  22. data/lib/rspec/core/hooks.rb +197 -1
  23. data/lib/rspec/core/let.rb +3 -2
  24. data/lib/rspec/core/metadata.rb +25 -4
  25. data/lib/rspec/core/option_parser.rb +89 -54
  26. data/lib/rspec/core/pending.rb +41 -0
  27. data/lib/rspec/core/rake_task.rb +9 -25
  28. data/lib/rspec/core/reporter.rb +43 -19
  29. data/lib/rspec/core/shared_context.rb +35 -0
  30. data/lib/rspec/core/shared_example_group.rb +0 -1
  31. data/lib/rspec/core/subject.rb +4 -4
  32. data/lib/rspec/core/version.rb +1 -1
  33. data/lib/rspec/core/world.rb +34 -52
  34. data/spec/autotest/failed_results_re_spec.rb +2 -2
  35. data/spec/command_line/order_spec.rb +131 -0
  36. data/spec/rspec/core/command_line_spec.rb +2 -1
  37. data/spec/rspec/core/configuration_options_spec.rb +83 -163
  38. data/spec/rspec/core/configuration_spec.rb +311 -139
  39. data/spec/rspec/core/drb_options_spec.rb +131 -0
  40. data/spec/rspec/core/example_group_spec.rb +22 -11
  41. data/spec/rspec/core/example_spec.rb +1 -2
  42. data/spec/rspec/core/filter_manager_spec.rb +175 -0
  43. data/spec/rspec/core/formatters/helpers_spec.rb +1 -1
  44. data/spec/rspec/core/formatters/html_formatter_spec.rb +3 -2
  45. data/spec/rspec/core/formatters/text_mate_formatter_spec.rb +1 -1
  46. data/spec/rspec/core/metadata_spec.rb +21 -6
  47. data/spec/rspec/core/option_parser_spec.rb +74 -0
  48. data/spec/rspec/core/reporter_spec.rb +18 -1
  49. data/spec/rspec/core/shared_context_spec.rb +54 -17
  50. data/spec/rspec/core/subject_spec.rb +1 -1
  51. data/spec/rspec/core/world_spec.rb +7 -188
  52. data/spec/spec_helper.rb +47 -43
  53. data/spec/support/config_options_helper.rb +27 -0
  54. metadata +28 -12
  55. data/lib/rspec/core/expecting/with_rspec.rb +0 -9
  56. data/lib/rspec/core/expecting/with_stdlib.rb +0 -9
@@ -1,6 +1,9 @@
1
1
  require 'spec_helper'
2
2
  require 'tmpdir'
3
3
 
4
+ # so the stdlib module is available...
5
+ module Test; module Unit; module Assertions; end; end; end
6
+
4
7
  module RSpec::Core
5
8
 
6
9
  describe Configuration do
@@ -48,12 +51,19 @@ module RSpec::Core
48
51
  end
49
52
  end
50
53
 
51
- describe "#mock_framework=" do
54
+ describe "#mock_framework="do
55
+ it "delegates to mock_with" do
56
+ config.should_receive(:mock_with).with(:rspec)
57
+ config.mock_framework = :rspec
58
+ end
59
+ end
60
+
61
+ describe "#mock_with" do
52
62
  [:rspec, :mocha, :rr, :flexmock].each do |framework|
53
63
  context "with #{framework}" do
54
64
  it "requires the adapter for #{framework.inspect}" do
55
65
  config.should_receive(:require).with("rspec/core/mocking/with_#{framework}")
56
- config.mock_framework = framework
66
+ config.mock_with framework
57
67
  end
58
68
  end
59
69
  end
@@ -62,55 +72,70 @@ module RSpec::Core
62
72
  it "sets the mock_framework_adapter to that module" do
63
73
  config.stub(:require)
64
74
  mod = Module.new
65
- config.mock_framework = mod
75
+ config.mock_with mod
66
76
  config.mock_framework.should eq(mod)
67
77
  end
68
78
  end
69
79
 
70
80
  it "uses the null adapter when set to any unknown key" do
71
81
  config.should_receive(:require).with('rspec/core/mocking/with_absolutely_nothing')
72
- config.mock_framework = :crazy_new_mocking_framework_ive_not_yet_heard_of
82
+ config.mock_with :crazy_new_mocking_framework_ive_not_yet_heard_of
73
83
  end
74
84
 
75
85
  context 'when there are already some example groups defined' do
76
- before(:each) do
77
- RSpec.world.stub(:example_groups).and_return([double.as_null_object])
78
- end
86
+ before(:each) { config.stub(:require) }
79
87
 
80
88
  it 'raises an error since this setting must be applied before any groups are defined' do
89
+ RSpec.world.stub(:example_groups).and_return([double.as_null_object])
81
90
  expect {
82
- config.mock_framework = :rspec
91
+ config.mock_with :mocha
83
92
  }.to raise_error(/must be configured before any example groups are defined/)
84
93
  end
85
- end
86
- end
87
94
 
88
- describe "#mock_with" do
89
- it "delegates to mock_framework=" do
90
- config.should_receive(:mock_framework=).with(:rspec)
91
- config.mock_with :rspec
95
+ it 'does not raise an error if the default `mock_with :rspec` is re-configured' do
96
+ config.mock_framework # called by RSpec when configuring the first example group
97
+ RSpec.world.stub(:example_groups).and_return([double.as_null_object])
98
+ config.mock_with :rspec
99
+ end
100
+
101
+ it 'does not raise an error if re-setting the same config' do
102
+ groups = []
103
+ RSpec.world.stub(:example_groups => groups)
104
+ config.mock_with :mocha
105
+ groups << double.as_null_object
106
+ config.mock_with :mocha
107
+ end
92
108
  end
93
109
  end
94
110
 
95
111
  describe "#expectation_framework" do
96
112
  it "defaults to :rspec" do
97
- config.should_receive(:require).with('rspec/core/expecting/with_rspec')
113
+ config.should_receive(:require).with('rspec/expectations')
98
114
  config.expectation_frameworks
99
115
  end
100
116
  end
101
117
 
102
118
  describe "#expectation_framework=" do
103
119
  it "delegates to expect_with=" do
104
- config.should_receive(:expect_with).with([:rspec])
120
+ config.should_receive(:expect_with).with(:rspec)
105
121
  config.expectation_framework = :rspec
106
122
  end
107
123
  end
108
124
 
109
125
  describe "#expect_with" do
110
- [:rspec, :stdlib].each do |framework|
126
+ before(:each) do
127
+ # we need to prevent stdlib from being required because it defines a
128
+ # `pass` method that conflicts with our `pass` matcher.
129
+ config.stub(:require)
130
+ end
131
+
132
+ [
133
+ [:rspec, 'rspec/expectations'],
134
+ [:stdlib, 'test/unit/assertions']
135
+ ].each do |(framework, required_file)|
111
136
  context "with #{framework}" do
112
- it "requires the adapter for #{framework.inspect}" do
113
- config.should_receive(:require).with("rspec/core/expecting/with_#{framework}")
137
+ it "requires #{required_file}" do
138
+ config.should_receive(:require).with(required_file)
114
139
  config.expect_with framework
115
140
  end
116
141
  end
@@ -123,15 +148,26 @@ module RSpec::Core
123
148
  end
124
149
 
125
150
  context 'when there are already some example groups defined' do
126
- before(:each) do
127
- RSpec.world.stub(:example_groups).and_return([double.as_null_object])
128
- end
129
-
130
151
  it 'raises an error since this setting must be applied before any groups are defined' do
152
+ RSpec.world.stub(:example_groups).and_return([double.as_null_object])
131
153
  expect {
132
154
  config.expect_with :rspec
133
155
  }.to raise_error(/must be configured before any example groups are defined/)
134
156
  end
157
+
158
+ it 'does not raise an error if the default `expect_with :rspec` is re-configured' do
159
+ config.expectation_frameworks # called by RSpec when configuring the first example group
160
+ RSpec.world.stub(:example_groups).and_return([double.as_null_object])
161
+ config.expect_with :rspec
162
+ end
163
+
164
+ it 'does not raise an error if re-setting the same config' do
165
+ groups = []
166
+ RSpec.world.stub(:example_groups => groups)
167
+ config.expect_with :stdlib
168
+ groups << double.as_null_object
169
+ config.expect_with :stdlib
170
+ end
135
171
  end
136
172
  end
137
173
 
@@ -185,9 +221,40 @@ module RSpec::Core
185
221
  config.files_to_run.should eq(["spec/rspec/core/resources/a_spec.rb"])
186
222
  end
187
223
 
224
+ context "with <path>:<line_number>" do
225
+ it "overrides inclusion filters set on config" do
226
+ config.filter_run_including :foo => :bar
227
+ config.files_or_directories_to_run = "path/to/file.rb:37"
228
+ config.inclusion_filter.size.should eq(1)
229
+ config.inclusion_filter[:locations].keys.first.should match(/path\/to\/file\.rb$/)
230
+ config.inclusion_filter[:locations].values.first.should eq([37])
231
+ end
232
+
233
+ it "overrides inclusion filters set before config" do
234
+ config.force(:inclusion_filter => {:foo => :bar})
235
+ config.files_or_directories_to_run = "path/to/file.rb:37"
236
+ config.inclusion_filter.size.should eq(1)
237
+ config.inclusion_filter[:locations].keys.first.should match(/path\/to\/file\.rb$/)
238
+ config.inclusion_filter[:locations].values.first.should eq([37])
239
+ end
240
+
241
+ it "clears exclusion filters set on config" do
242
+ config.exclusion_filter = { :foo => :bar }
243
+ config.files_or_directories_to_run = "path/to/file.rb:37"
244
+ config.exclusion_filter.should be_empty,
245
+ "expected exclusion filter to be empty:\n#{config.exclusion_filter}"
246
+ end
247
+
248
+ it "clears exclusion filters set before config" do
249
+ config.force(:exclusion_filter => { :foo => :bar })
250
+ config.files_or_directories_to_run = "path/to/file.rb:37"
251
+ config.exclusion_filter.should be_empty,
252
+ "expected exclusion filter to be empty:\n#{config.exclusion_filter}"
253
+ end
254
+ end
255
+
188
256
  context "with default pattern" do
189
257
  it "loads files named _spec.rb" do
190
- dir = "spec/rspec/core/resources"
191
258
  config.files_or_directories_to_run = "spec/rspec/core/resources"
192
259
  config.files_to_run.should eq([ "spec/rspec/core/resources/a_spec.rb"])
193
260
  end
@@ -198,7 +265,7 @@ module RSpec::Core
198
265
  config.files_to_run.should eq([file])
199
266
  end
200
267
  end
201
-
268
+
202
269
  context "with default default_path" do
203
270
  it "loads files in the default path when run by rspec" do
204
271
  config.stub(:command) { 'rspec' }
@@ -265,7 +332,7 @@ module RSpec::Core
265
332
  end
266
333
 
267
334
  context "with full_description" do
268
- it "overrides :focused" do
335
+ it "overrides filters" do
269
336
  config.filter_run :focused => true
270
337
  config.full_description = "foo"
271
338
  config.filter.should_not have_key(:focused)
@@ -302,7 +369,7 @@ module RSpec::Core
302
369
  config.full_description = "foo"
303
370
  config.filter.should eq({:full_description => /foo/})
304
371
  end
305
-
372
+
306
373
  describe "#default_path" do
307
374
  it 'defaults to "spec"' do
308
375
  config.default_path.should eq('spec')
@@ -387,93 +454,104 @@ module RSpec::Core
387
454
  end
388
455
  end
389
456
 
390
- describe "#color_enabled=" do
391
- context "given true" do
392
- context "with non-tty output and no autotest" do
393
- it "does not set color_enabled" do
394
- config.output_stream = StringIO.new
395
- config.output_stream.stub(:tty?) { false }
396
- config.tty = false
397
- config.color_enabled = true
398
- config.color_enabled.should be_false
399
- end
400
- end
401
-
402
- context "with tty output" do
403
- it "does not set color_enabled" do
404
- config.output_stream = StringIO.new
405
- config.output_stream.stub(:tty?) { true }
406
- config.tty = false
407
- config.color_enabled = true
408
- config.color_enabled.should be_true
409
- end
410
- end
411
-
412
- context "with tty set" do
413
- it "does not set color_enabled" do
414
- config.output_stream = StringIO.new
415
- config.output_stream.stub(:tty?) { false }
416
- config.tty = true
417
- config.color_enabled = true
418
- config.color_enabled.should be_true
457
+ %w[color color_enabled].each do |color_option|
458
+ describe "##{color_option}=" do
459
+ context "given true" do
460
+ context "with non-tty output and no autotest" do
461
+ it "does not set color_enabled" do
462
+ config.output_stream = StringIO.new
463
+ config.output_stream.stub(:tty?) { false }
464
+ config.tty = false
465
+ config.send "#{color_option}=", true
466
+ config.send(color_option).should be_false
467
+ end
419
468
  end
420
- end
421
469
 
422
- context "on windows" do
423
- before do
424
- @original_host = RbConfig::CONFIG['host_os']
425
- RbConfig::CONFIG['host_os'] = 'mingw'
426
- config.stub(:require)
427
- config.stub(:warn)
470
+ context "with tty output" do
471
+ it "does not set color_enabled" do
472
+ config.output_stream = StringIO.new
473
+ config.output_stream.stub(:tty?) { true }
474
+ config.tty = false
475
+ config.send "#{color_option}=", true
476
+ config.send(color_option).should be_true
477
+ end
428
478
  end
429
479
 
430
- after do
431
- RbConfig::CONFIG['host_os'] = @original_host
480
+ context "with tty set" do
481
+ it "does not set color_enabled" do
482
+ config.output_stream = StringIO.new
483
+ config.output_stream.stub(:tty?) { false }
484
+ config.tty = true
485
+ config.send "#{color_option}=", true
486
+ config.send(color_option).should be_true
487
+ end
432
488
  end
433
489
 
434
- context "with ANSICON available" do
435
- before(:all) do
436
- @original_ansicon = ENV['ANSICON']
437
- ENV['ANSICON'] = 'ANSICON'
490
+ context "on windows" do
491
+ before do
492
+ @original_host = RbConfig::CONFIG['host_os']
493
+ RbConfig::CONFIG['host_os'] = 'mingw'
494
+ config.stub(:require)
495
+ config.stub(:warn)
438
496
  end
439
497
 
440
- after(:all) do
441
- ENV['ANSICON'] = @original_ansicon
442
- end
443
-
444
- it "enables colors" do
445
- config.output_stream = StringIO.new
446
- config.output_stream.stub(:tty?) { true }
447
- config.color_enabled = true
448
- config.color_enabled.should be_true
498
+ after do
499
+ RbConfig::CONFIG['host_os'] = @original_host
449
500
  end
450
501
 
451
- it "leaves output stream intact" do
452
- config.output_stream = $stdout
453
- config.stub(:require) do |what|
454
- config.output_stream = 'foo' if what =~ /Win32/
502
+ context "with ANSICON available" do
503
+ before(:all) do
504
+ @original_ansicon = ENV['ANSICON']
505
+ ENV['ANSICON'] = 'ANSICON'
506
+ end
507
+
508
+ after(:all) do
509
+ ENV['ANSICON'] = @original_ansicon
455
510
  end
456
- config.color_enabled = true
457
- config.output_stream.should eq($stdout)
458
- end
459
- end
460
511
 
461
- context "with ANSICON NOT available" do
462
- it "warns to install ANSICON" do
463
- config.stub(:require) { raise LoadError }
464
- config.should_receive(:warn).
465
- with(/You must use ANSICON/)
466
- config.color_enabled = true
512
+ it "enables colors" do
513
+ config.output_stream = StringIO.new
514
+ config.output_stream.stub(:tty?) { true }
515
+ config.send "#{color_option}=", true
516
+ config.send(color_option).should be_true
517
+ end
518
+
519
+ it "leaves output stream intact" do
520
+ config.output_stream = $stdout
521
+ config.stub(:require) do |what|
522
+ config.output_stream = 'foo' if what =~ /Win32/
523
+ end
524
+ config.send "#{color_option}=", true
525
+ config.output_stream.should eq($stdout)
526
+ end
467
527
  end
468
528
 
469
- it "sets color_enabled to false" do
470
- config.stub(:require) { raise LoadError }
471
- config.color_enabled = true
472
- config.color_enabled.should be_false
529
+ context "with ANSICON NOT available" do
530
+ it "warns to install ANSICON" do
531
+ config.stub(:require) { raise LoadError }
532
+ config.should_receive(:warn).
533
+ with(/You must use ANSICON/)
534
+ config.send "#{color_option}=", true
535
+ end
536
+
537
+ it "sets color_enabled to false" do
538
+ config.stub(:require) { raise LoadError }
539
+ config.send "#{color_option}=", true
540
+ config.color_enabled = true
541
+ config.send(color_option).should be_false
542
+ end
473
543
  end
474
544
  end
475
545
  end
476
546
  end
547
+
548
+ it "prefers incoming cli_args" do
549
+ config.output_stream = StringIO.new
550
+ config.output_stream.stub :tty? => true
551
+ config.force :color => true
552
+ config.color = false
553
+ config.color.should be_true
554
+ end
477
555
  end
478
556
 
479
557
  describe '#formatter=' do
@@ -507,9 +585,9 @@ module RSpec::Core
507
585
  end
508
586
 
509
587
  it "finds a formatter by class name" do
510
- Object.const_set("CustomFormatter", Class.new(Formatters::BaseFormatter))
511
- config.add_formatter "CustomFormatter"
512
- config.formatters.first.should be_an_instance_of(CustomFormatter)
588
+ Object.const_set("ACustomFormatter", Class.new(Formatters::BaseFormatter))
589
+ config.add_formatter "ACustomFormatter"
590
+ config.formatters.first.should be_an_instance_of(ACustomFormatter)
513
591
  end
514
592
 
515
593
  it "finds a formatter by class fully qualified name" do
@@ -543,47 +621,41 @@ module RSpec::Core
543
621
  config.formatters.first.output.path.should eq(path)
544
622
  end
545
623
  end
546
-
547
624
  end
548
625
 
549
- describe "#filter_run" do
626
+ describe "#filter_run_including" do
550
627
  it_behaves_like "metadata hash builder" do
551
628
  def metadata_hash(*args)
552
- config.filter_run(*args)
553
- config.filter
629
+ config.filter_run_including(*args)
630
+ config.inclusion_filter
554
631
  end
555
632
  end
556
633
 
557
- it "sets the filter" do
558
- config.filter_run :focus => true
559
- config.filter[:focus].should be(true)
634
+ it "sets the filter with a hash" do
635
+ config.filter_run_including :foo => true
636
+ config.inclusion_filter[:foo].should be(true)
637
+ end
638
+
639
+ it "sets the filter with a symbol" do
640
+ RSpec.configuration.stub(:treat_symbols_as_metadata_keys_with_true_values? => true)
641
+ config.filter_run_including :foo
642
+ config.inclusion_filter[:foo].should be(true)
560
643
  end
561
644
 
562
645
  it "merges with existing filters" do
563
- config.filter_run :filter1 => true
564
- config.filter_run :filter2 => false
646
+ config.filter_run_including :foo => true
647
+ config.filter_run_including :bar => false
565
648
 
566
- config.filter[:filter1].should be(true)
567
- config.filter[:filter2].should be(false)
649
+ config.inclusion_filter[:foo].should be(true)
650
+ config.inclusion_filter[:bar].should be(false)
568
651
  end
569
652
 
570
- it "warns if :line_numbers is already a filter" do
571
- config.filter_run :line_numbers => [100]
572
- config.should_receive(:warn).with(
573
- "Filtering by {:focus=>true} is not possible since you " \
574
- "are already filtering by {:line_numbers=>[100]}"
575
- )
576
- config.filter_run :focus => true
653
+ it "gets overrided by forced options" do
654
+ config.force_exclude :foo => true
655
+ config.filter_run_including :foo => true
656
+ config.inclusion_filter.should eq({})
577
657
  end
578
658
 
579
- it "warns if :full_description is already a filter" do
580
- config.filter_run :full_description => 'foo'
581
- config.should_receive(:warn).with(
582
- "Filtering by {:focus=>true} is not possible since you " \
583
- "are already filtering by {:full_description=>\"foo\"}"
584
- )
585
- config.filter_run :focus => true
586
- end
587
659
  end
588
660
 
589
661
  describe "#filter_run_excluding" do
@@ -595,16 +667,29 @@ module RSpec::Core
595
667
  end
596
668
 
597
669
  it "sets the filter" do
598
- config.filter_run_excluding :slow => true
599
- config.exclusion_filter[:slow].should be(true)
670
+ config.filter_run_excluding :foo => true
671
+ config.exclusion_filter[:foo].should be(true)
672
+ end
673
+
674
+ it "sets the filter using a symbol" do
675
+ RSpec.configuration.stub(:treat_symbols_as_metadata_keys_with_true_values? => true)
676
+ config.filter_run_excluding :foo
677
+ config.exclusion_filter[:foo].should be(true)
600
678
  end
601
679
 
602
680
  it "merges with existing filters" do
603
- config.filter_run_excluding :filter1 => true
604
- config.filter_run_excluding :filter2 => false
681
+ config.filter_run_excluding :foo => true
682
+ config.filter_run_excluding :bar => false
605
683
 
606
- config.exclusion_filter[:filter1].should be(true)
607
- config.exclusion_filter[:filter2].should be(false)
684
+ config.exclusion_filter[:foo].should be(true)
685
+ config.exclusion_filter[:bar].should be(false)
686
+ end
687
+
688
+ it "gets overrided by forced options" do
689
+ config.exclusion_filter.clear
690
+ config.force_include :foo => true
691
+ config.filter_run_excluding :foo => true
692
+ config.exclusion_filter.should eq({})
608
693
  end
609
694
  end
610
695
 
@@ -615,6 +700,13 @@ module RSpec::Core
615
700
  end
616
701
  end
617
702
 
703
+ describe "#inclusion_filter=" do
704
+ it "treats symbols as hash keys with true values when told to" do
705
+ RSpec.configuration.stub(:treat_symbols_as_metadata_keys_with_true_values? => true)
706
+ config.inclusion_filter = :foo
707
+ config.inclusion_filter.should eq({:foo => true})
708
+ end
709
+ end
618
710
 
619
711
  describe "#exclusion_filter" do
620
712
  it "returns {} even if set to nil" do
@@ -655,21 +747,29 @@ module RSpec::Core
655
747
  end
656
748
  end
657
749
 
750
+ describe "#exclusion_filter=" do
751
+ it "treats symbols as hash keys with true values when told to" do
752
+ RSpec.configuration.stub(:treat_symbols_as_metadata_keys_with_true_values? => true)
753
+ config.exclusion_filter = :foo
754
+ config.exclusion_filter.should eq({:foo => true})
755
+ end
756
+ end
757
+
658
758
  describe "line_numbers=" do
659
- before { config.stub(:warn) }
759
+ before { config.filter_manager.stub(:warn) }
660
760
 
661
761
  it "sets the line numbers" do
662
762
  config.line_numbers = ['37']
663
763
  config.filter.should eq({:line_numbers => [37]})
664
764
  end
665
765
 
666
- it "overrides :focused" do
766
+ it "overrides filters" do
667
767
  config.filter_run :focused => true
668
768
  config.line_numbers = ['37']
669
769
  config.filter.should eq({:line_numbers => [37]})
670
770
  end
671
771
 
672
- it "prevents :focused" do
772
+ it "prevents subsequent filters" do
673
773
  config.line_numbers = ['37']
674
774
  config.filter_run :focused => true
675
775
  config.filter.should eq({:line_numbers => [37]})
@@ -779,7 +879,9 @@ module RSpec::Core
779
879
  describe "#add_setting" do
780
880
  describe "with no modifiers" do
781
881
  context "with no additional options" do
782
- before { config.add_setting :custom_option }
882
+ before do
883
+ config.add_setting :custom_option
884
+ end
783
885
 
784
886
  it "defaults to nil" do
785
887
  config.custom_option.should be_nil
@@ -796,7 +898,9 @@ module RSpec::Core
796
898
  end
797
899
 
798
900
  context "with :default => 'a value'" do
799
- before { config.add_setting :custom_option, :default => 'a value' }
901
+ before do
902
+ config.add_setting :custom_option, :default => 'a value'
903
+ end
800
904
 
801
905
  it "defaults to 'a value'" do
802
906
  config.custom_option.should eq("a value")
@@ -824,10 +928,17 @@ module RSpec::Core
824
928
  end
825
929
 
826
930
  context "with :alias => " do
827
- before do
931
+ it "is deprecated" do
932
+ RSpec::should_receive(:warn).with(/deprecated/)
828
933
  config.add_setting :custom_option
829
934
  config.add_setting :another_custom_option, :alias => :custom_option
830
935
  end
936
+ end
937
+
938
+ context "with :alias_with => " do
939
+ before do
940
+ config.add_setting :custom_option, :alias_with => :another_custom_option
941
+ end
831
942
 
832
943
  it "delegates the getter to the other option" do
833
944
  config.another_custom_option = "this value"
@@ -894,10 +1005,17 @@ module RSpec::Core
894
1005
 
895
1006
  describe "#alias_example_to" do
896
1007
  it_behaves_like "metadata hash builder" do
1008
+ after do
1009
+ RSpec::Core::ExampleGroup.module_eval do
1010
+ class << self
1011
+ undef :my_example_method if method_defined? :my_example_method
1012
+ end
1013
+ end
1014
+ end
897
1015
  def metadata_hash(*args)
898
- config.alias_example_to :my_example, *args
1016
+ config.alias_example_to :my_example_method, *args
899
1017
  group = ExampleGroup.describe("group")
900
- example = group.my_example("description")
1018
+ example = group.my_example_method("description")
901
1019
  example.metadata
902
1020
  end
903
1021
  end
@@ -916,5 +1034,59 @@ module RSpec::Core
916
1034
  config.formatters.should be_empty
917
1035
  end
918
1036
  end
1037
+
1038
+ describe '#seed' do
1039
+ it 'returns the seed as an int' do
1040
+ config.seed = '123'
1041
+ config.seed.should eq(123)
1042
+ end
1043
+ end
1044
+
1045
+ describe '#randomize?' do
1046
+ context 'with order set to :random' do
1047
+ before { config.order = :random }
1048
+
1049
+ it 'returns true' do
1050
+ config.randomize?.should be_true
1051
+ end
1052
+ end
1053
+
1054
+ context 'with order set to nil' do
1055
+ before { config.order = nil }
1056
+
1057
+ it 'returns false' do
1058
+ config.randomize?.should be_false
1059
+ end
1060
+ end
1061
+ end
1062
+
1063
+ describe '#order=' do
1064
+ context 'given "random:123"' do
1065
+ before { config.order = 'random:123' }
1066
+
1067
+ it 'sets order to "random"' do
1068
+ config.order.should eq('random')
1069
+ end
1070
+
1071
+ it 'sets seed to 123' do
1072
+ config.seed.should eq(123)
1073
+ end
1074
+ end
1075
+
1076
+ context 'given "default"' do
1077
+ before do
1078
+ config.order = 'rand:123'
1079
+ config.order = 'default'
1080
+ end
1081
+
1082
+ it "sets the order to nil" do
1083
+ config.order.should be_nil
1084
+ end
1085
+
1086
+ it "sets the seed to nil" do
1087
+ config.seed.should be_nil
1088
+ end
1089
+ end
1090
+ end
919
1091
  end
920
1092
  end