rspec-core 3.13.5 → 4.0.0.beta1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/Changelog.md +56 -1
  4. data/LICENSE.md +2 -2
  5. data/README.md +33 -44
  6. data/lib/rspec/core/bisect/example_minimizer.rb +3 -3
  7. data/lib/rspec/core/bisect/fork_runner.rb +0 -6
  8. data/lib/rspec/core/bisect/shell_command.rb +2 -0
  9. data/lib/rspec/core/bisect/shell_runner.rb +2 -25
  10. data/lib/rspec/core/bisect/utilities.rb +3 -7
  11. data/lib/rspec/core/configuration.rb +128 -330
  12. data/lib/rspec/core/configuration_options.rb +4 -16
  13. data/lib/rspec/core/drb.rb +0 -5
  14. data/lib/rspec/core/dsl.rb +3 -48
  15. data/lib/rspec/core/example.rb +5 -41
  16. data/lib/rspec/core/example_group.rb +36 -75
  17. data/lib/rspec/core/filter_manager.rb +2 -11
  18. data/lib/rspec/core/formatters/deprecation_formatter.rb +4 -4
  19. data/lib/rspec/core/formatters/exception_presenter.rb +30 -60
  20. data/lib/rspec/core/formatters/helpers.rb +1 -1
  21. data/lib/rspec/core/formatters/html_printer.rb +8 -7
  22. data/lib/rspec/core/formatters/html_snippet_extractor.rb +0 -4
  23. data/lib/rspec/core/formatters/profile_formatter.rb +2 -2
  24. data/lib/rspec/core/formatters/snippet_extractor.rb +3 -1
  25. data/lib/rspec/core/formatters/syntax_highlighter.rb +2 -0
  26. data/lib/rspec/core/formatters.rb +4 -8
  27. data/lib/rspec/core/hooks.rb +24 -45
  28. data/lib/rspec/core/memoized_helpers.rb +30 -120
  29. data/lib/rspec/core/metadata.rb +8 -216
  30. data/lib/rspec/core/metadata_filter.rb +15 -69
  31. data/lib/rspec/core/minitest_assertions_adapter.rb +2 -2
  32. data/lib/rspec/core/mocking_adapters/mocha.rb +2 -31
  33. data/lib/rspec/core/notifications.rb +4 -16
  34. data/lib/rspec/core/option_parser.rb +6 -14
  35. data/lib/rspec/core/ordering.rb +5 -6
  36. data/lib/rspec/core/output_wrapper.rb +2 -2
  37. data/lib/rspec/core/pending.rb +1 -9
  38. data/lib/rspec/core/project_initializer/spec/spec_helper.rb +14 -31
  39. data/lib/rspec/core/rake_task.rb +6 -7
  40. data/lib/rspec/core/shared_example_group.rb +7 -82
  41. data/lib/rspec/core/shell_escape.rb +2 -0
  42. data/lib/rspec/core/test_unit_assertions_adapter.rb +4 -17
  43. data/lib/rspec/core/version.rb +1 -1
  44. data/lib/rspec/core/world.rb +8 -23
  45. data/lib/rspec/core.rb +1 -22
  46. data.tar.gz.sig +0 -0
  47. metadata +24 -25
  48. metadata.gz.sig +0 -0
  49. data/lib/rspec/core/flat_map.rb +0 -20
@@ -58,7 +58,7 @@ module RSpec
58
58
 
59
59
  UNFORCED_OPTIONS = Set.new([
60
60
  :requires, :profile, :drb, :libs, :files_or_directories_to_run,
61
- :full_description, :full_backtrace, :tty
61
+ :full_description, :full_backtrace
62
62
  ])
63
63
 
64
64
  UNPROCESSABLE_OPTIONS = Set.new([:formatters])
@@ -111,7 +111,7 @@ module RSpec
111
111
  ]
112
112
 
113
113
  def process_options_into(config)
114
- opts = options.reject { |k, _| UNPROCESSABLE_OPTIONS.include? k }
114
+ opts = options.except(*UNPROCESSABLE_OPTIONS)
115
115
 
116
116
  order(opts.keys).each do |key|
117
117
  force?(key) ? config.force(key => opts[key]) : config.__send__("#{key}=", opts[key])
@@ -174,18 +174,12 @@ module RSpec
174
174
  return [] unless path && File.exist?(path)
175
175
  config_string = options_file_as_erb_string(path)
176
176
  config_lines = config_string.split(/\n+/).reject { |s| s =~ /\A\s*#/ }
177
- FlatMap.flat_map(config_lines, &:shellsplit)
177
+ config_lines.flat_map(&:shellsplit)
178
178
  end
179
179
 
180
- # :nocov:
181
180
  def options_file_as_erb_string(path)
182
- if RUBY_VERSION >= '2.6'
183
- ERB.new(File.read(path), :trim_mode => '-').result(binding)
184
- else
185
- ERB.new(File.read(path), nil, '-').result(binding)
186
- end
181
+ ERB.new(File.read(path), :trim_mode => '-').result(binding)
187
182
  end
188
- # :nocov:
189
183
 
190
184
  def custom_options_file
191
185
  command_line_options[:custom_options_file]
@@ -228,12 +222,6 @@ module RSpec
228
222
 
229
223
  def resolve_xdg_config_home
230
224
  File.expand_path(ENV.fetch("XDG_CONFIG_HOME", "~/.config"))
231
- rescue ArgumentError
232
- # :nocov:
233
- # On Ruby 2.4, `File.expand("~")` works even if `ENV['HOME']` is not set.
234
- # But on earlier versions, it fails.
235
- nil
236
- # :nocov:
237
225
  end
238
226
  end
239
227
  end
@@ -40,12 +40,10 @@ module RSpec
40
40
 
41
41
  def options
42
42
  argv = []
43
- argv << "--color" if @submitted_options[:color]
44
43
  argv << "--force-color" if @submitted_options[:color_mode] == :on
45
44
  argv << "--no-color" if @submitted_options[:color_mode] == :off
46
45
  argv << "--profile" if @submitted_options[:profile_examples]
47
46
  argv << "--backtrace" if @submitted_options[:full_backtrace]
48
- argv << "--tty" if @submitted_options[:tty]
49
47
  argv << "--fail-fast" if @submitted_options[:fail_fast]
50
48
  argv << "--options" << @submitted_options[:custom_options_file] if @submitted_options[:custom_options_file]
51
49
  argv << "--order" << @submitted_options[:order] if @submitted_options[:order]
@@ -86,11 +84,8 @@ module RSpec
86
84
  end
87
85
  end
88
86
 
89
- CONDITIONAL_FILTERS = [:if, :unless]
90
-
91
87
  def add_filter(argv, name, hash)
92
88
  hash.each_pair do |k, v|
93
- next if CONDITIONAL_FILTERS.include?(k)
94
89
  tag = name == :inclusion ? k.to_s.dup : "~#{k}".dup
95
90
  tag << ":#{v}" if v.is_a?(String)
96
91
  argv << "--tag" << tag
@@ -1,9 +1,7 @@
1
1
  module RSpec
2
2
  module Core
3
3
  # DSL defines methods to group examples, most notably `describe`,
4
- # and exposes them as class methods of {RSpec}. They can also be
5
- # exposed globally (on `main` and instances of `Module`) through
6
- # the {Configuration} option `expose_dsl_globally`.
4
+ # and exposes them as class methods of {RSpec}.
7
5
  #
8
6
  # By default the methods `describe`, `context` and `example_group`
9
7
  # are exposed. These methods define a named context for one or
@@ -28,11 +26,6 @@ module RSpec
28
26
  @example_group_aliases ||= []
29
27
  end
30
28
 
31
- # @private
32
- def self.exposed_globally?
33
- @exposed_globally ||= false
34
- end
35
-
36
29
  # @private
37
30
  def self.expose_example_group_alias(name)
38
31
  return if example_group_aliases.include?(name)
@@ -44,55 +37,17 @@ module RSpec
44
37
  RSpec.world.record(group)
45
38
  group
46
39
  end
47
-
48
- expose_example_group_alias_globally(name) if exposed_globally?
49
40
  end
50
41
 
51
42
  class << self
52
43
  # @private
53
44
  attr_accessor :top_level
54
45
  end
55
-
56
- # Adds the describe method to Module and the top level binding.
57
- # @api private
58
- def self.expose_globally!
59
- return if exposed_globally?
60
-
61
- example_group_aliases.each do |method_name|
62
- expose_example_group_alias_globally(method_name)
63
- end
64
-
65
- @exposed_globally = true
66
- end
67
-
68
- # Removes the describe method from Module and the top level binding.
69
- # @api private
70
- def self.remove_globally!
71
- return unless exposed_globally?
72
-
73
- example_group_aliases.each do |method_name|
74
- change_global_dsl { undef_method method_name }
75
- end
76
-
77
- @exposed_globally = false
78
- end
79
-
80
- # @private
81
- def self.expose_example_group_alias_globally(method_name)
82
- change_global_dsl do
83
- remove_method(method_name) if method_defined?(method_name)
84
- define_method(method_name) { |*a, &b| ::RSpec.__send__(method_name, *a, &b) }
85
- end
86
- end
87
-
88
- # @private
89
- def self.change_global_dsl(&changes)
90
- (class << top_level; self; end).class_exec(&changes)
91
- Module.class_exec(&changes)
92
- end
93
46
  end
94
47
  end
95
48
  end
96
49
 
97
50
  # Capture main without an eval.
51
+ # rubocop:disable Style/RedundantConstantBase
98
52
  ::RSpec::Core::DSL.top_level = self
53
+ # rubocop:enable Style/RedundantConstantBase
@@ -1,3 +1,5 @@
1
+ RSpec::Support.require_rspec_support 'ruby_features'
2
+
1
3
  module RSpec
2
4
  module Core
3
5
  # Wrapper for an instance of a subclass of {ExampleGroup}. An instance of
@@ -34,7 +36,7 @@ module RSpec
34
36
  # shared_examples "auditable" do
35
37
  # it "does something" do
36
38
  # log "#{example.full_description}: #{auditable.inspect}"
37
- # auditable.should do_something
39
+ # expect(auditable).to do_something
38
40
  # end
39
41
  # end
40
42
  #
@@ -103,15 +105,6 @@ module RSpec
103
105
  end
104
106
  end
105
107
 
106
- # Returns the location-based argument that can be passed to the `rspec` command to rerun this example.
107
- #
108
- # @deprecated Use {#location_rerun_argument} instead.
109
- # @note If there are multiple examples identified by this location, they will use {#id}
110
- # to rerun instead, but this method will still return the location (that's why it is deprecated!).
111
- def rerun_argument
112
- location_rerun_argument
113
- end
114
-
115
108
  # @return [String] the unique id of this example. Pass
116
109
  # this at the command line to re-run this exact example.
117
110
  def id
@@ -296,7 +289,7 @@ module RSpec
296
289
  RSpec.current_example = nil
297
290
  end
298
291
 
299
- if RSpec::Support::Ruby.jruby? || RUBY_VERSION.to_f < 1.9
292
+ if RSpec::Support::Ruby.jruby?
300
293
  # :nocov:
301
294
  # For some reason, rescuing `Support::AllExceptionsExceptOnesWeMustNotRescue`
302
295
  # in place of `Exception` above can cause the exit status to be the wrong
@@ -544,7 +537,7 @@ module RSpec
544
537
  RSpec::Matchers.generated_description
545
538
  rescue Support::AllExceptionsExceptOnesWeMustNotRescue => e
546
539
  location_description + " (Got an error when generating description " \
547
- "from matcher: #{e.class}: #{e.message} -- #{e.backtrace.first})"
540
+ "from matcher: #{e.class}: #{e.message} -- #{e.backtrace.first})"
548
541
  end
549
542
 
550
543
  def location_description
@@ -552,10 +545,7 @@ module RSpec
552
545
  end
553
546
 
554
547
  # Represents the result of executing an example.
555
- # Behaves like a hash for backwards compatibility.
556
548
  class ExecutionResult
557
- include HashImitatable
558
-
559
549
  # @return [Symbol] `:passed`, `:failed` or `:pending`.
560
550
  attr_accessor :status
561
551
 
@@ -617,32 +607,6 @@ module RSpec
617
607
  self.finished_at = finished_at
618
608
  self.run_time = (finished_at - started_at).to_f
619
609
  end
620
-
621
- # For backwards compatibility we present `status` as a string
622
- # when presenting the legacy hash interface.
623
- def hash_for_delegation
624
- super.tap do |hash|
625
- hash[:status] &&= status.to_s
626
- end
627
- end
628
-
629
- def set_value(name, value)
630
- value &&= value.to_sym if name == :status
631
- super(name, value)
632
- end
633
-
634
- def get_value(name)
635
- if name == :status
636
- status.to_s if status
637
- else
638
- super
639
- end
640
- end
641
-
642
- def issue_deprecation(_method_name, *_args)
643
- RSpec.deprecate("Treating `metadata[:execution_result]` as a hash",
644
- :replacement => "the attributes methods to access the data")
645
- end
646
610
  end
647
611
  end
648
612
 
@@ -321,12 +321,12 @@ module RSpec
321
321
  # @return [RSpec::Core::ExampleGroup]
322
322
  #
323
323
  # @see SharedExampleGroup
324
- def self.define_nested_shared_group_method(new_name, report_label="it should behave like")
324
+ def self.define_nested_shared_group_method(new_name, report_label="behaves like")
325
325
  idempotently_define_singleton_method(new_name) do |name, *args, &customization_block|
326
326
  # Pass :caller so the :location metadata is set properly.
327
327
  # Otherwise, it'll be set to the next line because that's
328
328
  # the block's source_location.
329
- group = example_group("#{report_label} #{name}", :caller => (the_caller = caller)) do
329
+ group = example_group("#{report_label} #{name}", :caller => (the_caller = caller(1, 1))) do
330
330
  find_and_eval_shared("examples", name, the_caller.first, *args, &customization_block)
331
331
  end
332
332
  group.metadata[:shared_group_name] = name
@@ -336,10 +336,7 @@ module RSpec
336
336
 
337
337
  # Generates a nested example group and includes the shared content
338
338
  # mapped to `name` in the nested group.
339
- define_nested_shared_group_method :it_behaves_like, "behaves like"
340
- # Generates a nested example group and includes the shared content
341
- # mapped to `name` in the nested group.
342
- define_nested_shared_group_method :it_should_behave_like
339
+ define_nested_shared_group_method :it_behaves_like
343
340
 
344
341
  # Includes shared content mapped to `name` directly in the group in which
345
342
  # it is declared, as opposed to `it_behaves_like`, which creates a nested
@@ -347,8 +344,10 @@ module RSpec
347
344
  # context.
348
345
  #
349
346
  # @see SharedExampleGroup
350
- def self.include_context(name, *args, &block)
351
- find_and_eval_shared("context", name, caller.first, *args, &block)
347
+ def self.include_context(name, *args)
348
+ issue_block_inclusion_error!("include_context") if block_given?
349
+
350
+ find_and_eval_shared("context", name, caller(1, 1).first, *args)
352
351
  end
353
352
 
354
353
  # Includes shared content mapped to `name` directly in the group in which
@@ -357,8 +356,10 @@ module RSpec
357
356
  # context.
358
357
  #
359
358
  # @see SharedExampleGroup
360
- def self.include_examples(name, *args, &block)
361
- find_and_eval_shared("examples", name, caller.first, *args, &block)
359
+ def self.include_examples(name, *args)
360
+ issue_block_inclusion_error!("include_examples") if block_given?
361
+
362
+ find_and_eval_shared("examples", name, caller(1, 1).first, *args)
362
363
  end
363
364
 
364
365
  # Clear memoized values when adding/removing examples
@@ -396,6 +397,15 @@ module RSpec
396
397
  )
397
398
  end
398
399
 
400
+ # @private
401
+ def self.issue_block_inclusion_error!(method)
402
+ raise ArgumentError,
403
+ "Do not pass a block to `#{method}`. " \
404
+ "Either use `it_behaves_like` to wrap the block " \
405
+ "contents in a context, or place the block content " \
406
+ "within the parent context."
407
+ end
408
+
399
409
  # @!endgroup
400
410
 
401
411
  # @private
@@ -415,14 +425,15 @@ module RSpec
415
425
 
416
426
  # @private
417
427
  def self.set_it_up(description, args, registration_collection, &example_group_block)
418
- # Ruby 1.9 has a bug that can lead to infinite recursion and a
419
- # SystemStackError if you include a module in a superclass after
428
+ # Historically Ruby had a bug that could lead to infinite recursion and a
429
+ # SystemStackError if you included a module in a superclass after
420
430
  # including it in a subclass: https://gist.github.com/845896
421
- # To prevent this, we must include any modules in
422
- # RSpec::Core::ExampleGroup before users create example groups and have
423
- # a chance to include the same module in a subclass of
424
- # RSpec::Core::ExampleGroup. So we need to configure example groups
425
- # here.
431
+ #
432
+ # To prevent this, we included any modules in RSpec::Core::ExampleGroup
433
+ # before users create example groups and have a chance to include the same module
434
+ # in a subclass of RSpec::Core::ExampleGroup.
435
+ #
436
+ # This may be changed if a better use case comes up in future.
426
437
  ensure_example_groups_are_configured
427
438
 
428
439
  # Register the example with the group before creating the metadata hash.
@@ -466,7 +477,7 @@ module RSpec
466
477
  # @private
467
478
  def self.descendant_filtered_examples
468
479
  @descendant_filtered_examples ||= filtered_examples +
469
- FlatMap.flat_map(children, &:descendant_filtered_examples)
480
+ children.flat_map(&:descendant_filtered_examples)
470
481
  end
471
482
 
472
483
  # @private
@@ -508,7 +519,7 @@ module RSpec
508
519
 
509
520
  # @private
510
521
  def self.descendants
511
- @_descendants ||= [self] + FlatMap.flat_map(children, &:descendants)
522
+ @_descendants ||= [self] + children.flat_map(&:descendants)
512
523
  end
513
524
 
514
525
  ## @private
@@ -564,28 +575,9 @@ module RSpec
564
575
  @currently_executing_a_context_hook = false
565
576
  end
566
577
 
567
- if RUBY_VERSION.to_f >= 1.9
568
- # @private
569
- def self.superclass_before_context_ivars
570
- superclass.before_context_ivars
571
- end
572
- else # 1.8.7
573
- # :nocov:
574
- # @private
575
- def self.superclass_before_context_ivars
576
- if superclass.respond_to?(:before_context_ivars)
577
- superclass.before_context_ivars
578
- else
579
- # `self` must be the singleton class of an ExampleGroup instance.
580
- # On 1.8.7, the superclass of a singleton class of an instance of A
581
- # is A's singleton class. On 1.9+, it's A. On 1.8.7, the first ancestor
582
- # is A, so we can mirror 1.8.7's behavior here. Note that we have to
583
- # search for the first that responds to `before_context_ivars`
584
- # in case a module has been included in the singleton class.
585
- ancestors.find { |a| a.respond_to?(:before_context_ivars) }.before_context_ivars
586
- end
587
- end
588
- # :nocov:
578
+ # @private
579
+ def self.superclass_before_context_ivars
580
+ superclass.before_context_ivars
589
581
  end
590
582
 
591
583
  # @private
@@ -674,7 +666,7 @@ module RSpec
674
666
  def self.declaration_locations
675
667
  @declaration_locations ||= [Metadata.location_tuple_from(metadata)] +
676
668
  examples.map { |e| Metadata.location_tuple_from(e.metadata) } +
677
- FlatMap.flat_map(children, &:declaration_locations)
669
+ children.flat_map(&:declaration_locations)
678
670
  end
679
671
 
680
672
  # @return [String] the unique id of this example group. Pass
@@ -693,20 +685,10 @@ module RSpec
693
685
  ivars.each { |name, value| instance.instance_variable_set(name, value) }
694
686
  end
695
687
 
696
- if RUBY_VERSION.to_f < 1.9
697
- # :nocov:
698
- # @private
699
- INSTANCE_VARIABLE_TO_IGNORE = '@__inspect_output'.freeze
700
- # :nocov:
701
- else
702
- # @private
703
- INSTANCE_VARIABLE_TO_IGNORE = :@__inspect_output
704
- end
705
-
706
688
  # @private
707
689
  def self.each_instance_variable_for_example(group)
708
690
  group.instance_variables.each do |ivar|
709
- yield ivar unless ivar == INSTANCE_VARIABLE_TO_IGNORE
691
+ yield ivar unless ivar == :@__inspect_output
710
692
  end
711
693
  end
712
694
 
@@ -721,15 +703,6 @@ module RSpec
721
703
  "#<#{self.class} #{@__inspect_output}>"
722
704
  end
723
705
 
724
- unless method_defined?(:singleton_class) # for 1.8.7
725
- # :nocov:
726
- # @private
727
- def singleton_class
728
- class << self; self; end
729
- end
730
- # :nocov:
731
- end
732
-
733
706
  # @private
734
707
  def self.update_inherited_metadata(updates)
735
708
  metadata.update(updates) do |key, existing_group_value, new_inherited_value|
@@ -811,7 +784,7 @@ module RSpec
811
784
  # RSpec's built-in formatters.
812
785
  def description
813
786
  @description ||= "Shared Example Group: #{shared_group_name.inspect} " \
814
- "called from #{formatted_inclusion_location}"
787
+ "called from #{formatted_inclusion_location}"
815
788
  end
816
789
 
817
790
  # @private
@@ -887,18 +860,6 @@ module RSpec
887
860
  name
888
861
  end
889
862
 
890
- if RUBY_VERSION == '1.9.2'
891
- # :nocov:
892
- class << self
893
- alias _base_name_for base_name_for
894
- def base_name_for(group)
895
- _base_name_for(group) + '_'
896
- end
897
- end
898
- private_class_method :_base_name_for
899
- # :nocov:
900
- end
901
-
902
863
  def self.disambiguate(name, const_scope)
903
864
  return name unless const_defined_on?(const_scope, name)
904
865
 
@@ -39,8 +39,6 @@ module RSpec
39
39
  # `examples` will be empty.
40
40
  return examples if examples.empty?
41
41
 
42
- examples = prune_conditionally_filtered_examples(examples)
43
-
44
42
  if inclusions.standalone?
45
43
  examples.select { |e| inclusions.include_example?(e) }
46
44
  else
@@ -48,7 +46,7 @@ module RSpec
48
46
 
49
47
  examples.select do |ex|
50
48
  file_scoped_include?(ex.metadata, ids, locations) do
51
- !exclusions.include_example?(ex) && non_scoped_inclusions.include_example?(ex)
49
+ (exclusions.empty? || !exclusions.include_example?(ex)) && non_scoped_inclusions.include_example?(ex)
52
50
  end
53
51
  end
54
52
  end
@@ -86,13 +84,6 @@ module RSpec
86
84
  inclusions.add(filter_key => filter)
87
85
  end
88
86
 
89
- def prune_conditionally_filtered_examples(examples)
90
- examples.reject do |ex|
91
- meta = ex.metadata
92
- !meta.fetch(:if, true) || meta[:unless]
93
- end
94
- end
95
-
96
87
  # When a user specifies a particular spec location, that takes priority
97
88
  # over any exclusion filters (such as if the spec is tagged with `:slow`
98
89
  # and there is a `:slow => true` exclusion filter), but only for specs
@@ -175,7 +166,7 @@ module RSpec
175
166
  end
176
167
 
177
168
  def include_example?(example)
178
- MetadataFilter.apply?(:any?, @rules, example.metadata)
169
+ MetadataFilter.apply?(@rules, example.metadata)
179
170
  end
180
171
  end
181
172
 
@@ -58,15 +58,15 @@ module RSpec
58
58
  EOS
59
59
 
60
60
  DEPRECATION_STREAM_NOTICE = "Pass `--deprecation-out` or set " \
61
- "`config.deprecation_stream` to a file for full output."
61
+ "`config.deprecation_stream` to a file for full output."
62
62
  TOO_MANY_WARNINGS_NOTICE = "Too many similar deprecation messages " \
63
- "reported, disregarding further reports. #{DEPRECATION_STREAM_NOTICE}"
63
+ "reported, disregarding further reports. #{DEPRECATION_STREAM_NOTICE}"
64
64
 
65
65
  # @private
66
66
  SpecifiedDeprecationMessage = Struct.new(:type) do
67
67
  def initialize(data)
68
68
  @message = data.message
69
- super deprecation_type_for(data)
69
+ super(deprecation_type_for(data))
70
70
  end
71
71
 
72
72
  def to_s
@@ -94,7 +94,7 @@ module RSpec
94
94
  GeneratedDeprecationMessage = Struct.new(:type) do
95
95
  def initialize(data)
96
96
  @data = data
97
- super data.deprecated
97
+ super(data.deprecated)
98
98
  end
99
99
 
100
100
  def to_s
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  RSpec::Support.require_rspec_core "formatters/console_codes"
3
2
  RSpec::Support.require_rspec_core "formatters/snippet_extractor"
4
3
  RSpec::Support.require_rspec_core 'formatters/syntax_highlighter'
@@ -11,8 +10,10 @@ module RSpec
11
10
  class ExceptionPresenter
12
11
  attr_reader :exception, :example, :description, :message_color,
13
12
  :detail_formatter, :extra_detail_formatter, :backtrace_formatter
14
- private :message_color, :detail_formatter, :extra_detail_formatter, :backtrace_formatter
15
13
 
14
+ # We want private attr_reader but that issues a warning on older rubies, refactor later
15
+ #
16
+ private :message_color, :detail_formatter, :extra_detail_formatter, :backtrace_formatter
16
17
  def initialize(exception, example, options={})
17
18
  @exception = exception
18
19
  @example = example
@@ -41,38 +42,30 @@ module RSpec
41
42
  formatted_cause(exception)
42
43
  end
43
44
 
44
- if RSpec::Support::RubyFeatures.supports_exception_cause?
45
- def formatted_cause(exception)
46
- last_cause = final_exception(exception, [exception])
47
- cause = []
45
+ def formatted_cause(exception)
46
+ last_cause = final_exception(exception, [exception])
47
+ cause = []
48
48
 
49
- if exception.cause
50
- cause << '------------------'
51
- cause << '--- Caused by: ---'
52
- cause << "#{exception_class_name(last_cause)}:" unless exception_class_name(last_cause) =~ /RSpec/
49
+ if exception.cause
50
+ cause << '------------------'
51
+ cause << '--- Caused by: ---'
52
+ cause << "#{exception_class_name(last_cause)}:" unless exception_class_name(last_cause) =~ /RSpec/
53
53
 
54
- encoded_string(exception_message_string(last_cause)).split("\n").each do |line|
55
- cause << " #{line}"
56
- end
54
+ encoded_string(exception_message_string(last_cause)).split("\n").each do |line|
55
+ cause << " #{line}"
56
+ end
57
57
 
58
- unless last_cause.backtrace.nil? || last_cause.backtrace.empty?
59
- lines = backtrace_formatter.format_backtrace(last_cause.backtrace, example.metadata)
60
- lines = [lines[0]] unless RSpec.configuration.full_cause_backtrace # rubocop:disable Metrics/BlockNesting
58
+ unless last_cause.backtrace.nil? || last_cause.backtrace.empty?
59
+ lines = backtrace_formatter.format_backtrace(last_cause.backtrace, example.metadata)
60
+ lines = [lines[0]] unless RSpec.configuration.full_cause_backtrace
61
61
 
62
- lines.each do |line|
63
- cause << (" #{line}")
64
- end
62
+ lines.each do |line|
63
+ cause << (" #{line}")
65
64
  end
66
65
  end
67
-
68
- cause
69
- end
70
- else
71
- # :nocov:
72
- def formatted_cause(_)
73
- []
74
66
  end
75
- # :nocov:
67
+
68
+ cause
76
69
  end
77
70
 
78
71
  def colorized_formatted_backtrace(colorizer=::RSpec::Core::Formatters::ConsoleCodes)
@@ -112,23 +105,12 @@ module RSpec
112
105
  end
113
106
  end
114
107
 
115
- if String.method_defined?(:encoding)
116
- def encoding_of(string)
117
- string.encoding
118
- end
119
-
120
- def encoded_string(string)
121
- RSpec::Support::EncodedString.new(string, Encoding.default_external)
122
- end
123
- else # for 1.8.7
124
- # :nocov:
125
- def encoding_of(_string)
126
- end
108
+ def encoding_of(string)
109
+ string.encoding
110
+ end
127
111
 
128
- def encoded_string(string)
129
- RSpec::Support::EncodedString.new(string)
130
- end
131
- # :nocov:
112
+ def encoded_string(string)
113
+ RSpec::Support::EncodedString.new(string, Encoding.default_external)
132
114
  end
133
115
 
134
116
  def indent_lines(lines, failure_number)
@@ -181,7 +163,7 @@ module RSpec
181
163
 
182
164
  # rubocop:disable Lint/RescueException
183
165
  # :nocov:
184
- if SyntaxError.instance_methods.include?(:detailed_message)
166
+ if SyntaxError.method_defined?(:detailed_message)
185
167
  def exception_message_string(exception)
186
168
  case exception
187
169
  when SyntaxError then exception.detailed_message.to_s
@@ -253,10 +235,6 @@ module RSpec
253
235
  ["Unable to find #{file_path} to read failed line"]
254
236
  rescue SnippetExtractor::NoSuchLineError
255
237
  ["Unable to find matching line in #{file_path}"]
256
- rescue SecurityError
257
- # :nocov: - SecurityError is no longer produced starting in ruby 2.7
258
- ["Unable to read failed line"]
259
- # :nocov:
260
238
  end
261
239
 
262
240
  def find_failed_line
@@ -283,17 +261,9 @@ module RSpec
283
261
  end
284
262
  end
285
263
 
286
- if String.method_defined?(:encoding)
287
- def encoded_description(description)
288
- return if description.nil?
289
- encoded_string(description)
290
- end
291
- else # for 1.8.7
292
- # :nocov:
293
- def encoded_description(description)
294
- description
295
- end
296
- # :nocov:
264
+ def encoded_description(description)
265
+ return if description.nil?
266
+ encoded_string(description)
297
267
  end
298
268
 
299
269
  def exception_backtrace
@@ -392,7 +362,7 @@ module RSpec
392
362
  common_backtrace_truncater = CommonBacktraceTruncater.new(exception)
393
363
 
394
364
  lambda do |failure_number, colorizer|
395
- FlatMap.flat_map(exception.all_exceptions.each_with_index) do |failure, index|
365
+ exception.all_exceptions.each_with_index.flat_map do |failure, index|
396
366
  options = with_multiple_error_options_as_needed(
397
367
  failure,
398
368
  :description => nil,