类: RSpec::Core::World 私有

继承
Object
  • Object
显示全部
定义在
lib/rspec/core/world.rb

概述

此类是私有 API 的一部分。 应尽量避免使用此类,因为它可能会在将来被移除或更改。

用于存放全局非配置数据的内部容器。

实例属性摘要 折叠

实例方法摘要 折叠

构造函数详细信息

#initialize(configuration = RSpec.configuration) ⇒World

此方法是私有 API 的一部分。 应尽量避免使用此方法,因为它可能会在将来被移除或更改。

返回 World 的新实例。

26
27
28
29
30
31
32
33
34
# File 'lib/rspec/core/world.rb', line 26
def initialize(configuration=RSpec.configuration)
  @wants_to_quit = false
  @rspec_is_quitting = false
  @configuration = configuration
  configuration.world = self
  @example_groups = []
  @example_group_counts_by_spec_file = Hash.new(0)
  prepare_example_filtering
end

实例属性详细信息

#wants_to_quitvoid

此方法是私有 API 的一部分。 应尽量避免使用此方法,因为它可能会在将来被移除或更改。

用于在接收到 SIGINT 时内部确定要执行的操作。

11
12
13
# File 'lib/rspec/core/world.rb', line 11
def wants_to_quit
  @wants_to_quit
end

实例方法详细信息

#announce_exclusion_filter(announcements) ⇒void

此方法是私有 API 的一部分。 应尽量避免使用此方法,因为它可能会在将来被移除或更改。

将排除过滤器添加到公告消息中。

226
227
228
229
230
# File 'lib/rspec/core/world.rb', line 226
def announce_exclusion_filter(announcements)
  return if exclusion_filter.empty?
  announcements << "exclude #{exclusion_filter.description}"
end

#announce_filtersvoid

此方法是私有 API 的一部分。 应尽量避免使用此方法,因为它可能会在将来被移除或更改。

通知报告器过滤器。

171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/rspec/core/world.rb', line 171
def announce_filters
  fail_if_config_and_cli_options_invalid
  filter_announcements = []
  announce_inclusion_filter filter_announcements
  announce_exclusion_filter filter_announcements
  unless filter_manager.empty?
    if filter_announcements.length == 1
      report_filter_message("Run options: #{filter_announcements[0]}")
    else
      report_filter_message("Run options:\n  #{filter_announcements.join("\n  ")}")
    end
  end
  if @configuration.run_all_when_everything_filtered? && example_count.zero? && !@configuration.only_failures?
    report_filter_message("#{everything_filtered_message}; ignoring #{inclusion_filter.description}")
    filtered_examples.clear
    inclusion_filter.clear
  end
  return unless example_count.zero?
  example_groups.clear
  unless rspec_is_quitting
    if filter_manager.empty?
      report_filter_message("No examples found.")
    elsif exclusion_filter.empty? || inclusion_filter.empty?
      report_filter_message(everything_filtered_message)
    end
  end
end

#announce_inclusion_filter(announcements) ⇒void

此方法是私有 API 的一部分。 应尽量避免使用此方法,因为它可能会在将来被移除或更改。

将包含过滤器添加到公告消息中。

217
218
219
220
221
# File 'lib/rspec/core/world.rb', line 217
def announce_inclusion_filter(announcements)
  return if inclusion_filter.empty?
  announcements << "include #{inclusion_filter.description}"
end

#example_count(groups = example_groups) ⇒void

此方法是私有 API 的一部分。 应尽量避免使用此方法,因为它可能会在将来被移除或更改。

获取要运行的示例数量。

109
110
111
112
# File 'lib/rspec/core/world.rb', line 109
def example_count(groups=example_groups)
  FlatMap.flat_map(groups) { |g| g.descendants }.
    inject(0) { |a, e| a + e.filtered_examples.size }
end

#ordered_example_groupsvoid

此方法是私有 API 的一部分。 应尽量避免使用此方法,因为它可能会在将来被移除或更改。

将配置中的排序策略应用于示例组。

52
53
54
55
# File 'lib/rspec/core/world.rb', line 52
def ordered_example_groups
  ordering_strategy = @configuration.ordering_registry.fetch(:global)
  ordering_strategy.order(@example_groups)
end

#preceding_declaration_line(absolute_file_name, filter_line) ⇒void

此方法是私有 API 的一部分。 应尽量避免使用此方法,因为它可能会在将来被移除或更改。

查找先前声明的行号。

140
141
142
143
144
145
146
# File 'lib/rspec/core/world.rb', line 140
def preceding_declaration_line(absolute_file_name, filter_line)
  line_numbers = descending_declaration_line_numbers_by_file.fetch(absolute_file_name) do
    return nil
  end
  line_numbers.find { |num| num <= filter_line }
end

#prepare_example_filteringvoid

准备过滤器,以便它们在示例组运行时应用于它们。

这是一个独立的方法,以便可以在进程的生命周期内修改/替换过滤器并重新过滤示例,这对于自定义运行器很有用。

43
44
45
46
47
# File 'lib/rspec/core/world.rb', line 43
def prepare_example_filtering
  @filtered_examples = Hash.new do |hash, group|
    hash[group] = filter_manager.prune(group.examples)
  end
end

#record(example_group) ⇒void

此方法是私有 API 的一部分。 应尽量避免使用此方法,因为它可能会在将来被移除或更改。

记录示例组。

81
82
83
84
# File 'lib/rspec/core/world.rb', line 81
def record(example_group)
  @configuration.on_example_group_definition_callbacks.each { |block| block.call(example_group) }
  @example_group_counts_by_spec_file[example_group.[:absolute_file_path]] += 1
end

#resetvoid

此方法是私有 API 的一部分。 应尽量避免使用此方法,因为它可能会在将来被移除或更改。

在运行套件之前将世界重置为“空白”。

60
61
62
63
64
65
66
# File 'lib/rspec/core/world.rb', line 60
def reset
  RSpec::ExampleGroups.remove_all_constants
  example_groups.clear
  @sources_by_path.clear if defined?(@sources_by_path)
  @syntax_highlighter = nil
  @example_group_counts_by_spec_file = Hash.new(0)
end