rspec-core 2.99.2 → 3.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (165) hide show
  1. checksums.yaml +14 -6
  2. checksums.yaml.gz.sig +2 -0
  3. data.tar.gz.sig +0 -0
  4. data/Changelog.md +103 -191
  5. data/License.txt +1 -0
  6. data/README.md +4 -25
  7. data/features/Upgrade.md +2 -14
  8. data/features/command_line/dry_run.feature +29 -0
  9. data/features/command_line/example_name_option.feature +1 -1
  10. data/features/command_line/fail_fast.feature +26 -0
  11. data/features/command_line/format_option.feature +3 -3
  12. data/features/command_line/line_number_option.feature +16 -11
  13. data/features/command_line/order.feature +2 -3
  14. data/features/command_line/pattern_option.feature +3 -3
  15. data/features/command_line/randomization.feature +63 -0
  16. data/features/command_line/require_option.feature +2 -2
  17. data/features/command_line/ruby.feature +1 -1
  18. data/features/configuration/alias_example_to.feature +13 -22
  19. data/features/configuration/{backtrace_clean_patterns.feature → backtrace_exclusion_patterns.feature} +17 -14
  20. data/features/configuration/custom_settings.feature +11 -11
  21. data/features/configuration/overriding_global_ordering.feature +93 -0
  22. data/features/configuration/profile.feature +13 -13
  23. data/features/configuration/read_options_from_file.feature +7 -7
  24. data/features/example_groups/basic_structure.feature +1 -1
  25. data/features/example_groups/shared_context.feature +8 -8
  26. data/features/example_groups/shared_examples.feature +6 -14
  27. data/features/expectation_framework_integration/configure_expectation_framework.feature +27 -122
  28. data/features/filtering/exclusion_filters.feature +2 -5
  29. data/features/filtering/inclusion_filters.feature +1 -5
  30. data/features/formatters/json_formatter.feature +2 -2
  31. data/features/formatters/text_formatter.feature +4 -4
  32. data/features/helper_methods/arbitrary_methods.feature +2 -2
  33. data/features/helper_methods/let.feature +5 -5
  34. data/features/helper_methods/modules.feature +5 -8
  35. data/features/hooks/around_hooks.feature +2 -2
  36. data/features/hooks/before_and_after_hooks.feature +14 -14
  37. data/features/hooks/filtering.feature +12 -14
  38. data/features/metadata/described_class.feature +1 -1
  39. data/features/metadata/user_defined.feature +16 -29
  40. data/features/mock_framework_integration/use_flexmock.feature +1 -1
  41. data/features/mock_framework_integration/use_mocha.feature +1 -1
  42. data/features/mock_framework_integration/use_rr.feature +1 -1
  43. data/features/mock_framework_integration/use_rspec.feature +5 -5
  44. data/features/pending/pending_examples.feature +5 -5
  45. data/features/spec_files/arbitrary_file_suffix.feature +1 -1
  46. data/features/step_definitions/additional_cli_steps.rb +3 -3
  47. data/features/subject/explicit_subject.feature +8 -8
  48. data/features/subject/implicit_receiver.feature +29 -0
  49. data/features/subject/implicit_subject.feature +4 -4
  50. data/features/support/env.rb +10 -3
  51. data/features/support/require_expect_syntax_in_aruba_specs.rb +16 -0
  52. data/lib/rspec/core.rb +11 -48
  53. data/lib/rspec/core/backport_random.rb +302 -0
  54. data/lib/rspec/core/backtrace_formatter.rb +65 -0
  55. data/lib/rspec/core/command_line.rb +7 -18
  56. data/lib/rspec/core/configuration.rb +202 -507
  57. data/lib/rspec/core/configuration_options.rb +17 -30
  58. data/lib/rspec/core/example.rb +29 -39
  59. data/lib/rspec/core/example_group.rb +166 -259
  60. data/lib/rspec/core/filter_manager.rb +30 -47
  61. data/lib/rspec/core/flat_map.rb +17 -0
  62. data/lib/rspec/core/formatters.rb +0 -138
  63. data/lib/rspec/core/formatters/base_formatter.rb +46 -1
  64. data/lib/rspec/core/formatters/base_text_formatter.rb +38 -61
  65. data/lib/rspec/core/formatters/deprecation_formatter.rb +21 -52
  66. data/lib/rspec/core/formatters/helpers.rb +0 -28
  67. data/lib/rspec/core/formatters/html_formatter.rb +1 -1
  68. data/lib/rspec/core/formatters/json_formatter.rb +38 -9
  69. data/lib/rspec/core/formatters/snippet_extractor.rb +14 -5
  70. data/lib/rspec/core/hooks.rb +55 -39
  71. data/lib/rspec/core/memoized_helpers.rb +17 -167
  72. data/lib/rspec/core/metadata.rb +16 -64
  73. data/lib/rspec/core/option_parser.rb +30 -39
  74. data/lib/rspec/core/ordering.rb +154 -0
  75. data/lib/rspec/core/pending.rb +12 -69
  76. data/lib/rspec/core/project_initializer.rb +12 -10
  77. data/lib/rspec/core/rake_task.rb +5 -108
  78. data/lib/rspec/core/reporter.rb +15 -18
  79. data/lib/rspec/core/runner.rb +16 -30
  80. data/lib/rspec/core/shared_context.rb +3 -5
  81. data/lib/rspec/core/shared_example_group.rb +3 -51
  82. data/lib/rspec/core/shared_example_group/collection.rb +1 -19
  83. data/lib/rspec/core/version.rb +1 -1
  84. data/lib/rspec/core/warnings.rb +22 -0
  85. data/lib/rspec/core/world.rb +12 -8
  86. data/spec/command_line/order_spec.rb +20 -23
  87. data/spec/rspec/core/backtrace_formatter_spec.rb +216 -0
  88. data/spec/rspec/core/command_line_spec.rb +32 -48
  89. data/spec/rspec/core/configuration_options_spec.rb +19 -50
  90. data/spec/rspec/core/configuration_spec.rb +142 -713
  91. data/spec/rspec/core/drb_command_line_spec.rb +2 -0
  92. data/spec/rspec/core/dsl_spec.rb +0 -1
  93. data/spec/rspec/core/example_group_spec.rb +192 -223
  94. data/spec/rspec/core/example_spec.rb +40 -16
  95. data/spec/rspec/core/filter_manager_spec.rb +2 -2
  96. data/spec/rspec/core/formatters/base_formatter_spec.rb +0 -41
  97. data/spec/rspec/core/formatters/base_text_formatter_spec.rb +5 -123
  98. data/spec/rspec/core/formatters/deprecation_formatter_spec.rb +2 -87
  99. data/spec/rspec/core/formatters/documentation_formatter_spec.rb +2 -3
  100. data/spec/rspec/core/formatters/{text_mate_formatted.html → html_formatted-1.8.7-jruby.html} +44 -25
  101. data/spec/rspec/core/formatters/html_formatted-1.8.7-rbx.html +477 -0
  102. data/spec/rspec/core/formatters/{html_formatted.html → html_formatted-1.8.7.html} +42 -25
  103. data/spec/rspec/core/formatters/html_formatted-1.9.2.html +425 -0
  104. data/spec/rspec/core/formatters/html_formatted-1.9.3-jruby.html +416 -0
  105. data/spec/rspec/core/formatters/html_formatted-1.9.3-rbx.html +477 -0
  106. data/spec/rspec/core/formatters/html_formatted-1.9.3.html +419 -0
  107. data/spec/rspec/core/formatters/html_formatted-2.0.0.html +425 -0
  108. data/spec/rspec/core/formatters/html_formatter_spec.rb +21 -46
  109. data/spec/rspec/core/formatters/json_formatter_spec.rb +97 -8
  110. data/spec/rspec/core/hooks_filtering_spec.rb +5 -5
  111. data/spec/rspec/core/hooks_spec.rb +61 -47
  112. data/spec/rspec/core/memoized_helpers_spec.rb +20 -322
  113. data/spec/rspec/core/metadata_spec.rb +1 -24
  114. data/spec/rspec/core/option_parser_spec.rb +20 -62
  115. data/spec/rspec/core/ordering_spec.rb +102 -0
  116. data/spec/rspec/core/pending_example_spec.rb +0 -40
  117. data/spec/rspec/core/project_initializer_spec.rb +1 -25
  118. data/spec/rspec/core/rake_task_spec.rb +5 -72
  119. data/spec/rspec/core/random_spec.rb +47 -0
  120. data/spec/rspec/core/reporter_spec.rb +23 -48
  121. data/spec/rspec/core/runner_spec.rb +31 -39
  122. data/spec/rspec/core/shared_context_spec.rb +3 -15
  123. data/spec/rspec/core/shared_example_group/collection_spec.rb +4 -17
  124. data/spec/rspec/core/shared_example_group_spec.rb +12 -45
  125. data/spec/rspec/core/{deprecation_spec.rb → warnings_spec.rb} +3 -1
  126. data/spec/rspec/core_spec.rb +4 -21
  127. data/spec/spec_helper.rb +41 -5
  128. data/spec/support/helper_methods.rb +0 -29
  129. data/spec/support/sandboxed_mock_space.rb +0 -16
  130. data/spec/support/shared_example_groups.rb +7 -36
  131. data/spec/support/stderr_splitter.rb +36 -0
  132. metadata +163 -157
  133. metadata.gz.sig +1 -0
  134. data/exe/autospec +0 -13
  135. data/features/Autotest.md +0 -38
  136. data/features/configuration/treat_symbols_as_metadata_keys_with_true_values.feature +0 -52
  137. data/features/subject/attribute_of_subject.feature +0 -124
  138. data/features/subject/one_liner_syntax.feature +0 -71
  139. data/lib/autotest/discover.rb +0 -10
  140. data/lib/autotest/rspec2.rb +0 -77
  141. data/lib/rspec/core/backtrace_cleaner.rb +0 -46
  142. data/lib/rspec/core/backward_compatibility.rb +0 -55
  143. data/lib/rspec/core/caller_filter.rb +0 -60
  144. data/lib/rspec/core/deprecated_mutable_array_proxy.rb +0 -32
  145. data/lib/rspec/core/deprecation.rb +0 -26
  146. data/lib/rspec/core/extensions/instance_eval_with_args.rb +0 -44
  147. data/lib/rspec/core/extensions/kernel.rb +0 -9
  148. data/lib/rspec/core/extensions/module_eval_with_args.rb +0 -38
  149. data/lib/rspec/core/extensions/ordered.rb +0 -27
  150. data/lib/rspec/core/formatters/console_codes.rb +0 -42
  151. data/lib/rspec/core/formatters/text_mate_formatter.rb +0 -34
  152. data/lib/rspec/core/metadata_hash_builder.rb +0 -97
  153. data/lib/rspec/core/minitest_assertions_adapter.rb +0 -28
  154. data/lib/rspec/core/test_unit_assertions_adapter.rb +0 -30
  155. data/spec/autotest/discover_spec.rb +0 -49
  156. data/spec/autotest/failed_results_re_spec.rb +0 -45
  157. data/spec/autotest/rspec_spec.rb +0 -133
  158. data/spec/rspec/core/backtrace_cleaner_spec.rb +0 -68
  159. data/spec/rspec/core/caller_filter_spec.rb +0 -58
  160. data/spec/rspec/core/deprecations_spec.rb +0 -59
  161. data/spec/rspec/core/formatters/console_codes_spec.rb +0 -50
  162. data/spec/rspec/core/formatters/text_mate_formatter_spec.rb +0 -107
  163. data/spec/rspec/core/kernel_extensions_spec.rb +0 -9
  164. data/spec/rspec/core/pending_spec.rb +0 -27
  165. data/spec/support/silence_dsl_deprecations.rb +0 -32
@@ -350,6 +350,45 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
350
350
  expect(actual.__id__).to eq(exception.__id__)
351
351
  end
352
352
  end
353
+
354
+ context "with --dry-run" do
355
+ before { RSpec.configuration.dry_run = true }
356
+
357
+ it "does not execute any examples or hooks" do
358
+ executed = []
359
+
360
+ RSpec.configure do |c|
361
+ c.before(:each) { executed << :before_each_config }
362
+ c.before(:all) { executed << :before_all_config }
363
+ c.after(:each) { executed << :after_each_config }
364
+ c.after(:all) { executed << :after_all_config }
365
+ c.around(:each) { |ex| executed << :around_each_config; ex.run }
366
+ end
367
+
368
+ group = RSpec::Core::ExampleGroup.describe do
369
+ before(:all) { executed << :before_all }
370
+ before(:each) { executed << :before_each }
371
+ after(:all) { executed << :after_all }
372
+ after(:each) { executed << :after_each }
373
+ around(:each) { |ex| executed << :around_each; ex.run }
374
+
375
+ example { executed << :example }
376
+
377
+ context "nested" do
378
+ before(:all) { executed << :nested_before_all }
379
+ before(:each) { executed << :nested_before_each }
380
+ after(:all) { executed << :nested_after_all }
381
+ after(:each) { executed << :nested_after_each }
382
+ around(:each) { |ex| executed << :nested_around_each; ex.run }
383
+
384
+ example { executed << :nested_example }
385
+ end
386
+ end
387
+
388
+ group.run
389
+ expect(executed).to eq([])
390
+ end
391
+ end
353
392
  end
354
393
 
355
394
  describe "#pending" do
@@ -462,7 +501,7 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
462
501
  context { example { values << rand } }
463
502
  end.run
464
503
 
465
- expect(values.uniq).to have(2).values
504
+ expect(values.uniq.count).to eq(2)
466
505
  end
467
506
 
468
507
  describe "optional block argument" do
@@ -472,21 +511,6 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
472
511
  end
473
512
  end
474
513
 
475
- %w[example running_example].each do |accessor|
476
- describe accessor do
477
- before { allow_deprecation }
478
-
479
- it "is deprecated" do
480
- expect_warn_deprecation_with_call_site(__FILE__, __LINE__ + 1, /#{accessor}/)
481
- send(accessor)
482
- end
483
-
484
- it "returns the current running example" do |ex|
485
- expect(send(accessor)).to eq ex
486
- end
487
- end
488
- end
489
-
490
514
  describe "setting the current example" do
491
515
  it "sets RSpec.current_example to the example that is currently running" do
492
516
  group = RSpec::Core::ExampleGroup.describe("an example group")
@@ -165,7 +165,7 @@ module RSpec::Core
165
165
  describe "#inclusions#description" do
166
166
  it 'cleans up the description' do
167
167
  project_dir = File.expand_path('.')
168
- expect(lambda { }.inspect).to include(project_dir) unless defined?(JRUBY_VERSION) && JRUBY_VERSION =~ /\A1\.7/
168
+ expect(lambda { }.inspect).to include(project_dir)
169
169
  expect(lambda { }.inspect).to include(' (lambda)') if RUBY_VERSION > '1.9'
170
170
  expect(lambda { }.inspect).to include('0x')
171
171
 
@@ -181,7 +181,7 @@ module RSpec::Core
181
181
  describe "#exclusions#description" do
182
182
  it 'cleans up the description' do
183
183
  project_dir = File.expand_path('.')
184
- expect(lambda { }.inspect).to include(project_dir) unless defined?(JRUBY_VERSION) && JRUBY_VERSION =~ /\A1\.7/
184
+ expect(lambda { }.inspect).to include(project_dir)
185
185
  expect(lambda { }.inspect).to include(' (lambda)') if RUBY_VERSION > '1.9'
186
186
  expect(lambda { }.inspect).to include('0x')
187
187
 
@@ -6,26 +6,6 @@ describe RSpec::Core::Formatters::BaseFormatter do
6
6
  let(:output) { StringIO.new }
7
7
  let(:formatter) { RSpec::Core::Formatters::BaseFormatter.new(output) }
8
8
 
9
- describe "backtrace_line" do
10
- it "trims current working directory" do
11
- expect(formatter.__send__(:backtrace_line, File.expand_path(__FILE__))).to eq("./spec/rspec/core/formatters/base_formatter_spec.rb")
12
- end
13
-
14
- it "leaves the original line intact" do
15
- original_line = File.expand_path(__FILE__)
16
- formatter.__send__(:backtrace_line, original_line)
17
- expect(original_line).to eq(File.expand_path(__FILE__))
18
- end
19
-
20
- it "deals gracefully with a security error" do
21
- safely do
22
- formatter.__send__(:backtrace_line, __FILE__)
23
- # on some rubies, this doesn't raise a SecurityError; this test just
24
- # assures that if it *does* raise an error, the error is caught inside
25
- end
26
- end
27
- end
28
-
29
9
  describe "read_failed_line" do
30
10
  it "deals gracefully with a heterogeneous language stack trace" do
31
11
  exception = double(:Exception, :backtrace => [
@@ -84,25 +64,4 @@ describe RSpec::Core::Formatters::BaseFormatter do
84
64
 
85
65
  end
86
66
  end
87
-
88
- describe "#format_backtrace" do
89
- let(:rspec_expectations_dir) { "/path/to/rspec-expectations/lib" }
90
- let(:rspec_core_dir) { "/path/to/rspec-core/lib" }
91
- let(:backtrace) do
92
- [
93
- "#{rspec_expectations_dir}/rspec/matchers/operator_matcher.rb:51:in `eval_match'",
94
- "#{rspec_expectations_dir}/rspec/matchers/operator_matcher.rb:29:in `=='",
95
- "./my_spec.rb:5",
96
- "#{rspec_core_dir}/rspec/core/example.rb:52:in `run'",
97
- "#{rspec_core_dir}/rspec/core/runner.rb:37:in `run'",
98
- RSpec::Core::Runner::AT_EXIT_HOOK_BACKTRACE_LINE,
99
- "./my_spec.rb:3"
100
- ]
101
- end
102
-
103
- it "removes lines from rspec and lines that come before the invocation of the at_exit autorun hook" do
104
- expect(formatter.format_backtrace(backtrace, double.as_null_object)).to eq(["./my_spec.rb:5"])
105
- end
106
- end
107
-
108
67
  end
@@ -5,16 +5,6 @@ describe RSpec::Core::Formatters::BaseTextFormatter do
5
5
  let(:output) { StringIO.new }
6
6
  let(:formatter) { RSpec::Core::Formatters::BaseTextFormatter.new(output) }
7
7
 
8
- context "when closing the formatter", :isolated_directory => true do
9
- it 'does not close an already closed output stream' do
10
- output = File.new("./output_to_close", "w")
11
- formatter = described_class.new(output)
12
- output.close
13
-
14
- expect { formatter.close }.not_to raise_error
15
- end
16
- end
17
-
18
8
  describe "#summary_line" do
19
9
  it "with 0s outputs pluralized (excluding pending)" do
20
10
  expect(formatter.summary_line(0,0,0)).to eq("0 examples, 0 failures")
@@ -155,50 +145,6 @@ describe RSpec::Core::Formatters::BaseTextFormatter do
155
145
  end
156
146
  end
157
147
  end
158
-
159
- context 'for #share_as' do
160
- before { allow(RSpec).to receive(:deprecate) }
161
-
162
- it 'outputs the name and location' do
163
-
164
- group.share_as :FooBar do
165
- it("example name") { expect("this").to eq("that") }
166
- end
167
-
168
- line = __LINE__.next
169
- group.send(:include, FooBar)
170
-
171
- run_all_and_dump_failures
172
-
173
- expect(output.string).to include(
174
- 'Shared Example Group: "FooBar" called from ' +
175
- "./spec/rspec/core/formatters/base_text_formatter_spec.rb:#{line}"
176
- )
177
- end
178
-
179
- context 'that contains nested example groups' do
180
- it 'outputs the name and location' do
181
-
182
- group.share_as :NestedFoo do
183
- describe 'nested group' do
184
- describe 'hell' do
185
- it("example name") { expect("this").to eq("that") }
186
- end
187
- end
188
- end
189
-
190
- line = __LINE__.next
191
- group.send(:include, NestedFoo)
192
-
193
- run_all_and_dump_failures
194
-
195
- expect(output.string).to include(
196
- 'Shared Example Group: "NestedFoo" called from ' +
197
- "./spec/rspec/core/formatters/base_text_formatter_spec.rb:#{line}"
198
- )
199
- end
200
- end
201
- end
202
148
  end
203
149
 
204
150
  describe "#dump_pending" do
@@ -212,7 +158,7 @@ describe RSpec::Core::Formatters::BaseTextFormatter do
212
158
  end
213
159
 
214
160
  context "with show_failures_in_pending_blocks setting enabled" do
215
- before { RSpec.configuration.instance_variable_set(:@show_failures_in_pending_blocks, true) }
161
+ before { RSpec.configuration.stub(:show_failures_in_pending_blocks?) { true } }
216
162
 
217
163
  it "preserves formatting" do
218
164
  group.example("example name") { pending { expect("this").to eq("that") } }
@@ -294,50 +240,6 @@ describe RSpec::Core::Formatters::BaseTextFormatter do
294
240
  end
295
241
  end
296
242
  end
297
-
298
- context 'for #share_as' do
299
- before { allow(RSpec).to receive(:deprecate) }
300
-
301
- it 'outputs the name and location' do
302
-
303
- group.share_as :FooBar2 do
304
- it("example name") { pending { expect("this").to eq("that") } }
305
- end
306
-
307
- line = __LINE__.next
308
- group.send(:include, FooBar2)
309
-
310
- run_all_and_dump_pending
311
-
312
- expect(output.string).to include(
313
- 'Shared Example Group: "FooBar2" called from ' +
314
- "./spec/rspec/core/formatters/base_text_formatter_spec.rb:#{line}"
315
- )
316
- end
317
-
318
- context 'that contains nested example groups' do
319
- it 'outputs the name and location' do
320
-
321
- group.share_as :NestedFoo2 do
322
- describe 'nested group' do
323
- describe 'hell' do
324
- it("example name") { pending { expect("this").to eq("that") } }
325
- end
326
- end
327
- end
328
-
329
- line = __LINE__.next
330
- group.send(:include, NestedFoo2)
331
-
332
- run_all_and_dump_pending
333
-
334
- expect(output.string).to include(
335
- 'Shared Example Group: "NestedFoo2" called from ' +
336
- "./spec/rspec/core/formatters/base_text_formatter_spec.rb:#{line}"
337
- )
338
- end
339
- end
340
- end
341
243
  end
342
244
 
343
245
  context "with show_failures_in_pending_blocks setting disabled" do
@@ -456,7 +358,7 @@ describe RSpec::Core::Formatters::BaseTextFormatter do
456
358
  describe "custom_colors" do
457
359
  it "uses the custom success color" do
458
360
  RSpec.configure do |config|
459
- config.color = true
361
+ config.color_enabled = true
460
362
  config.tty = true
461
363
  config.success_color = :cyan
462
364
  end
@@ -466,10 +368,6 @@ describe RSpec::Core::Formatters::BaseTextFormatter do
466
368
  end
467
369
 
468
370
  describe "#colorize" do
469
- before do
470
- allow(RSpec.configuration).to receive(:color_enabled?) { true }
471
- end
472
-
473
371
  it "accepts a VT100 integer code and formats the text with it" do
474
372
  expect(formatter.colorize('abc', 32)).to eq "\e[32mabc\e[0m"
475
373
  end
@@ -483,25 +381,8 @@ describe RSpec::Core::Formatters::BaseTextFormatter do
483
381
  end
484
382
  end
485
383
 
486
- describe "#const_missing name" do
487
-
488
- it "warns of deprecation for VT100_COLORS" do
489
- expect_deprecation_with_call_site __FILE__, __LINE__ + 1
490
- expect(described_class::VT100_COLORS).to eq RSpec::Core::Formatters::ConsoleCodes::VT100_CODES
491
- end
492
-
493
- it "warns of deprecation for VT100_COLOR_CODES" do
494
- expect_deprecation_with_call_site __FILE__, __LINE__ + 1
495
- expect(described_class::VT100_COLOR_CODES).to eq RSpec::Core::Formatters::ConsoleCodes::VT100_CODES.to_set
496
- end
497
-
498
- it "behaves normally for other constants" do
499
- expect { described_class::NoSuchConst }.to raise_error(NameError)
500
- end
501
- end
502
-
503
- RSpec::Core::Formatters::ConsoleCodes::VT100_CODES.each do |name, number|
504
- next if name == :black || name == :bold
384
+ described_class::VT100_COLORS.each do |name, number|
385
+ next if name == :black
505
386
 
506
387
  describe "##{name}" do
507
388
  before do
@@ -521,4 +402,5 @@ describe RSpec::Core::Formatters::BaseTextFormatter do
521
402
  end
522
403
  end
523
404
  end
405
+
524
406
  end
@@ -4,28 +4,6 @@ require 'tempfile'
4
4
 
5
5
  module RSpec::Core::Formatters
6
6
  describe DeprecationFormatter do
7
- let(:deprecation_stream) { StringIO.new }
8
- let(:summary_stream) { StringIO.new }
9
- let(:formatter) { DeprecationFormatter.new(deprecation_stream, summary_stream) }
10
-
11
- def with_start_defined_on_kernel
12
- return yield if ::Kernel.method_defined?(:start)
13
-
14
- begin
15
- ::Kernel.module_eval { def start(*); raise "boom"; end }
16
- yield
17
- ensure
18
- ::Kernel.module_eval { undef start }
19
- end
20
- end
21
-
22
- it 'does not blow up when `Kernel` defines `start`' do
23
- with_start_defined_on_kernel do
24
- reporter = ::RSpec::Core::Reporter.new(formatter)
25
- reporter.start(3)
26
- end
27
- end
28
-
29
7
  describe "#deprecation" do
30
8
  let(:formatter) { DeprecationFormatter.new(deprecation_stream, summary_stream) }
31
9
  let(:summary_stream) { StringIO.new }
@@ -39,23 +17,6 @@ module RSpec::Core::Formatters
39
17
  expect(deprecation_stream.read).to eq "this message\n"
40
18
  end
41
19
 
42
- it "surrounds multiline messages in fenceposts" do
43
- multiline_message = <<-EOS.gsub(/^\s+\|/, '')
44
- |line one
45
- |line two
46
- EOS
47
- formatter.deprecation(:message => multiline_message)
48
- deprecation_stream.rewind
49
-
50
- expected = <<-EOS.gsub(/^\s+\|/, '')
51
- |--------------------------------------------------------------------------------
52
- |line one
53
- |line two
54
- |--------------------------------------------------------------------------------
55
- EOS
56
- expect(deprecation_stream.read).to eq expected
57
- end
58
-
59
20
  it "includes the method" do
60
21
  formatter.deprecation(:deprecated => "i_am_deprecated")
61
22
  deprecation_stream.rewind
@@ -125,27 +86,6 @@ module RSpec::Core::Formatters
125
86
  end
126
87
  end
127
88
 
128
- context "with an Error deprecation_stream" do
129
- let(:deprecation_stream) { DeprecationFormatter::RaiseErrorStream.new }
130
-
131
- it 'prints a summary of the number of deprecations found' do
132
- expect { formatter.deprecation(:deprecated => 'foo') }.to raise_error(RSpec::Core::DeprecationError)
133
-
134
- formatter.deprecation_summary
135
-
136
- expect(summary_stream.string).to eq("\n1 deprecation found.\n")
137
- end
138
-
139
- it 'pluralizes the count when it is greater than 1' do
140
- expect { formatter.deprecation(:deprecated => 'foo') }.to raise_error(RSpec::Core::DeprecationError)
141
- expect { formatter.deprecation(:deprecated => 'bar') }.to raise_error(RSpec::Core::DeprecationError)
142
-
143
- formatter.deprecation_summary
144
-
145
- expect(summary_stream.string).to eq("\n2 deprecations found.\n")
146
- end
147
- end
148
-
149
89
  context "with an IO deprecation_stream" do
150
90
  let(:deprecation_stream) { StringIO.new }
151
91
 
@@ -179,38 +119,13 @@ module RSpec::Core::Formatters
179
119
  |i_am_deprecated is deprecated. Called from foo.rb:1.
180
120
  |i_am_deprecated is deprecated. Called from foo.rb:2.
181
121
  |i_am_deprecated is deprecated. Called from foo.rb:3.
182
- |Too many uses of deprecated 'i_am_deprecated'. #{DeprecationFormatter::DEPRECATION_STREAM_NOTICE}
183
- |
184
- |#{DeprecationFormatter::RAISE_ERROR_CONFIG_NOTICE}
185
- EOS
186
- expect(deprecation_stream.string).to eq expected.chomp
187
- end
188
-
189
- it "limits deprecations warnings by optional type" do
190
- 5.times {|i|
191
- formatter.deprecation(
192
- :deprecated => "i_am_deprecated #{i}",
193
- :call_site => "foo.rb:#{i + 1}",
194
- :type => 'i_am_deprecated'
195
- )
196
- }
197
- formatter.deprecation_summary
198
-
199
- expected = <<-EOS.gsub(/^\s+\|/, '')
200
- |
201
- |Deprecation Warnings:
202
- |
203
- |i_am_deprecated 0 is deprecated. Called from foo.rb:1.
204
- |i_am_deprecated 1 is deprecated. Called from foo.rb:2.
205
- |i_am_deprecated 2 is deprecated. Called from foo.rb:3.
206
- |Too many uses of deprecated 'i_am_deprecated'. #{DeprecationFormatter::DEPRECATION_STREAM_NOTICE}
122
+ |Too many uses of deprecated 'i_am_deprecated'. Set config.deprecation_stream to a File for full output.
207
123
  |
208
124
  |#{DeprecationFormatter::RAISE_ERROR_CONFIG_NOTICE}
209
125
  EOS
210
126
  expect(deprecation_stream.string).to eq expected.chomp
211
127
  end
212
128
 
213
-
214
129
  it "limits :message deprecation warnings with different callsites after 3 calls" do
215
130
  5.times do |n|
216
131
  message = "This is a long string with some callsite info: /path/#{n}/to/some/file.rb:2#{n}3. And some more stuff can come after."
@@ -224,7 +139,7 @@ module RSpec::Core::Formatters
224
139
  |This is a long string with some callsite info: /path/0/to/some/file.rb:203. And some more stuff can come after.
225
140
  |This is a long string with some callsite info: /path/1/to/some/file.rb:213. And some more stuff can come after.
226
141
  |This is a long string with some callsite info: /path/2/to/some/file.rb:223. And some more stuff can come after.
227
- |Too many similar deprecation messages reported, disregarding further reports. #{DeprecationFormatter::DEPRECATION_STREAM_NOTICE}
142
+ |Too many similar deprecation messages reported, disregarding further reports. Set config.deprecation_stream to a File for full output.
228
143
  |
229
144
  |#{DeprecationFormatter::RAISE_ERROR_CONFIG_NOTICE}
230
145
  EOS