rspec-core 3.0.0.beta1 → 3.0.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. data.tar.gz.sig +0 -0
  2. data/Changelog.md +137 -0
  3. data/README.md +2 -2
  4. data/exe/rspec +2 -23
  5. data/features/README.md +1 -5
  6. data/features/command_line/README.md +7 -10
  7. data/features/command_line/exit_status.feature +1 -1
  8. data/features/command_line/format_option.feature +1 -1
  9. data/features/command_line/init.feature +40 -1
  10. data/features/command_line/line_number_option.feature +2 -2
  11. data/features/command_line/ruby.feature +5 -4
  12. data/features/configuration/enable_global_dsl.feature +54 -0
  13. data/features/example_groups/aliasing.feature +48 -0
  14. data/features/example_groups/basic_structure.feature +1 -1
  15. data/features/expectation_framework_integration/configure_expectation_framework.feature +1 -1
  16. data/features/filtering/if_and_unless.feature +0 -30
  17. data/features/formatters/custom_formatter.feature +32 -0
  18. data/features/formatters/regression_tests.feature +95 -0
  19. data/features/hooks/around_hooks.feature +1 -0
  20. data/features/hooks/before_and_after_hooks.feature +2 -2
  21. data/features/mock_framework_integration/use_flexmock.feature +11 -13
  22. data/features/mock_framework_integration/use_mocha.feature +11 -13
  23. data/features/mock_framework_integration/use_rr.feature +11 -13
  24. data/features/mock_framework_integration/use_rspec.feature +11 -13
  25. data/features/pending_and_skipped_examples/README.md +3 -0
  26. data/features/pending_and_skipped_examples/pending_examples.feature +118 -0
  27. data/features/pending_and_skipped_examples/skipped_examples.feature +106 -0
  28. data/features/step_definitions/additional_cli_steps.rb +34 -0
  29. data/features/subject/explicit_subject.feature +1 -1
  30. data/features/subject/one_liner_syntax.feature +71 -0
  31. data/lib/rspec/core.rb +6 -14
  32. data/lib/rspec/core/backtrace_formatter.rb +16 -4
  33. data/lib/rspec/core/command_line.rb +2 -3
  34. data/lib/rspec/core/configuration.rb +114 -125
  35. data/lib/rspec/core/configuration_options.rb +32 -18
  36. data/lib/rspec/core/dsl.rb +80 -18
  37. data/lib/rspec/core/example.rb +84 -33
  38. data/lib/rspec/core/example_group.rb +95 -43
  39. data/lib/rspec/core/filter_manager.rb +31 -40
  40. data/lib/rspec/core/formatters.rb +137 -0
  41. data/lib/rspec/core/formatters/base_formatter.rb +28 -41
  42. data/lib/rspec/core/formatters/base_text_formatter.rb +26 -37
  43. data/lib/rspec/core/formatters/deprecation_formatter.rb +48 -27
  44. data/lib/rspec/core/formatters/documentation_formatter.rb +27 -22
  45. data/lib/rspec/core/formatters/html_formatter.rb +48 -56
  46. data/lib/rspec/core/formatters/html_printer.rb +11 -18
  47. data/lib/rspec/core/formatters/json_formatter.rb +18 -22
  48. data/lib/rspec/core/formatters/legacy_formatter.rb +227 -0
  49. data/lib/rspec/core/formatters/progress_formatter.rb +7 -10
  50. data/lib/rspec/core/hooks.rb +250 -217
  51. data/lib/rspec/core/memoized_helpers.rb +43 -9
  52. data/lib/rspec/core/mocking_adapters/flexmock.rb +29 -0
  53. data/lib/rspec/core/{mocking/with_mocha.rb → mocking_adapters/mocha.rb} +19 -16
  54. data/lib/rspec/core/mocking_adapters/null.rb +12 -0
  55. data/lib/rspec/core/mocking_adapters/rr.rb +28 -0
  56. data/lib/rspec/core/mocking_adapters/rspec.rb +30 -0
  57. data/lib/rspec/core/notifications.rb +100 -0
  58. data/lib/rspec/core/option_parser.rb +11 -18
  59. data/lib/rspec/core/pending.rb +78 -47
  60. data/lib/rspec/core/project_initializer.rb +2 -49
  61. data/lib/rspec/core/project_initializer/dot_rspec +3 -0
  62. data/lib/rspec/core/project_initializer/spec_helper.rb +82 -0
  63. data/lib/rspec/core/rake_task.rb +5 -14
  64. data/lib/rspec/core/reporter.rb +24 -32
  65. data/lib/rspec/core/ruby_project.rb +1 -1
  66. data/lib/rspec/core/runner.rb +14 -4
  67. data/lib/rspec/core/shared_example_group.rb +40 -13
  68. data/lib/rspec/core/version.rb +1 -1
  69. data/spec/command_line/order_spec.rb +15 -15
  70. data/spec/rspec/core/backtrace_formatter_spec.rb +15 -1
  71. data/spec/rspec/core/command_line_spec.rb +18 -17
  72. data/spec/rspec/core/configuration_options_spec.rb +57 -34
  73. data/spec/rspec/core/configuration_spec.rb +162 -184
  74. data/spec/rspec/core/drb_command_line_spec.rb +5 -7
  75. data/spec/rspec/core/drb_options_spec.rb +2 -2
  76. data/spec/rspec/core/dsl_spec.rb +79 -15
  77. data/spec/rspec/core/example_group_spec.rb +253 -39
  78. data/spec/rspec/core/example_spec.rb +149 -33
  79. data/spec/rspec/core/filter_manager_spec.rb +9 -26
  80. data/spec/rspec/core/formatters/base_formatter_spec.rb +2 -5
  81. data/spec/rspec/core/formatters/base_text_formatter_spec.rb +42 -145
  82. data/spec/rspec/core/formatters/deprecation_formatter_spec.rb +64 -34
  83. data/spec/rspec/core/formatters/documentation_formatter_spec.rb +15 -28
  84. data/spec/rspec/core/formatters/helpers_spec.rb +2 -2
  85. data/spec/rspec/core/formatters/{html_formatted-1.8.7.html → html_formatted-2.1.0.html} +22 -44
  86. data/spec/rspec/core/formatters/{html_formatted-1.8.7-jruby.html → html_formatted.html} +30 -49
  87. data/spec/rspec/core/formatters/html_formatter_spec.rb +35 -19
  88. data/spec/rspec/core/formatters/json_formatter_spec.rb +42 -40
  89. data/spec/rspec/core/formatters/legacy_formatter_spec.rb +137 -0
  90. data/spec/rspec/core/formatters/progress_formatter_spec.rb +38 -25
  91. data/spec/rspec/core/formatters/snippet_extractor_spec.rb +1 -1
  92. data/spec/rspec/core/formatters_spec.rb +120 -0
  93. data/spec/rspec/core/hooks_filtering_spec.rb +1 -1
  94. data/spec/rspec/core/hooks_spec.rb +13 -2
  95. data/spec/rspec/core/memoized_helpers_spec.rb +17 -8
  96. data/spec/rspec/core/metadata_spec.rb +3 -3
  97. data/spec/rspec/core/option_parser_spec.rb +53 -46
  98. data/spec/rspec/core/ordering_spec.rb +4 -4
  99. data/spec/rspec/core/pending_example_spec.rb +23 -126
  100. data/spec/rspec/core/pending_spec.rb +8 -0
  101. data/spec/rspec/core/project_initializer_spec.rb +8 -41
  102. data/spec/rspec/core/rake_task_spec.rb +15 -4
  103. data/spec/rspec/core/random_spec.rb +1 -1
  104. data/spec/rspec/core/reporter_spec.rb +50 -37
  105. data/spec/rspec/core/resources/formatter_specs.rb +9 -11
  106. data/spec/rspec/core/rspec_matchers_spec.rb +1 -1
  107. data/spec/rspec/core/ruby_project_spec.rb +3 -3
  108. data/spec/rspec/core/runner_spec.rb +65 -23
  109. data/spec/rspec/core/shared_context_spec.rb +4 -4
  110. data/spec/rspec/core/shared_example_group/collection_spec.rb +1 -1
  111. data/spec/rspec/core/shared_example_group_spec.rb +20 -11
  112. data/spec/rspec/core/warnings_spec.rb +1 -1
  113. data/spec/rspec/core/world_spec.rb +10 -10
  114. data/spec/rspec/core_spec.rb +2 -2
  115. data/spec/spec_helper.rb +12 -24
  116. data/spec/support/config_options_helper.rb +1 -3
  117. data/spec/support/formatter_support.rb +83 -0
  118. data/spec/support/isolate_load_path_mutation.rb +1 -2
  119. data/spec/support/isolated_directory.rb +1 -1
  120. data/spec/support/isolated_home_directory.rb +1 -1
  121. data/spec/support/legacy_formatter_using_sub_classing_example.rb +87 -0
  122. data/spec/support/matchers.rb +20 -0
  123. data/spec/support/mathn_integration_support.rb +2 -2
  124. data/spec/support/old_style_formatter_example.rb +69 -0
  125. data/spec/support/shared_example_groups.rb +1 -1
  126. data/spec/support/spec_files.rb +3 -3
  127. metadata +192 -69
  128. metadata.gz.sig +3 -1
  129. checksums.yaml +0 -15
  130. checksums.yaml.gz.sig +0 -2
  131. data/features/configuration/show_failures_in_pending_blocks.feature +0 -61
  132. data/features/pending/pending_examples.feature +0 -229
  133. data/features/subject/implicit_receiver.feature +0 -29
  134. data/lib/rspec/core/mocking/with_absolutely_nothing.rb +0 -11
  135. data/lib/rspec/core/mocking/with_flexmock.rb +0 -27
  136. data/lib/rspec/core/mocking/with_rr.rb +0 -27
  137. data/lib/rspec/core/mocking/with_rspec.rb +0 -27
  138. data/spec/rspec/core/formatters/html_formatted-1.8.7-rbx.html +0 -477
  139. data/spec/rspec/core/formatters/html_formatted-1.9.2.html +0 -425
  140. data/spec/rspec/core/formatters/html_formatted-1.9.3-jruby.html +0 -416
  141. data/spec/rspec/core/formatters/html_formatted-1.9.3-rbx.html +0 -477
  142. data/spec/rspec/core/formatters/html_formatted-1.9.3.html +0 -419
  143. data/spec/rspec/core/formatters/html_formatted-2.0.0.html +0 -425
  144. data/spec/support/in_sub_process.rb +0 -37
  145. data/spec/support/sandboxed_mock_space.rb +0 -100
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
  require 'pp'
3
3
  require 'stringio'
4
4
 
5
- describe RSpec::Core::Example, :parent_metadata => 'sample' do
5
+ RSpec.describe RSpec::Core::Example, :parent_metadata => 'sample' do
6
6
  let(:example_group) do
7
7
  RSpec::Core::ExampleGroup.describe('group description')
8
8
  end
@@ -62,7 +62,7 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
62
62
 
63
63
  describe "when there is no explicit description" do
64
64
  def expect_with(*frameworks)
65
- RSpec.configuration.stub(:expecting_with_rspec?).and_return(frameworks.include?(:rspec))
65
+ allow(RSpec.configuration).to receive(:expecting_with_rspec?).and_return(frameworks.include?(:rspec))
66
66
 
67
67
  if frameworks.include?(:stdlib)
68
68
  example_group.class_eval do
@@ -110,6 +110,20 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
110
110
  example_group.run
111
111
  expect(example.description).to match(/example at #{relative_path(__FILE__)}:#{__LINE__ - 3}/)
112
112
  end
113
+
114
+ context "if the example is pending" do
115
+ it "still uses the matcher-generated description if a matcher ran" do
116
+ example = example_group.example { pending; expect(4).to eq(5) }
117
+ example_group.run
118
+ expect(example.description).to eq("should eq 5")
119
+ end
120
+
121
+ it "uses the file and line number of the example if no matcher ran" do
122
+ example = example_group.example { pending; fail }
123
+ example_group.run
124
+ expect(example.description).to match(/example at #{relative_path(__FILE__)}:#{__LINE__ - 2}/)
125
+ end
126
+ end
113
127
  end
114
128
 
115
129
  context "when `expect_with :rspec, :stdlib` is configured" do
@@ -139,7 +153,7 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
139
153
  before(:each) { expect_with :stdlib }
140
154
 
141
155
  it "does not attempt to get the generated description from RSpec::Matchers" do
142
- RSpec::Matchers.should_not_receive(:generated_description)
156
+ expect(RSpec::Matchers).not_to receive(:generated_description)
143
157
  example_group.example { assert 5 == 5 }
144
158
  example_group.run
145
159
  end
@@ -296,7 +310,7 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
296
310
  # We can't use should_receive(:message).with(/.../) here,
297
311
  # because if that fails, it would fail within our example-under-test,
298
312
  # and since there's already two errors, it would just be reported again.
299
- RSpec.configuration.reporter.stub(:message) { |msg| reported_msg = msg }
313
+ allow(RSpec.configuration.reporter).to receive(:message) { |msg| reported_msg = msg }
300
314
  group.run
301
315
  reported_msg
302
316
  end
@@ -325,7 +339,7 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
325
339
  group = RSpec::Core::ExampleGroup.describe do
326
340
  example do
327
341
  foo = double
328
- foo.should_receive(:bar)
342
+ expect(foo).to receive(:bar)
329
343
  raise "boom"
330
344
  end
331
345
  end
@@ -392,13 +406,19 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
392
406
  end
393
407
 
394
408
  describe "#pending" do
409
+ def expect_pending_result(example)
410
+ expect(example).to be_pending
411
+ expect(example.metadata[:execution_result][:status]).to eq("pending")
412
+ expect(example.metadata[:execution_result][:pending_message]).to be
413
+ end
414
+
395
415
  context "in the example" do
396
416
  it "sets the example to pending" do
397
417
  group = RSpec::Core::ExampleGroup.describe do
398
- example { pending }
418
+ example { pending; fail }
399
419
  end
400
420
  group.run
401
- expect(group.examples.first).to be_pending
421
+ expect_pending_result(group.examples.first)
402
422
  end
403
423
 
404
424
  it "allows post-example processing in around hooks (see https://github.com/rspec/rspec-core/issues/322)" do
@@ -414,65 +434,161 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
414
434
  expect(blah).to be(:success)
415
435
  end
416
436
 
417
- context "with a block" do
418
- it "sets the example to pending if block fails" do
419
- group = RSpec::Core::ExampleGroup.describe do
420
- example do
421
- pending { expect(1).to eq(2) }
422
- end
437
+ it 'sets the backtrace to the example definition so it can be located by the user' do
438
+ expected = [__FILE__, __LINE__ + 2].map(&:to_s)
439
+ group = RSpec::Core::ExampleGroup.describe do
440
+ example {
441
+ pending
442
+ }
443
+ end
444
+ group.run
445
+ # TODO: De-dup this logic in rspec-support
446
+ actual = group.examples.first.exception.backtrace.
447
+ find { |line| line !~ RSpec::CallerFilter::LIB_REGEX }.
448
+ split(':')[0..1]
449
+ expect(actual).to eq(expected)
450
+ end
451
+ end
452
+
453
+ context "in before(:each)" do
454
+ it "sets each example to pending" do
455
+ group = RSpec::Core::ExampleGroup.describe do
456
+ before(:each) { pending }
457
+ example { fail }
458
+ example { fail }
459
+ end
460
+ group.run
461
+ expect_pending_result(group.examples.first)
462
+ expect_pending_result(group.examples.last)
463
+ end
464
+
465
+ it 'sets example to pending when failure occurs in before(:each)' do
466
+ group = RSpec::Core::ExampleGroup.describe do
467
+ before(:each) { pending; fail }
468
+ example {}
469
+ end
470
+ group.run
471
+ expect_pending_result(group.examples.first)
472
+ end
473
+ end
474
+
475
+ context "in before(:all)" do
476
+ it "is forbidden" do
477
+ group = RSpec::Core::ExampleGroup.describe do
478
+ before(:all) { pending }
479
+ example { fail }
480
+ example { fail }
481
+ end
482
+ group.run
483
+ expect(group.examples.first.exception).to be
484
+ expect(group.examples.first.exception.message).to \
485
+ match(/may not be used outside of examples/)
486
+ end
487
+ end
488
+
489
+ context "in around(:each)" do
490
+ it "sets the example to pending" do
491
+ group = RSpec::Core::ExampleGroup.describe do
492
+ around(:each) { pending }
493
+ example { fail }
494
+ end
495
+ group.run
496
+ expect_pending_result(group.examples.first)
497
+ end
498
+
499
+ it 'sets example to pending when failure occurs in around(:each)' do
500
+ group = RSpec::Core::ExampleGroup.describe do
501
+ around(:each) { pending; fail }
502
+ example {}
503
+ end
504
+ group.run
505
+ expect_pending_result(group.examples.first)
506
+ end
507
+ end
508
+
509
+ context "in after(:each)" do
510
+ it "sets each example to pending" do
511
+ group = RSpec::Core::ExampleGroup.describe do
512
+ after(:each) { pending; fail }
513
+ example { }
514
+ example { }
515
+ end
516
+ group.run
517
+ expect_pending_result(group.examples.first)
518
+ expect_pending_result(group.examples.last)
519
+ end
520
+ end
521
+
522
+ end
523
+
524
+ describe "#skip" do
525
+ context "in the example" do
526
+ it "sets the example to skipped" do
527
+ group = RSpec::Core::ExampleGroup.describe do
528
+ example { skip }
529
+ end
530
+ group.run
531
+ expect(group.examples.first).to be_skipped
532
+ end
533
+
534
+ it "allows post-example processing in around hooks (see https://github.com/rspec/rspec-core/issues/322)" do
535
+ blah = nil
536
+ group = RSpec::Core::ExampleGroup.describe do
537
+ around do |example|
538
+ example.run
539
+ blah = :success
423
540
  end
424
- group.run
425
- expect(group.examples.first.metadata[:execution_result][:status]).to eq('pending')
426
- expect(group.examples.first.metadata[:execution_result][:pending_fixed]).to eq(false)
541
+ example { skip }
427
542
  end
543
+ group.run
544
+ expect(blah).to be(:success)
545
+ end
428
546
 
429
- it "fails if block is fixed, i.e. does not raise" do
547
+ context "with a message" do
548
+ it "sets the example to skipped with the provided message" do
430
549
  group = RSpec::Core::ExampleGroup.describe do
431
- example do
432
- pending {}
433
- end
550
+ example { skip "lorem ipsum" }
434
551
  end
435
552
  group.run
436
- expect(group.examples.first.metadata[:execution_result][:status]).to eq('failed')
437
- expect(group.examples.first.metadata[:execution_result][:pending_fixed]).to eq(true)
553
+ expect(group.examples.first).to be_skipped_with("lorem ipsum")
438
554
  end
439
555
  end
440
556
  end
441
557
 
442
558
  context "in before(:each)" do
443
- it "sets each example to pending" do
559
+ it "sets each example to skipped" do
444
560
  group = RSpec::Core::ExampleGroup.describe do
445
- before(:each) { pending }
561
+ before(:each) { skip }
446
562
  example {}
447
563
  example {}
448
564
  end
449
565
  group.run
450
- expect(group.examples.first).to be_pending
451
- expect(group.examples.last).to be_pending
566
+ expect(group.examples.first).to be_skipped
567
+ expect(group.examples.last).to be_skipped
452
568
  end
453
569
  end
454
570
 
455
571
  context "in before(:all)" do
456
572
  it "sets each example to pending" do
457
573
  group = RSpec::Core::ExampleGroup.describe do
458
- before(:all) { pending }
574
+ before(:all) { skip("not done"); fail }
459
575
  example {}
460
576
  example {}
461
577
  end
462
578
  group.run
463
- expect(group.examples.first).to be_pending
464
- expect(group.examples.last).to be_pending
579
+ expect(group.examples.first).to be_skipped_with("not done")
580
+ expect(group.examples.last).to be_skipped_with("not done")
465
581
  end
466
582
  end
467
583
 
468
584
  context "in around(:each)" do
469
- it "sets the example to pending" do
585
+ it "sets the example to skipped" do
470
586
  group = RSpec::Core::ExampleGroup.describe do
471
- around(:each) { pending }
587
+ around(:each) { skip }
472
588
  example {}
473
589
  end
474
590
  group.run
475
- expect(group.examples.first).to be_pending
591
+ expect(group.examples.first).to be_skipped
476
592
  end
477
593
  end
478
594
  end
@@ -483,7 +599,7 @@ describe RSpec::Core::Example, :parent_metadata => 'sample' do
483
599
  group = RSpec::Core::ExampleGroup.describe
484
600
  example = group.example
485
601
  example.__send__ :start, reporter
486
- Time.stub(:now => Time.utc(2012, 10, 1))
602
+ allow(Time).to receive_messages(:now => Time.utc(2012, 10, 1))
487
603
  example.__send__ :finish, reporter
488
604
  expect(example.metadata[:execution_result][:run_time]).to be < 0.2
489
605
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module RSpec::Core
4
- describe FilterManager do
4
+ RSpec.describe FilterManager do
5
5
  def opposite(name)
6
6
  name =~ /^in/ ? name.sub(/^(in)/,'ex') : name.sub(/^(ex)/,'in')
7
7
  end
@@ -43,6 +43,13 @@ module RSpec::Core
43
43
  expect(filter_manager.inclusions).to eq({filter => "value"})
44
44
  end
45
45
 
46
+ it "clears previous exclusion" do
47
+ filter_manager = FilterManager.new
48
+ filter_manager.include :foo => :bar
49
+ filter_manager.include filter => "value"
50
+ expect(filter_manager.exclusions).to be_empty
51
+ end
52
+
46
53
  it "does nothing when :#{filter} previously set" do
47
54
  filter_manager = FilterManager.new
48
55
  filter_manager.include filter => "a_value"
@@ -105,7 +112,7 @@ module RSpec::Core
105
112
  describe "#prune" do
106
113
  def filterable_object_with(args = {})
107
114
  object = double('a filterable object')
108
- object.stub(:any_apply?) { |f| Metadata.new(args).any_apply?(f) }
115
+ allow(object).to receive(:any_apply?) { |f| Metadata.new(args).any_apply?(f) }
109
116
  object
110
117
  end
111
118
 
@@ -204,30 +211,6 @@ module RSpec::Core
204
211
  expect(filter_manager.exclusions.description).to eq({ :foo => :bar }.inspect)
205
212
  end
206
213
 
207
- it 'deprecates an overridden :if filter' do
208
- expect(RSpec).to receive(:deprecate).with(/exclude\(:if/)
209
- filter_manager = FilterManager.new
210
- filter_manager.exclude :if => :custom_filter
211
- end
212
-
213
- it 'deprecates an :if filter overridden with low priority' do
214
- expect(RSpec).to receive(:deprecate).with(/exclude\(:if/)
215
- filter_manager = FilterManager.new
216
- filter_manager.exclude_with_low_priority :if => :custom_filter
217
- end
218
-
219
- it 'deprecates an overridden :unless filter' do
220
- expect(RSpec).to receive(:deprecate).with(/exclude\(:unless/)
221
- filter_manager = FilterManager.new
222
- filter_manager.exclude :unless => :custom_filter
223
- end
224
-
225
- it 'deprecates an :unless filter overridden with low priority' do
226
- expect(RSpec).to receive(:deprecate).with(/exclude\(:unless/)
227
- filter_manager = FilterManager.new
228
- filter_manager.exclude_with_low_priority :unless => :custom_filter
229
- end
230
-
231
214
  it 'includes an overriden :if filter' do
232
215
  allow(RSpec).to receive(:deprecate)
233
216
  filter_manager = FilterManager.new
@@ -1,10 +1,8 @@
1
1
  require 'spec_helper'
2
2
  require 'rspec/core/formatters/base_formatter'
3
3
 
4
- describe RSpec::Core::Formatters::BaseFormatter do
5
-
6
- let(:output) { StringIO.new }
7
- let(:formatter) { RSpec::Core::Formatters::BaseFormatter.new(output) }
4
+ RSpec.describe RSpec::Core::Formatters::BaseFormatter do
5
+ include FormatterSupport
8
6
 
9
7
  describe "read_failed_line" do
10
8
  it "deals gracefully with a heterogeneous language stack trace" do
@@ -54,7 +52,6 @@ describe RSpec::Core::Formatters::BaseFormatter do
54
52
  end
55
53
 
56
54
  it "doesn't hang when file exists" do
57
- pending("This issue still exists on JRuby, but should be resolved shortly: https://github.com/rspec/rspec-core/issues/295", :if => RUBY_PLATFORM == 'java')
58
55
  exception = double(:Exception, :backtrace => [ "#{__FILE__}:#{__LINE__}"])
59
56
 
60
57
  example = double(:Example, :file_path => __FILE__)
@@ -1,21 +1,23 @@
1
1
  require 'spec_helper'
2
2
  require 'rspec/core/formatters/base_text_formatter'
3
3
 
4
- describe RSpec::Core::Formatters::BaseTextFormatter do
5
- let(:output) { StringIO.new }
6
- let(:formatter) { RSpec::Core::Formatters::BaseTextFormatter.new(output) }
4
+ RSpec.describe RSpec::Core::Formatters::BaseTextFormatter do
5
+ include FormatterSupport
7
6
 
8
- describe "#summary_line" do
7
+ describe "#dump_summary" do
9
8
  it "with 0s outputs pluralized (excluding pending)" do
10
- expect(formatter.summary_line(0,0,0)).to eq("0 examples, 0 failures")
9
+ send_notification :dump_summary, summary_notification(0, 0, 0, 0)
10
+ expect(output.string).to match("0 examples, 0 failures")
11
11
  end
12
12
 
13
13
  it "with 1s outputs singular (including pending)" do
14
- expect(formatter.summary_line(1,1,1)).to eq("1 example, 1 failure, 1 pending")
14
+ send_notification :dump_summary, summary_notification(1, 1, 1, 1)
15
+ expect(output.string).to match("1 example, 1 failure, 1 pending")
15
16
  end
16
17
 
17
18
  it "with 2s outputs pluralized (including pending)" do
18
- expect(formatter.summary_line(2,2,2)).to eq("2 examples, 2 failures, 2 pending")
19
+ send_notification :dump_summary, summary_notification(2, 2, 2, 2)
20
+ expect(output.string).to match("2 examples, 2 failures, 2 pending")
19
21
  end
20
22
  end
21
23
 
@@ -25,7 +27,7 @@ describe RSpec::Core::Formatters::BaseTextFormatter do
25
27
  it("fails") { fail }
26
28
  end
27
29
  line = __LINE__ - 2
28
- group.run(formatter)
30
+ group.run(reporter)
29
31
  formatter.dump_commands_to_rerun_failed_examples
30
32
  expect(output.string).to include("rspec #{RSpec::Core::Metadata::relative_path("#{__FILE__}:#{line}")} # example group fails")
31
33
  end
@@ -34,11 +36,11 @@ describe RSpec::Core::Formatters::BaseTextFormatter do
34
36
  describe "#dump_failures" do
35
37
  let(:group) { RSpec::Core::ExampleGroup.describe("group name") }
36
38
 
37
- before { RSpec.configuration.stub(:color_enabled?) { false } }
39
+ before { allow(RSpec.configuration).to receive(:color_enabled?) { false } }
38
40
 
39
41
  def run_all_and_dump_failures
40
- group.run(formatter)
41
- formatter.dump_failures
42
+ group.run(reporter)
43
+ send_notification :dump_failures, null_notification
42
44
  end
43
45
 
44
46
  it "preserves formatting" do
@@ -53,7 +55,7 @@ describe RSpec::Core::Formatters::BaseTextFormatter do
53
55
  context "with an exception without a message" do
54
56
  it "does not throw NoMethodError" do
55
57
  exception_without_message = Exception.new()
56
- exception_without_message.stub(:message) { nil }
58
+ allow(exception_without_message).to receive(:message) { nil }
57
59
  group.example("example name") { raise exception_without_message }
58
60
  expect { run_all_and_dump_failures }.not_to raise_error
59
61
  end
@@ -68,7 +70,7 @@ describe RSpec::Core::Formatters::BaseTextFormatter do
68
70
  context "with an exception that has an exception instance as its message" do
69
71
  it "does not raise NoMethodError" do
70
72
  gonzo_exception = RuntimeError.new
71
- gonzo_exception.stub(:message) { gonzo_exception }
73
+ allow(gonzo_exception).to receive(:message) { gonzo_exception }
72
74
  group.example("example name") { raise gonzo_exception }
73
75
  expect { run_all_and_dump_failures }.not_to raise_error
74
76
  end
@@ -101,7 +103,7 @@ describe RSpec::Core::Formatters::BaseTextFormatter do
101
103
 
102
104
  context "with a failed message expectation (rspec-mocks)" do
103
105
  it "does not show the error class" do
104
- group.example("example name") { "this".should_receive("that") }
106
+ group.example("example name") { expect("this").to receive("that") }
105
107
  run_all_and_dump_failures
106
108
  expect(output.string).not_to match(/RSpec/m)
107
109
  end
@@ -147,126 +149,21 @@ describe RSpec::Core::Formatters::BaseTextFormatter do
147
149
  end
148
150
  end
149
151
 
150
- describe "#dump_pending" do
151
- let(:group) { RSpec::Core::ExampleGroup.describe("group name") }
152
-
153
- before { RSpec.configuration.stub(:color_enabled?) { false } }
154
-
155
- def run_all_and_dump_pending
156
- group.run(formatter)
157
- formatter.dump_pending
158
- end
159
-
160
- context "with show_failures_in_pending_blocks setting enabled" do
161
- before { RSpec.configuration.stub(:show_failures_in_pending_blocks?) { true } }
162
-
163
- it "preserves formatting" do
164
- group.example("example name") { pending { expect("this").to eq("that") } }
165
-
166
- run_all_and_dump_pending
167
-
168
- expect(output.string).to match(/group name example name/m)
169
- expect(output.string).to match(/(\s+)expected: \"that\"\n\1 got: \"this\"/m)
170
- end
171
-
172
- context "with an exception without a message" do
173
- it "does not throw NoMethodError" do
174
- exception_without_message = Exception.new()
175
- exception_without_message.stub(:message) { nil }
176
- group.example("example name") { pending { raise exception_without_message } }
177
- expect { run_all_and_dump_pending }.not_to raise_error
178
- end
179
- end
180
-
181
- context "with an exception class other than RSpec" do
182
- it "does not show the error class" do
183
- group.example("example name") { pending { raise NameError.new('foo') } }
184
- run_all_and_dump_pending
185
- expect(output.string).to match(/NameError/m)
186
- end
187
- end
188
-
189
- context "with a failed expectation (rspec-expectations)" do
190
- it "does not show the error class" do
191
- group.example("example name") { pending { expect("this").to eq("that") } }
192
- run_all_and_dump_pending
193
- expect(output.string).not_to match(/RSpec/m)
194
- end
195
- end
196
-
197
- context "with a failed message expectation (rspec-mocks)" do
198
- it "does not show the error class" do
199
- group.example("example name") { pending { "this".should_receive("that") } }
200
- run_all_and_dump_pending
201
- expect(output.string).not_to match(/RSpec/m)
202
- end
203
- end
204
-
205
- context 'for #share_examples_for' do
206
- it 'outputs the name and location' do
207
-
208
- group.share_examples_for 'foo bar' do
209
- it("example name") { pending { expect("this").to eq("that") } }
210
- end
211
-
212
- line = __LINE__.next
213
- group.it_should_behave_like('foo bar')
214
-
215
- run_all_and_dump_pending
216
-
217
- expect(output.string).to include(
218
- 'Shared Example Group: "foo bar" called from ' +
219
- "./spec/rspec/core/formatters/base_text_formatter_spec.rb:#{line}"
220
- )
221
- end
222
-
223
- context 'that contains nested example groups' do
224
- it 'outputs the name and location' do
225
- group.share_examples_for 'foo bar' do
226
- describe 'nested group' do
227
- it("example name") { pending { expect("this").to eq("that") } }
228
- end
229
- end
230
-
231
- line = __LINE__.next
232
- group.it_should_behave_like('foo bar')
233
-
234
- run_all_and_dump_pending
235
-
236
- expect(output.string).to include(
237
- 'Shared Example Group: "foo bar" called from ' +
238
- "./spec/rspec/core/formatters/base_text_formatter_spec.rb:#{line}"
239
- )
240
- end
241
- end
242
- end
243
- end
244
-
245
- context "with show_failures_in_pending_blocks setting disabled" do
246
- before { RSpec.configuration.stub(:show_failures_in_pending_blocks?) { false } }
247
-
248
- it "does not output the failure information" do
249
- group.example("example name") { pending { expect("this").to eq("that") } }
250
- run_all_and_dump_pending
251
- expect(output.string).not_to match(/(\s+)expected: \"that\"\n\1 got: \"this\"/m)
252
- end
253
- end
254
- end
255
-
256
- describe "#dump_profile_slowest_examples" do
152
+ describe "#dump_profile_slowest_examples", :slow do
257
153
  example_line_number = nil
258
154
 
259
155
  before do
260
156
  group = RSpec::Core::ExampleGroup.describe("group") do
261
- # Use a sleep so there is some measurable time, to ensure
262
- # the reported percent is 100%, not 0%.
263
- example("example") { sleep 0.001 }
264
- example_line_number = __LINE__ - 1
157
+ example("example") do |example|
158
+ # make it look slow without actually taking up precious time
159
+ example.clock = class_double(RSpec::Core::Time, :now => RSpec::Core::Time.now + 0.5)
160
+ end
161
+ example_line_number = __LINE__ - 4
265
162
  end
266
- group.run(double('reporter').as_null_object)
163
+ group.run(reporter)
267
164
 
268
- formatter.stub(:examples) { group.examples }
269
- RSpec.configuration.stub(:profile_examples) { 10 }
165
+ allow(formatter).to receive(:examples) { group.examples }
166
+ allow(RSpec.configuration).to receive(:profile_examples) { 10 }
270
167
  end
271
168
 
272
169
  it "names the example" do
@@ -292,23 +189,23 @@ describe RSpec::Core::Formatters::BaseTextFormatter do
292
189
  end
293
190
  end
294
191
 
295
- describe "#dump_profile_slowest_example_groups" do
296
- let(:group) do
192
+ describe "#dump_profile_slowest_example_groups", :slow do
193
+ let(:group) do
297
194
  RSpec::Core::ExampleGroup.describe("slow group") do
298
- # Use a sleep so there is some measurable time, to ensure
299
- # the reported percent is 100%, not 0%.
300
- example("example") { sleep 0.01 }
301
- end
195
+ example("example") do |example|
196
+ # make it look slow without actually taking up precious time
197
+ example.clock = class_double(RSpec::Core::Time, :now => RSpec::Core::Time.now + 0.5)
198
+ end
199
+ end
302
200
  end
303
- let(:rpt) { double('reporter').as_null_object }
304
201
 
305
202
  before do
306
- group.run(rpt)
307
- RSpec.configuration.stub(:profile_examples) { 10 }
203
+ group.run(reporter)
204
+ allow(RSpec.configuration).to receive(:profile_examples) { 10 }
308
205
  end
309
206
 
310
207
  context "with one example group" do
311
- before { formatter.stub(:examples) { group.examples } }
208
+ before { allow(formatter).to receive(:examples) { group.examples } }
312
209
 
313
210
  it "doesn't profile a single example group" do
314
211
  formatter.dump_profile_slowest_example_groups
@@ -319,12 +216,12 @@ describe RSpec::Core::Formatters::BaseTextFormatter do
319
216
  context "with multiple example groups" do
320
217
  before do
321
218
  group2 = RSpec::Core::ExampleGroup.describe("fast group") do
322
- example("example 1") { sleep 0.004 }
323
- example("example 2") { sleep 0.007 }
219
+ example("example 1") { }
220
+ example("example 2") { }
324
221
  end
325
- group2.run(rpt)
222
+ group2.run(reporter)
326
223
 
327
- formatter.stub(:examples) { group.examples + group2.examples }
224
+ allow(formatter).to receive(:examples) { group.examples + group2.examples }
328
225
  end
329
226
 
330
227
  it "prints the slowest example groups" do
@@ -345,9 +242,9 @@ describe RSpec::Core::Formatters::BaseTextFormatter do
345
242
 
346
243
  it "depends on parent_groups to get the top level example group" do
347
244
  ex = ""
348
- group.describe("group 2") do
245
+ group.describe("group 2") do
349
246
  describe "group 3" do
350
- ex = example("nested example 1")
247
+ ex = example("nested example 1")
351
248
  end
352
249
  end
353
250
 
@@ -362,7 +259,7 @@ describe RSpec::Core::Formatters::BaseTextFormatter do
362
259
  config.tty = true
363
260
  config.success_color = :cyan
364
261
  end
365
- formatter.dump_summary(0,1,0,0)
262
+ send_notification :dump_summary, summary_notification(0, 1, 0, 0)
366
263
  expect(output.string).to include("\e[36m")
367
264
  end
368
265
  end