rspec-core 2.14.8 → 2.99.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +8 -8
  2. data/Changelog.md +54 -8
  3. data/features/command_line/order.feature +5 -8
  4. data/features/configuration/custom_settings.feature +10 -10
  5. data/features/configuration/deprecation_stream.feature +3 -3
  6. data/features/configuration/read_options_from_file.feature +1 -1
  7. data/features/example_groups/shared_examples.feature +2 -2
  8. data/features/hooks/around_hooks.feature +1 -1
  9. data/features/metadata/current_example.feature +43 -4
  10. data/features/metadata/user_defined.feature +12 -12
  11. data/lib/autotest/rspec2.rb +60 -56
  12. data/lib/rspec/core.rb +40 -2
  13. data/lib/rspec/core/caller_filter.rb +55 -0
  14. data/lib/rspec/core/command_line.rb +2 -2
  15. data/lib/rspec/core/configuration.rb +201 -13
  16. data/lib/rspec/core/deprecation.rb +2 -7
  17. data/lib/rspec/core/example.rb +5 -8
  18. data/lib/rspec/core/example_group.rb +101 -17
  19. data/lib/rspec/core/filter_manager.rb +2 -2
  20. data/lib/rspec/core/formatters/deprecation_formatter.rb +173 -15
  21. data/lib/rspec/core/formatters/text_mate_formatter.rb +0 -12
  22. data/lib/rspec/core/hooks.rb +1 -1
  23. data/lib/rspec/core/memoized_helpers.rb +49 -17
  24. data/lib/rspec/core/metadata.rb +1 -1
  25. data/lib/rspec/core/option_parser.rb +8 -3
  26. data/lib/rspec/core/pending.rb +14 -10
  27. data/lib/rspec/core/rake_task.rb +30 -6
  28. data/lib/rspec/core/runner.rb +9 -0
  29. data/lib/rspec/core/shared_example_group.rb +11 -9
  30. data/lib/rspec/core/shared_example_group/collection.rb +3 -1
  31. data/lib/rspec/core/version.rb +1 -2
  32. data/spec/command_line/order_spec.rb +4 -4
  33. data/spec/rspec/core/backtrace_cleaner_spec.rb +10 -10
  34. data/spec/rspec/core/caller_filter_spec.rb +58 -0
  35. data/spec/rspec/core/command_line_spec.rb +1 -0
  36. data/spec/rspec/core/configuration_options_spec.rb +6 -6
  37. data/spec/rspec/core/configuration_spec.rb +285 -52
  38. data/spec/rspec/core/deprecation_spec.rb +10 -29
  39. data/spec/rspec/core/deprecations_spec.rb +0 -14
  40. data/spec/rspec/core/example_group_spec.rb +74 -56
  41. data/spec/rspec/core/example_spec.rb +54 -17
  42. data/spec/rspec/core/filter_manager_spec.rb +2 -2
  43. data/spec/rspec/core/formatters/deprecation_formatter_spec.rb +156 -52
  44. data/spec/rspec/core/formatters/html_formatter_spec.rb +1 -1
  45. data/spec/rspec/core/formatters/text_mate_formatter_spec.rb +1 -2
  46. data/spec/rspec/core/hooks_spec.rb +2 -0
  47. data/spec/rspec/core/memoized_helpers_spec.rb +154 -113
  48. data/spec/rspec/core/metadata_spec.rb +25 -25
  49. data/spec/rspec/core/option_parser_spec.rb +19 -1
  50. data/spec/rspec/core/project_initializer_spec.rb +4 -4
  51. data/spec/rspec/core/rake_task_spec.rb +25 -4
  52. data/spec/rspec/core/shared_context_spec.rb +4 -4
  53. data/spec/rspec/core/shared_example_group_spec.rb +1 -1
  54. data/spec/rspec/core_spec.rb +36 -2
  55. data/spec/spec_helper.rb +3 -0
  56. data/spec/support/helper_methods.rb +16 -1
  57. data/spec/support/shared_example_groups.rb +1 -0
  58. data/spec/support/silence_dsl_deprecations.rb +32 -0
  59. metadata +10 -7
  60. data/spec/rspec/core/formatters/text_mate_formatted-2.1.0.html +0 -425
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+ require 'rspec/core/caller_filter'
3
+
4
+ module RSpec
5
+ describe CallerFilter do
6
+ def ruby_files_in_lib(lib)
7
+ # http://rubular.com/r/HYpUMftlG2
8
+ path = $LOAD_PATH.find { |p| p.match(/\/rspec-#{lib}(-[a-f0-9]+)?\/lib/) }
9
+
10
+ unless path
11
+ pending "Cannot locate rspec-#{lib} files."
12
+ end
13
+
14
+ Dir["#{path}/**/*.rb"].sort.tap do |files|
15
+ # Just a sanity check...
16
+ expect(files.count).to be > 10
17
+ end
18
+ end
19
+
20
+ describe "the filtering regex" do
21
+ def unmatched_from(files)
22
+ files.reject { |file| file.match(CallerFilter::LIB_REGEX) }
23
+ end
24
+
25
+ %w[ core mocks expectations ].each do |lib|
26
+ it "matches all ruby files in rspec-#{lib}" do
27
+ files = ruby_files_in_lib(lib)
28
+
29
+ files.reject! do |file|
30
+ # We don't care about this file -- it only has a single require statement
31
+ # and won't show up in any backtraces.
32
+ file.end_with?('lib/rspec-expectations.rb') ||
33
+
34
+ # This has a single require and a single deprecation, and won't be
35
+ # in backtraces.
36
+ file.end_with?('lib/spec/mocks.rb') ||
37
+
38
+ # Autotest files are only loaded by the autotest executable
39
+ # and not by the rspec command and thus won't be in backtraces.
40
+ file.include?('autotest')
41
+ end
42
+
43
+ expect(unmatched_from files).to eq([])
44
+ end
45
+ end
46
+
47
+ it "does not match other ruby files" do
48
+ files = %w[
49
+ /path/to/lib/rspec/some-extension/foo.rb
50
+ /path/to/spec/rspec/core/some_spec.rb
51
+ ]
52
+
53
+ expect(unmatched_from files).to eq(files)
54
+ end
55
+ end
56
+ end
57
+ end
58
+
@@ -13,6 +13,7 @@ module RSpec::Core
13
13
  before { config.stub :run_hook }
14
14
 
15
15
  it "configures streams before command line options" do
16
+ config.stub(:reporter => double.as_null_object)
16
17
  config.stub :load_spec_files
17
18
 
18
19
  # this is necessary to ensure that color works correctly on windows
@@ -231,11 +231,11 @@ describe RSpec::Core::ConfigurationOptions, :isolated_directory => true, :isolat
231
231
 
232
232
  describe "--fail-fast" do
233
233
  it "defaults to false" do
234
- expect(parse_options[:fail_fast]).to be_false
234
+ expect(parse_options[:fail_fast]).to be_falsey
235
235
  end
236
236
 
237
237
  it "sets fail_fast on config" do
238
- expect(parse_options("--fail-fast")[:fail_fast]).to be_true
238
+ expect(parse_options("--fail-fast")[:fail_fast]).to be_truthy
239
239
  end
240
240
  end
241
241
 
@@ -354,11 +354,11 @@ describe RSpec::Core::ConfigurationOptions, :isolated_directory => true, :isolat
354
354
  File.open(File.expand_path("~/.rspec"), "w") {|f| f << "--color"}
355
355
  with_env_vars 'SPEC_OPTS' => "--debug --example 'foo bar'" do
356
356
  options = parse_options("--drb")
357
- expect(options[:color]).to be_true
357
+ expect(options[:color]).to be_truthy
358
358
  expect(options[:line_numbers]).to eq(["37"])
359
- expect(options[:debug]).to be_true
359
+ expect(options[:debug]).to be_truthy
360
360
  expect(options[:full_description]).to eq([/foo\ bar/])
361
- expect(options[:drb]).to be_true
361
+ expect(options[:drb]).to be_truthy
362
362
  expect(options[:formatters]).to eq([['global']])
363
363
  end
364
364
  end
@@ -404,7 +404,7 @@ describe RSpec::Core::ConfigurationOptions, :isolated_directory => true, :isolat
404
404
  File.open("./custom.opts", "w") {|f| f << "--color"}
405
405
  options = parse_options("-O", "./custom.opts")
406
406
  expect(options[:format]).to be_nil
407
- expect(options[:color]).to be_true
407
+ expect(options[:color]).to be_truthy
408
408
  end
409
409
 
410
410
  it "parses -e 'full spec description'" do
@@ -28,6 +28,81 @@ module RSpec::Core
28
28
  end
29
29
  end
30
30
 
31
+ shared_examples_for "output_stream" do |attribute|
32
+ define_method :attribute_value do
33
+ config.__send__(attribute)
34
+ end
35
+
36
+ update_line = __LINE__ + 2
37
+ define_method :update_attribute do |value|
38
+ config.__send__(:"#{attribute}=", value)
39
+ end
40
+
41
+ it 'defaults to standard output' do
42
+ expect(attribute_value).to eq $stdout
43
+ end
44
+
45
+ it 'is configurable' do
46
+ io = double 'output io'
47
+ update_attribute(io)
48
+ expect(attribute_value).to eq io
49
+ end
50
+
51
+ context 'when the reporter has already been initialized' do
52
+ before do
53
+ config.reporter
54
+ allow(config).to receive(:warn)
55
+ end
56
+
57
+ it 'prints a notice indicating the reconfigured output_stream will be ignored' do
58
+ update_attribute(StringIO.new)
59
+ expect(config).to have_received(:warn).with(/output_stream.*#{__FILE__}:#{update_line}/)
60
+ end
61
+
62
+ it 'does not change the value of `output_stream`' do
63
+ update_attribute(StringIO.new)
64
+ expect(attribute_value).to eq($stdout)
65
+ end
66
+
67
+ it 'does not print a warning if set to the value it already has' do
68
+ update_attribute(attribute_value)
69
+ expect(config).not_to have_received(:warn)
70
+ end
71
+ end
72
+ end
73
+
74
+ describe "#output_stream" do
75
+ include_examples "output_stream", :output_stream
76
+ end
77
+
78
+ describe "#output" do
79
+ include_examples "output_stream", :output
80
+
81
+ specify 'the reader is deprecated' do
82
+ expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /output/)
83
+ config.output
84
+ end
85
+
86
+ specify 'the writer is deprecated' do
87
+ expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /output=/)
88
+ config.output = $stdout
89
+ end
90
+ end
91
+
92
+ describe "#out" do
93
+ include_examples "output_stream", :out
94
+
95
+ specify 'the reader is deprecated' do
96
+ expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /out/)
97
+ config.out
98
+ end
99
+
100
+ specify 'the writer is deprecated' do
101
+ expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /out=/)
102
+ config.out = $stdout
103
+ end
104
+ end
105
+
31
106
  describe "#setup_load_path_and_require" do
32
107
  include_context "isolate load path mutation"
33
108
 
@@ -94,12 +169,18 @@ module RSpec::Core
94
169
 
95
170
  describe "#treat_symbols_as_metadata_keys_with_true_values?" do
96
171
  it 'defaults to false' do
97
- expect(config.treat_symbols_as_metadata_keys_with_true_values?).to be_false
172
+ expect(config.treat_symbols_as_metadata_keys_with_true_values?).to be_falsey
173
+ end
174
+
175
+ it 'prints a deprecation warning when explicitly set to false since RSpec 3 will not support that' do
176
+ expect_deprecation_with_call_site(__FILE__, __LINE__ + 1)
177
+ config.treat_symbols_as_metadata_keys_with_true_values = false
178
+ expect(config.treat_symbols_as_metadata_keys_with_true_values?).to be false
98
179
  end
99
180
 
100
181
  it 'can be set to true' do
101
182
  config.treat_symbols_as_metadata_keys_with_true_values = true
102
- expect(config.treat_symbols_as_metadata_keys_with_true_values?).to be_true
183
+ expect(config.treat_symbols_as_metadata_keys_with_true_values?).to be_truthy
103
184
  end
104
185
  end
105
186
 
@@ -127,7 +208,7 @@ module RSpec::Core
127
208
  mod_config.custom_setting = true
128
209
  end
129
210
 
130
- expect(custom_config.custom_setting).to be_true
211
+ expect(custom_config.custom_setting).to be_truthy
131
212
  end
132
213
 
133
214
  it "raises if framework module doesn't support configuration" do
@@ -495,6 +576,22 @@ module RSpec::Core
495
576
  expect(config.files_to_run).to include("#{dir}/a_bar.rb")
496
577
  end
497
578
  end
579
+
580
+ context "after files have already been loaded" do
581
+ it 'will warn that it will have no effect' do
582
+ allow(Kernel).to receive(:warn)
583
+ config.load_spec_files
584
+ config.send(setter, "rspec/**/*.spec"); line = __LINE__
585
+ expect(Kernel).to have_received(:warn).with(/has no effect.*#{__FILE__}:#{line}/)
586
+ end
587
+
588
+ it 'will not warn if reset is called after load_spec_files' do
589
+ config.load_spec_files
590
+ config.reset
591
+ expect(Kernel).to_not receive(:warn)
592
+ config.send(setter, "rspec/**/*.spec")
593
+ end
594
+ end
498
595
  end
499
596
  end
500
597
 
@@ -639,12 +736,12 @@ module RSpec::Core
639
736
  describe "#run_all_when_everything_filtered?" do
640
737
 
641
738
  it "defaults to false" do
642
- expect(config.run_all_when_everything_filtered?).to be_false
739
+ expect(config.run_all_when_everything_filtered?).to be_falsey
643
740
  end
644
741
 
645
742
  it "can be queried with question method" do
646
743
  config.run_all_when_everything_filtered = true
647
- expect(config.run_all_when_everything_filtered?).to be_true
744
+ expect(config.run_all_when_everything_filtered?).to be_truthy
648
745
  end
649
746
  end
650
747
 
@@ -661,8 +758,8 @@ module RSpec::Core
661
758
  config.tty = true
662
759
  config.output_stream.stub :tty? => true
663
760
 
664
- expect(config.send(color_option)).to be_true
665
- expect(config.send(color_option, output)).to be_true
761
+ expect(config.send(color_option)).to be_truthy
762
+ expect(config.send(color_option, output)).to be_truthy
666
763
  end
667
764
  end
668
765
 
@@ -674,8 +771,8 @@ module RSpec::Core
674
771
  config.tty = true
675
772
  config.output_stream.stub :tty? => false
676
773
 
677
- expect(config.send(color_option)).to be_true
678
- expect(config.send(color_option, output)).to be_true
774
+ expect(config.send(color_option)).to be_truthy
775
+ expect(config.send(color_option, output)).to be_truthy
679
776
  end
680
777
  end
681
778
 
@@ -687,8 +784,8 @@ module RSpec::Core
687
784
  config.tty = false
688
785
  config.output_stream.stub :tty? => true
689
786
 
690
- expect(config.send(color_option)).to be_true
691
- expect(config.send(color_option, output)).to be_true
787
+ expect(config.send(color_option)).to be_truthy
788
+ expect(config.send(color_option, output)).to be_truthy
692
789
  end
693
790
  end
694
791
 
@@ -700,8 +797,8 @@ module RSpec::Core
700
797
  config.tty = false
701
798
  config.output_stream.stub :tty? => false
702
799
 
703
- expect(config.send(color_option)).to be_false
704
- expect(config.send(color_option, output)).to be_false
800
+ expect(config.send(color_option)).to be_falsey
801
+ expect(config.send(color_option, output)).to be_falsey
705
802
  end
706
803
  end
707
804
 
@@ -724,7 +821,7 @@ module RSpec::Core
724
821
  config.output_stream = StringIO.new
725
822
  config.output_stream.stub :tty? => true
726
823
  config.send "#{color_option}=", true
727
- expect(config.send(color_option)).to be_true
824
+ expect(config.send(color_option)).to be_truthy
728
825
  end
729
826
 
730
827
  it "leaves output stream intact" do
@@ -749,7 +846,7 @@ module RSpec::Core
749
846
  config.stub(:require) { raise LoadError }
750
847
  config.send "#{color_option}=", true
751
848
  config.color_enabled = true
752
- expect(config.send(color_option)).to be_false
849
+ expect(config.send(color_option)).to be_falsey
753
850
  end
754
851
  end
755
852
  end
@@ -761,7 +858,7 @@ module RSpec::Core
761
858
  config.output_stream.stub :tty? => true
762
859
  config.force :color => true
763
860
  config.color = false
764
- expect(config.color).to be_true
861
+ expect(config.color).to be_truthy
765
862
  end
766
863
  end
767
864
 
@@ -919,29 +1016,29 @@ module RSpec::Core
919
1016
 
920
1017
  describe "the default :if filter" do
921
1018
  it "does not exclude a spec with { :if => true } metadata" do
922
- expect(config.exclusion_filter[:if].call(true)).to be_false
1019
+ expect(config.exclusion_filter[:if].call(true)).to be_falsey
923
1020
  end
924
1021
 
925
1022
  it "excludes a spec with { :if => false } metadata" do
926
- expect(config.exclusion_filter[:if].call(false)).to be_true
1023
+ expect(config.exclusion_filter[:if].call(false)).to be_truthy
927
1024
  end
928
1025
 
929
1026
  it "excludes a spec with { :if => nil } metadata" do
930
- expect(config.exclusion_filter[:if].call(nil)).to be_true
1027
+ expect(config.exclusion_filter[:if].call(nil)).to be_truthy
931
1028
  end
932
1029
  end
933
1030
 
934
1031
  describe "the default :unless filter" do
935
1032
  it "excludes a spec with { :unless => true } metadata" do
936
- expect(config.exclusion_filter[:unless].call(true)).to be_true
1033
+ expect(config.exclusion_filter[:unless].call(true)).to be_truthy
937
1034
  end
938
1035
 
939
1036
  it "does not exclude a spec with { :unless => false } metadata" do
940
- expect(config.exclusion_filter[:unless].call(false)).to be_false
1037
+ expect(config.exclusion_filter[:unless].call(false)).to be_falsey
941
1038
  end
942
1039
 
943
1040
  it "does not exclude a spec with { :unless => nil } metadata" do
944
- expect(config.exclusion_filter[:unless].call(nil)).to be_false
1041
+ expect(config.exclusion_filter[:unless].call(nil)).to be_falsey
945
1042
  end
946
1043
  end
947
1044
  end
@@ -1021,7 +1118,7 @@ module RSpec::Core
1021
1118
  RSpec.stub(:deprecate)
1022
1119
  config = Configuration.new
1023
1120
  config.backtrace_clean_patterns = [/.*/]
1024
- expect(config.backtrace_cleaner.exclude? "this").to be_true
1121
+ expect(config.backtrace_cleaner.exclude? "this").to be_truthy
1025
1122
  end
1026
1123
  end
1027
1124
 
@@ -1048,33 +1145,33 @@ module RSpec::Core
1048
1145
  it "can be appended to" do
1049
1146
  config = Configuration.new
1050
1147
  config.backtrace_clean_patterns << /.*/
1051
- expect(config.backtrace_cleaner.exclude? "this").to be_true
1148
+ expect(config.backtrace_cleaner.exclude? "this").to be_truthy
1052
1149
  end
1053
1150
  end
1054
1151
 
1055
1152
  describe ".backtrace_cleaner#exclude? defaults" do
1056
1153
  it "returns true for rspec files" do
1057
- expect(config.backtrace_cleaner.exclude?("lib/rspec/core.rb")).to be_true
1154
+ expect(config.backtrace_cleaner.exclude?("lib/rspec/core.rb")).to be_truthy
1058
1155
  end
1059
1156
 
1060
1157
  it "returns true for spec_helper" do
1061
- expect(config.backtrace_cleaner.exclude?("spec/spec_helper.rb")).to be_true
1158
+ expect(config.backtrace_cleaner.exclude?("spec/spec_helper.rb")).to be_truthy
1062
1159
  end
1063
1160
 
1064
1161
  it "returns true for java files (for JRuby)" do
1065
- expect(config.backtrace_cleaner.exclude?("org/jruby/RubyArray.java:2336")).to be_true
1162
+ expect(config.backtrace_cleaner.exclude?("org/jruby/RubyArray.java:2336")).to be_truthy
1066
1163
  end
1067
1164
 
1068
1165
  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
1166
+ expect(config.backtrace_cleaner.exclude?('ruby-1.8.7-p334/gems/mygem-2.3.0/lib/mygem.rb')).to be_truthy
1070
1167
  end
1071
1168
 
1072
1169
  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
1170
+ expect(config.backtrace_cleaner.exclude?('code/my-gems-plugin/lib/plugin.rb')).to be_falsey
1074
1171
  end
1075
1172
 
1076
1173
  it "returns false for something in the current working directory" do
1077
- expect(config.backtrace_cleaner.exclude?("#{Dir.getwd}/arbitrary")).to be_false
1174
+ expect(config.backtrace_cleaner.exclude?("#{Dir.getwd}/arbitrary")).to be_falsey
1078
1175
  end
1079
1176
  end
1080
1177
 
@@ -1088,6 +1185,8 @@ module RSpec::Core
1088
1185
  end
1089
1186
  config.stub(:require)
1090
1187
  Object.const_set("Debugger", debugger)
1188
+
1189
+ allow_deprecation
1091
1190
  end
1092
1191
 
1093
1192
  after do
@@ -1106,32 +1205,43 @@ module RSpec::Core
1106
1205
  debugger.should_receive(:start)
1107
1206
  config.debug = true
1108
1207
  end
1208
+
1209
+ it "warns that this feature is deprecated" do
1210
+ expect_deprecation_with_call_site(__FILE__, __LINE__ + 1)
1211
+ config.debug = true
1212
+ end
1109
1213
  end
1110
1214
 
1111
1215
  describe "#debug=false" do
1216
+ before { allow_deprecation }
1217
+
1112
1218
  it "does not require 'ruby-debug'" do
1113
1219
  config.should_not_receive(:require).with('ruby-debug')
1114
1220
  config.debug = false
1115
1221
  end
1222
+
1223
+ it "warns that this feature is deprecated" do
1224
+ expect_deprecation_with_call_site(__FILE__, __LINE__ + 1)
1225
+ config.debug = false
1226
+ end
1116
1227
  end
1117
1228
 
1118
1229
  describe "#debug?" do
1230
+ before { allow_deprecation }
1231
+
1119
1232
  it 'returns true if the debugger has been loaded' do
1120
1233
  stub_const("Debugger", Object.new)
1121
- expect(config.debug?).to be_true
1234
+ expect(config.debug?).to be_truthy
1122
1235
  end
1123
1236
 
1124
1237
  it 'returns false if the debugger has not been loaded' do
1125
1238
  hide_const("Debugger")
1126
- expect(config.debug?).to be_false
1239
+ expect(config.debug?).to be_falsey
1127
1240
  end
1128
- end
1129
1241
 
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)
1242
+ it "warns that this feature is deprecated" do
1243
+ expect_deprecation_with_call_site(__FILE__, __LINE__ + 1)
1244
+ config.debug?
1135
1245
  end
1136
1246
  end
1137
1247
 
@@ -1181,7 +1291,7 @@ module RSpec::Core
1181
1291
  end
1182
1292
 
1183
1293
  it "adds a predicate" do
1184
- expect(config.custom_option?).to be_false
1294
+ expect(config.custom_option?).to be_falsey
1185
1295
  end
1186
1296
 
1187
1297
  it "can be overridden" do
@@ -1200,7 +1310,7 @@ module RSpec::Core
1200
1310
  end
1201
1311
 
1202
1312
  it "returns true for the predicate" do
1203
- expect(config.custom_option?).to be_true
1313
+ expect(config.custom_option?).to be_truthy
1204
1314
  end
1205
1315
 
1206
1316
  it "can be overridden with a truthy value" do
@@ -1245,7 +1355,7 @@ module RSpec::Core
1245
1355
 
1246
1356
  it "delegates the predicate to the other option" do
1247
1357
  config.custom_option = true
1248
- expect(config.another_custom_option?).to be_true
1358
+ expect(config.another_custom_option?).to be_truthy
1249
1359
  end
1250
1360
  end
1251
1361
  end
@@ -1361,12 +1471,18 @@ module RSpec::Core
1361
1471
  end
1362
1472
 
1363
1473
  describe "#force" do
1364
- it "forces order" do
1474
+ it "forces order (when given default)" do
1365
1475
  config.force :order => "default"
1366
1476
  config.order = "rand"
1367
1477
  expect(config.order).to eq("default")
1368
1478
  end
1369
1479
 
1480
+ it "forces order (when given defined)" do
1481
+ config.force :order => "defined"
1482
+ config.order = "rand"
1483
+ expect(config.order).to eq("defined")
1484
+ end
1485
+
1370
1486
  it "forces order and seed with :order => 'rand:37'" do
1371
1487
  config.force :order => "rand:37"
1372
1488
  config.order = "default"
@@ -1376,7 +1492,7 @@ module RSpec::Core
1376
1492
 
1377
1493
  it "forces order and seed with :seed => '37'" do
1378
1494
  config.force :seed => "37"
1379
- config.order = "default"
1495
+ config.order = "defined"
1380
1496
  expect(config.seed).to eq(37)
1381
1497
  expect(config.order).to eq("rand")
1382
1498
  end
@@ -1392,11 +1508,11 @@ module RSpec::Core
1392
1508
  it "forces 'false' value" do
1393
1509
  config.add_setting :custom_option
1394
1510
  config.custom_option = true
1395
- expect(config.custom_option?).to be_true
1511
+ expect(config.custom_option?).to be_truthy
1396
1512
  config.force :custom_option => false
1397
- expect(config.custom_option?).to be_false
1513
+ expect(config.custom_option?).to be_falsey
1398
1514
  config.custom_option = true
1399
- expect(config.custom_option?).to be_false
1515
+ expect(config.custom_option?).to be_falsey
1400
1516
  end
1401
1517
  end
1402
1518
 
@@ -1412,7 +1528,7 @@ module RSpec::Core
1412
1528
  before { config.order = :random }
1413
1529
 
1414
1530
  it 'returns true' do
1415
- expect(config.randomize?).to be_true
1531
+ expect(config.randomize?).to be_truthy
1416
1532
  end
1417
1533
  end
1418
1534
 
@@ -1420,9 +1536,14 @@ module RSpec::Core
1420
1536
  before { config.order = nil }
1421
1537
 
1422
1538
  it 'returns false' do
1423
- expect(config.randomize?).to be_false
1539
+ expect(config.randomize?).to be_falsey
1424
1540
  end
1425
1541
  end
1542
+
1543
+ it 'is deprecated' do
1544
+ expect_warn_deprecation_with_call_site(__FILE__, __LINE__ + 1, /randomize\?/)
1545
+ config.randomize?
1546
+ end
1426
1547
  end
1427
1548
 
1428
1549
  describe '#order=' do
@@ -1445,10 +1566,10 @@ module RSpec::Core
1445
1566
  end
1446
1567
  end
1447
1568
 
1448
- context 'given "default"' do
1569
+ shared_examples_for "defined order" do |order|
1449
1570
  before do
1450
1571
  config.order = 'rand:123'
1451
- config.order = 'default'
1572
+ config.order = order
1452
1573
  end
1453
1574
 
1454
1575
  it "sets the order to nil" do
@@ -1466,10 +1587,26 @@ module RSpec::Core
1466
1587
  expect(list.ordered).to eq([1, 2, 3, 4])
1467
1588
  end
1468
1589
  end
1590
+
1591
+ context "given 'default'" do
1592
+ include_examples "defined order", 'default'
1593
+
1594
+ it 'prints a deprecation notice' do
1595
+ expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /default/)
1596
+ config.order = 'default'
1597
+ end
1598
+ end
1599
+
1600
+ context "given 'defined'" do
1601
+ include_examples "defined order", 'defined'
1602
+ end
1469
1603
  end
1470
1604
 
1471
1605
  describe "#order_examples" do
1472
- before { RSpec.stub(:configuration => config) }
1606
+ before do
1607
+ allow_deprecation
1608
+ RSpec.stub(:configuration => config)
1609
+ end
1473
1610
 
1474
1611
  it 'sets a block that determines the ordering of a collection extended with Extensions::Ordered::Examples' do
1475
1612
  examples = [1, 2, 3, 4]
@@ -1482,6 +1619,11 @@ module RSpec::Core
1482
1619
  config.order_examples { |examples| examples.reverse }
1483
1620
  expect(config.order).to eq("custom")
1484
1621
  end
1622
+
1623
+ it 'prints a deprecation warning' do
1624
+ expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /RSpec::Configuration#order_examples/)
1625
+ config.order_examples { }
1626
+ end
1485
1627
  end
1486
1628
 
1487
1629
  describe "#example_ordering_block" do
@@ -1491,7 +1633,10 @@ module RSpec::Core
1491
1633
  end
1492
1634
 
1493
1635
  describe "#order_groups" do
1494
- before { RSpec.stub(:configuration => config) }
1636
+ before do
1637
+ allow_deprecation
1638
+ RSpec.stub(:configuration => config)
1639
+ end
1495
1640
 
1496
1641
  it 'sets a block that determines the ordering of a collection extended with Extensions::Ordered::ExampleGroups' do
1497
1642
  groups = [1, 2, 3, 4]
@@ -1504,6 +1649,11 @@ module RSpec::Core
1504
1649
  config.order_groups { |groups| groups.reverse }
1505
1650
  expect(config.order).to eq("custom")
1506
1651
  end
1652
+
1653
+ it 'prints a deprecation warning' do
1654
+ expect_deprecation_with_call_site(__FILE__, __LINE__ + 1, /RSpec::Configuration#order_groups/)
1655
+ config.order_groups { }
1656
+ end
1507
1657
  end
1508
1658
 
1509
1659
  describe "#group_ordering_block" do
@@ -1530,6 +1680,41 @@ module RSpec::Core
1530
1680
  end
1531
1681
  end
1532
1682
 
1683
+ describe "#register_ordering(:global)" do
1684
+ let(:examples) { [1, 2, 3, 4].extend Extensions::Ordered::Examples }
1685
+ let(:groups) { [1, 2, 3, 4].extend Extensions::Ordered::ExampleGroups }
1686
+
1687
+ before do
1688
+ RSpec.stub(:configuration => config)
1689
+ config.register_ordering(:global) { |list| list.reverse }
1690
+ end
1691
+
1692
+ it 'sets a block that determines the ordering of a collection extended with Extensions::Ordered::Examples' do
1693
+ expect(examples.ordered).to eq([4, 3, 2, 1])
1694
+ end
1695
+
1696
+ it 'sets a block that determines the ordering of a collection extended with Extensions::Ordered::ExampleGroups' do
1697
+ expect(groups.ordered).to eq([4, 3, 2, 1])
1698
+ end
1699
+
1700
+ it 'sets #order to "custom"' do
1701
+ expect(config.order).to eq("custom")
1702
+ end
1703
+
1704
+ it 'raises an ArgumentError if given a symbol other than `:global`' do
1705
+ expect {
1706
+ config.register_ordering(:custom) { }
1707
+ }.to raise_error(ArgumentError, /:global/)
1708
+ end
1709
+ end
1710
+
1711
+ describe "#order" do
1712
+ it 'is deprecated' do
1713
+ expect_warn_deprecation_with_call_site(__FILE__, __LINE__ + 1, /order/)
1714
+ config.order
1715
+ end
1716
+ end
1717
+
1533
1718
  describe '#warnings' do
1534
1719
  around do |example|
1535
1720
  @_original_setting = $VERBOSE
@@ -1557,5 +1742,53 @@ module RSpec::Core
1557
1742
  end
1558
1743
  end
1559
1744
 
1745
+ describe "#raise_errors_for_deprecations!" do
1746
+ it 'causes deprecations to raise errors rather than printing to the deprecation stream' do
1747
+ config.deprecation_stream = stream = StringIO.new
1748
+ config.raise_errors_for_deprecations!
1749
+
1750
+ expect {
1751
+ config.reporter.deprecation(:deprecated => "foo", :call_site => "foo.rb:1")
1752
+ }.to raise_error(RSpec::Core::DeprecationError, /foo is deprecated/)
1753
+
1754
+ expect(stream.string).to eq("")
1755
+ end
1756
+ end
1757
+
1758
+ describe "#expose_current_running_example_as" do
1759
+ before { stub_const(Configuration::ExposeCurrentExample.name, Module.new) }
1760
+
1761
+ it 'exposes the current example via the named method' do
1762
+ RSpec.configuration.expose_current_running_example_as :the_example
1763
+ RSpec.configuration.expose_current_running_example_as :another_example_helper
1764
+
1765
+ value_1 = value_2 = nil
1766
+
1767
+ ExampleGroup.describe "Group" do
1768
+ it "works" do
1769
+ value_1 = the_example
1770
+ value_2 = another_example_helper
1771
+ end
1772
+ end.run
1773
+
1774
+ expect(value_1).to be_an(RSpec::Core::Example)
1775
+ expect(value_1.description).to eq("works")
1776
+ expect(value_2).to be(value_1)
1777
+ end
1778
+
1779
+ [:example, :running_example].each do |name|
1780
+ it "silences the deprecation warning for ##{name} when configured to expose via that name" do
1781
+ RSpec.configuration.expose_current_running_example_as name
1782
+ allow(RSpec).to receive(:deprecate)
1783
+
1784
+ ExampleGroup.describe "Group" do
1785
+ specify { __send__(name) }
1786
+ end.run
1787
+
1788
+ expect(RSpec).to_not have_received(:deprecate)
1789
+ end
1790
+ end
1791
+ end
1792
+
1560
1793
  end
1561
1794
  end