class RSpec::Core::World
Internal container for global non-configuration data.
@api private
def all_example_groups
- Private: -
def all_example_groups FlatMap.flat_map(example_groups) { |g| g.descendants } end
def all_examples
- Private: -
def all_examples FlatMap.flat_map(all_example_groups) { |g| g.examples } end
def announce_exclusion_filter(announcements)
- Api: - private
def announce_exclusion_filter(announcements) return if exclusion_filter.empty? announcements << "exclude #{exclusion_filter.description}" end
def announce_filters
- Api: - private
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
def announce_inclusion_filter(announcements)
- Api: - private
def announce_inclusion_filter(announcements) return if inclusion_filter.empty? announcements << "include #{inclusion_filter.description}" end
def descending_declaration_line_numbers_by_file
def descending_declaration_line_numbers_by_file @descending_declaration_line_numbers_by_file ||= begin declaration_locations = FlatMap.flat_map(example_groups, &:declaration_locations) hash_of_arrays = Hash.new { |h, k| h[k] = [] } # TODO: change `inject` to `each_with_object` when we drop 1.8.7 support. line_nums_by_file = declaration_locations.inject(hash_of_arrays) do |hash, (file_name, line_number)| hash[file_name] << line_number hash end line_nums_by_file.each_value do |list| list.sort! list.reverse! end end end
def everything_filtered_message
- Private: -
def everything_filtered_message "\nAll examples were filtered out" end
def example_count(groups=example_groups)
- Api: - private
def example_count(groups=example_groups) FlatMap.flat_map(groups) { |g| g.descendants }. inject(0) { |a, e| a + e.filtered_examples.size } end
def exclusion_filter
- Private: -
def exclusion_filter @configuration.exclusion_filter end
def fail_if_config_and_cli_options_invalid
def fail_if_config_and_cli_options_invalid return unless @configuration.only_failures_but_not_configured? reporter.abort_with( "\nTo use `--only-failures`, you must first set " \ "`config.example_status_persistence_file_path`.", 1 # exit code ) end
def filter_manager
- Private: -
def filter_manager @configuration.filter_manager end
def inclusion_filter
- Private: -
def inclusion_filter @configuration.inclusion_filter end
def initialize(configuration=RSpec.configuration)
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
def num_example_groups_defined_in(file)
- Private: -
def num_example_groups_defined_in(file) @example_group_counts_by_spec_file[file] end
def ordered_example_groups
- Api: - private
def ordered_example_groups ordering_strategy = @configuration.ordering_registry.fetch(:global) ordering_strategy.order(@example_groups) end
def preceding_declaration_line(absolute_file_name, filter_line)
- Api: - private
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
def prepare_example_filtering
- Api: - public
def prepare_example_filtering @filtered_examples = Hash.new do |hash, group| hash[group] = filter_manager.prune(group.examples) end end
def record(example_group)
- Api: - private
def record(example_group) @configuration.on_example_group_definition_callbacks.each { |block| block.call(example_group) } @example_group_counts_by_spec_file[example_group.metadata[:absolute_file_path]] += 1 end
def registered_example_group_files
- Private: -
def registered_example_group_files @example_group_counts_by_spec_file.keys end
def report_filter_message(message)
- Private: -
def report_filter_message(message) reporter.message(message) unless @configuration.silence_filter_announcements? end
def reporter
- Private: -
def reporter @configuration.reporter end
def reset
- Api: - private
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
def shared_example_group_registry
- Private: -
def shared_example_group_registry @shared_example_group_registry ||= SharedExampleGroup::Registry.new end
def source_from_file(path)
- Private: -
def source_from_file(path) unless defined?(@sources_by_path) RSpec::Support.require_rspec_support 'source' @sources_by_path = {} end @sources_by_path[path] ||= Support::Source.from_file(path) end
def syntax_highlighter
- Private: -
def syntax_highlighter @syntax_highlighter ||= Formatters::SyntaxHighlighter.new(@configuration) end
def traverse_example_group_trees_until(&block)
- Private: -
def traverse_example_group_trees_until(&block) example_groups.each do |group| group.traverse_tree_until(&block) end end