类: RSpec::Core::Notifications::ProfileNotification
- 继承
-
Object
- Object
- RSpec::Core::Notifications::ProfileNotification
- 定义于
- lib/rspec/core/notifications.rb
概述
ProfileNotification
类保存了在启用性能分析时运行测试套件结果的信息。格式化程序使用它在测试运行结束后提供性能分析信息。
实例属性摘要 收起
-
#duration ⇒ Float
运行套件所花费的时间(以秒为单位)。
-
#example_groups ⇒ Array<RSpec::Core::Profiler>
运行的示例组。
-
#examples ⇒ Array<RSpec::Core::Example>
运行的示例。
-
#number_of_examples ⇒ Fixnum
要进行性能分析的示例数量。
实例方法摘要 收起
-
#initialize(duration, examples, number_of_examples, example_groups) ⇒ ProfileNotification 构造函数
ProfileNotification 的新实例。
-
#percentage ⇒ String
所花费时间的百分比。
-
#slow_duration ⇒ Float
运行最慢的示例所花费的时间(以秒为单位)。
-
#slowest_examples ⇒ Array<RSpec::Core::Example>
最慢的示例。
-
#slowest_groups ⇒ Array<RSpec::Core::Example>
最慢的示例组。
构造函数详细信息
#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 |
实例属性详细信息
#duration ⇒Float
运行套件所花费的时间(以秒为单位)
429 430 431 |
# File 'lib/rspec/core/notifications.rb', line 429 def duration @duration end |
#example_groups ⇒Array<RSpec::Core::Profiler>
运行的示例组
429 430 431 |
# File 'lib/rspec/core/notifications.rb', line 429 def example_groups @example_groups end |
#examples ⇒Array<RSpec::Core::Example>
运行的示例
429 430 431 |
# File 'lib/rspec/core/notifications.rb', line 429 def examples @examples end |
#number_of_examples ⇒Fixnum
要进行性能分析的示例数量
429 430 431 |
# File 'lib/rspec/core/notifications.rb', line 429 def number_of_examples @number_of_examples end |
实例方法详细信息
#percentage ⇒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_duration ⇒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_examples ⇒Array<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_groups ⇒Array<RSpec::Core::Example>
返回最慢的示例组。
464 465 466 |
# File 'lib/rspec/core/notifications.rb', line 464 def slowest_groups @slowest_groups ||= calculate_slowest_groups end |