类: RSpec::Core::Reporter
- 继承
-
Object
- Object
- RSpec::Core::Reporter
- 定义于
- lib/rspec/core/reporter.rb
概述
报告器会向监听器(通常是规格套件运行的格式化程序)发送通知。
实例方法摘要 折叠
-
#exit_early(exit_code) ⇒ void
报告在未运行任何示例的情况下提前退出的运行。
-
#initialize(configuration) ⇒ Reporter 构造函数
Reporter 的新实例。
-
#message(message) ⇒ void
向支持的格式化程序发送自定义消息。
-
#publish(event, options = {}) ⇒ void
向支持的注册格式化程序发布自定义事件。
-
#register_listener(listener, *notifications) ⇒ void
将监听器注册到通知列表。
-
#report(expected_example_count) {|Block| ... } ⇒ void
初始化报告运行并自身让渡以进行进一步报告。
构造函数详细信息
#initialize(configuration) ⇒Reporter
返回 Reporter 的新实例。
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rspec/core/reporter.rb', line 14 def initialize(configuration) @configuration = configuration @listeners = Hash.new { |h, k| h[k] = Set.new } @examples = [] @failed_examples = [] @pending_examples = [] @duration = @start = @load_time = nil @non_example_exception_count = 0 @setup_default = lambda {} @setup = false @profiler = nil end |
实例方法详细信息
#exit_early(exit_code) ⇒void
报告在未运行任何示例的情况下提前退出的运行。
84 85 86 |
# File 'lib/rspec/core/reporter.rb', line 84 def exit_early(exit_code) report(0) { exit_code } end |
#message(message) ⇒void
向支持的格式化程序发送自定义消息。
99 100 101 |
# File 'lib/rspec/core/reporter.rb', line 99 def () notify :message, Notifications::MessageNotification.new() end |
#publish(event, options = {}) ⇒void
向支持的注册格式化程序发布自定义事件。
108 109 110 111 112 113 114 |
# File 'lib/rspec/core/reporter.rb', line 108 def publish(event, ={}) if RSPEC_NOTIFICATIONS.include? event raise "RSpec::Core::Reporter#publish is intended for sending custom " \ "events not internal RSpec ones, please rename your custom event." end notify event, Notifications::CustomNotification.for() end |
#register_listener(listener, *notifications) ⇒void
将监听器注册到通知列表。报告器会将事件通知发送给所有注册的监听器。
37 38 39 40 41 42 |
# File 'lib/rspec/core/reporter.rb', line 37 def register_listener(listener, *notifications) notifications.each do |notification| @listeners[notification.to_sym] << listener end true end |
#report(count, &block) ⇒ void #report(count, &block) ⇒ void
初始化报告运行并自身让渡以进行进一步报告。需要块,以便报告器可以管理运行后的清理工作。
71 72 73 74 75 76 77 78 |
# File 'lib/rspec/core/reporter.rb', line 71 def report(expected_example_count) start(expected_example_count) begin yield self ensure finish end end |