类: RSpec::Core::Notifications::ProfileNotification

继承
Object
  • Object
显示所有
定义于
lib/rspec/core/notifications.rb

概述

ProfileNotification 类保存了在启用性能分析时运行测试套件结果的信息。格式化程序使用它在测试运行结束后提供性能分析信息。

实例属性摘要 收起

实例方法摘要 收起

构造函数详细信息

#initialize(duration, examples, number_of_examples, example_groups) ⇒ProfileNotification

返回 ProfileNotification 的新实例。

430
431
432
433
434
435
# File 'lib/rspec/core/notifications.rb', line 430
def initialize(duration, examples, number_of_examples, example_groups)
  @duration = duration
  @examples = examples
  @number_of_examples = number_of_examples
  @example_groups = example_groups
end

实例属性详细信息

#durationFloat

运行套件所花费的时间(以秒为单位)

返回

  • (Float)

    duration 的当前值

429
430
431
# File 'lib/rspec/core/notifications.rb', line 429
def duration
  @duration
end

#example_groupsArray<RSpec::Core::Profiler>

运行的示例组

返回

  • (Array<RSpec::Core::Profiler>)

    example_groups 的当前值

429
430
431
# File 'lib/rspec/core/notifications.rb', line 429
def example_groups
  @example_groups
end

#examplesArray<RSpec::Core::Example>

运行的示例

返回

429
430
431
# File 'lib/rspec/core/notifications.rb', line 429
def examples
  @examples
end

#number_of_examplesFixnum

要进行性能分析的示例数量

返回

  • (Fixnum)

    number_of_examples 的当前值

429
430
431
# File 'lib/rspec/core/notifications.rb', line 429
def number_of_examples
  @number_of_examples
end

实例方法详细信息

#percentageString

返回所花费时间的百分比。

返回

  • (String)

    所花费时间的百分比

455
456
457
458
459
460
461
# File 'lib/rspec/core/notifications.rb', line 455
def percentage
  @percentage ||=
    begin
      time_taken = slow_duration / duration
      '%.1f' % ((time_taken.nan? ? 0.0 : time_taken) * 100)
    end
end

#slow_durationFloat

返回运行最慢的示例所花费的时间(以秒为单位)。

返回

  • (Float)

    运行最慢的示例所花费的时间(以秒为单位)

447
448
449
450
451
452
# File 'lib/rspec/core/notifications.rb', line 447
def slow_duration
  @slow_duration ||=
    slowest_examples.inject(0.0) do |i, e|
      i + e.execution_result.run_time
    end
end

#slowest_examplesArray<RSpec::Core::Example>

返回最慢的示例。

返回

439
440
441
442
443
444
# File 'lib/rspec/core/notifications.rb', line 439
def slowest_examples
  @slowest_examples ||=
    examples.sort_by do |example|
      -example.execution_result.run_time
    end.first(number_of_examples)
end

#slowest_groupsArray<RSpec::Core::Example>

返回最慢的示例组。

返回

464
465
466
# File 'lib/rspec/core/notifications.rb', line 464
def slowest_groups
  @slowest_groups ||= calculate_slowest_groups
end