异常: RSpec::Core::MultipleExceptionError

继承
StandardError
  • Object
显示全部
定义于
lib/rspec/core/formatters/exception_presenter.rb

概述

提供一个单一的异常实例,该实例提供对多个子异常的访问。这用于单个规范有多个异常的情况,例如 it 块中有一个异常,after 块中有一个异常。

实例属性摘要 折叠

实例方法摘要 折叠

构造函数详细信息

#initialize(*exceptions) ⇒MultipleExceptionError

返回 MultipleExceptionError 的新实例。

参数

  • exceptions (Array<Exception>)

    异常的初始列表。

519
520
521
522
523
524
525
526
527
528
529
# File 'lib/rspec/core/formatters/exception_presenter.rb', line 519
def initialize(*exceptions)
  super()
  @failures                = []
  @other_errors            = []
  @all_exceptions          = []
  @aggregation_metadata    = { :hide_backtrace => true }
  @aggregation_block_label = nil
  exceptions.each { |e| add e }
end

实例属性详细信息

#aggregation_block_labelnil (只读)

返回 仅为与 RSpec::Expectations::MultipleExpectationsNotMetError 的接口兼容性而提供。

返回

  • (nil)

    仅为与 RSpec::Expectations::MultipleExpectationsNotMetError 的接口兼容性而提供。

516
517
518
# File 'lib/rspec/core/formatters/exception_presenter.rb', line 516
def aggregation_block_label
  @aggregation_block_label
end

#aggregation_metadataHash (只读)

返回 RSpec 用于格式化目的的元数据。

返回

  • (Hash)

    RSpec 用于格式化目的的元数据。

512
513
514
# File 'lib/rspec/core/formatters/exception_presenter.rb', line 512
def 
  @aggregation_metadata
end

#all_exceptionsArray<Exception> (只读)

返回 失败和其他异常的列表,组合在一起。

返回

  • (Array<Exception>)

    失败和其他异常的列表,组合在一起。

509
510
511
# File 'lib/rspec/core/formatters/exception_presenter.rb', line 509
def all_exceptions
  @all_exceptions
end

#failuresArray<Exception> (只读)

返回 失败的列表。

返回

  • (Array<Exception>)

    失败的列表。

503
504
505
# File 'lib/rspec/core/formatters/exception_presenter.rb', line 503
def failures
  @failures
end

#other_errorsArray<Exception> (只读)

返回 其他错误的列表。

返回

  • (Array<Exception>)

    其他错误的列表。

506
507
508
# File 'lib/rspec/core/formatters/exception_presenter.rb', line 506
def other_errors
  @other_errors
end

实例方法详细信息

#exception_count_descriptionvoid

返回 [String] 失败/错误计数的描述。

544
545
546
547
548
549
# File 'lib/rspec/core/formatters/exception_presenter.rb', line 544
def exception_count_description
  failure_count = Formatters::Helpers.pluralize(failures.size, "failure")
  return failure_count if other_errors.empty?
  error_count = Formatters::Helpers.pluralize(other_errors.size, "other error")
  "#{failure_count} and #{error_count}"
end

#messageString

注意

RSpec 实际上并没有使用它——而是分别格式化每个异常。

返回 将所有异常消息组合成一个字符串。

返回

  • (String)

    将所有异常消息组合成一个字符串。

534
535
536
# File 'lib/rspec/core/formatters/exception_presenter.rb', line 534
def message
  all_exceptions.map(&:message).join("\n\n")
end

#summaryString

返回 失败的摘要,包括块标签和失败计数。

返回

  • (String)

    失败的摘要,包括块标签和失败计数。

539
540
541
# File 'lib/rspec/core/formatters/exception_presenter.rb', line 539
def summary
  "Got #{exception_count_description}"
end