Class: RSpec::Core::World Private
Relationships & Source Files | |
Namespace Children | |
Modules:
| |
Inherits: | Object |
Defined in: | rspec-core/lib/rspec/core/world.rb |
Overview
Internal container for global non-configuration data.
Class Method Summary
- .new(configuration = RSpec.configuration) ⇒ World constructor Internal use only
Instance Attribute Summary
- #example_group_counts_by_spec_file readonly Internal use only
- #example_groups readonly Internal use only
- #filtered_examples readonly Internal use only
-
#non_example_failure
rw
Internal use only
Used internally to signal that a failure outside of an example has occurred, and that therefore the exit status should indicate the run failed.
-
#rspec_is_quitting
rw
Internal use only
Used internally to signify that a SystemExit occurred in Configuration#load_file_handling_errors, and thus examples cannot be counted accurately.
-
#wants_to_quit
rw
Internal use only
Used internally to determine what to do when a SIGINT is received.
Instance Method Summary
- #all_example_groups Internal use only
- #all_examples Internal use only
-
#announce_exclusion_filter(announcements)
Internal use only
Add exclusion filters to announcement message.
-
#announce_filters
Internal use only
Notify reporter of filters.
-
#announce_inclusion_filter(announcements)
Internal use only
Add inclusion filters to announcement message.
- #everything_filtered_message Internal use only
-
#example_count(groups = example_groups)
Internal use only
Get count of examples to be run.
- #exclusion_filter Internal use only
- #filter_manager Internal use only
- #inclusion_filter Internal use only
- #num_example_groups_defined_in(file) Internal use only
-
#ordered_example_groups
Internal use only
Apply ordering strategy from configuration to example groups.
-
#preceding_declaration_line(absolute_file_name, filter_line)
Internal use only
Find line number of previous declaration.
-
#prepare_example_filtering
Prepares filters so that they apply to example groups when they run.
-
#record(example_group)
Internal use only
Records an example group.
- #registered_example_group_files Internal use only
- #report_filter_message(message) Internal use only
- #reporter Internal use only
-
#reset
Internal use only
Reset world to ‘scratch’ before running suite.
- #shared_example_group_registry Internal use only
- #source_from_file(path) Internal use only
- #syntax_highlighter Internal use only
-
#traverse_example_group_trees_until(&block)
Internal use only
Traverses the tree of each top level group.
- #descending_declaration_line_numbers_by_file private Internal use only
- #fail_if_config_and_cli_options_invalid private Internal use only
Instance Attribute Details
#example_group_counts_by_spec_file (readonly)
[ GitHub ]# File 'rspec-core/lib/rspec/core/world.rb', line 8
attr_reader :example_groups, :filtered_examples, :example_group_counts_by_spec_file
#example_groups (readonly)
[ GitHub ]# File 'rspec-core/lib/rspec/core/world.rb', line 8
attr_reader :example_groups, :filtered_examples, :example_group_counts_by_spec_file
#filtered_examples (readonly)
[ GitHub ]# File 'rspec-core/lib/rspec/core/world.rb', line 8
attr_reader :example_groups, :filtered_examples, :example_group_counts_by_spec_file
#non_example_failure (rw)
Used internally to signal that a failure outside of an example has occurred, and that therefore the exit status should indicate the run failed.
# File 'rspec-core/lib/rspec/core/world.rb', line 24
attr_accessor :non_example_failure
#rspec_is_quitting (rw)
Used internally to signify that a SystemExit occurred in Configuration#load_file_handling_errors, and thus examples cannot be counted accurately. Specifically, we cannot accurately report “No examples found”.
# File 'rspec-core/lib/rspec/core/world.rb', line 18
attr_accessor :rspec_is_quitting
#wants_to_quit (rw)
Used internally to determine what to do when a SIGINT is received.
# File 'rspec-core/lib/rspec/core/world.rb', line 11
attr_accessor :wants_to_quit
Instance Method Details
#all_example_groups
[ GitHub ]# File 'rspec-core/lib/rspec/core/world.rb', line 115
def all_example_groups FlatMap.flat_map(example_groups) { |g| g.descendants } end
#all_examples
[ GitHub ]# File 'rspec-core/lib/rspec/core/world.rb', line 120
def all_examples FlatMap.flat_map(all_example_groups) { |g| g.examples } end
#announce_exclusion_filter(announcements)
Add exclusion filters to announcement message.
# File 'rspec-core/lib/rspec/core/world.rb', line 226
def announce_exclusion_filter(announcements) return if exclusion_filter.empty? announcements << "exclude #{exclusion_filter.description}" end
#announce_filters
Notify reporter of filters.
# File 'rspec-core/lib/rspec/core/world.rb', line 171
def announce_filters filter_announcements = [] announce_inclusion_filter filter_announcements announce_exclusion_filter filter_announcements unless filter_manager.empty? if filter_announcements.length == 1 ("Run options: #{filter_announcements[0]}") else ("Run options:\n #{filter_announcements.join("\n ")}") end end if @configuration.run_all_when_everything_filtered? && example_count.zero? && !@configuration.only_failures? ("#{}; 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? ("No examples found.") elsif exclusion_filter.empty? || inclusion_filter.empty? ( ) end end end
#announce_inclusion_filter(announcements)
Add inclusion filters to announcement message.
# File 'rspec-core/lib/rspec/core/world.rb', line 217
def announce_inclusion_filter(announcements) return if inclusion_filter.empty? announcements << "include #{inclusion_filter.description}" end
#descending_declaration_line_numbers_by_file (private)
[ GitHub ]# File 'rspec-core/lib/rspec/core/world.rb', line 234
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
#everything_filtered_message
[ GitHub ]# File 'rspec-core/lib/rspec/core/world.rb', line 210
def "\nAll examples were filtered out" end
#example_count(groups = example_groups)
Get count of examples to be run.
# File 'rspec-core/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
#exclusion_filter
[ GitHub ]# File 'rspec-core/lib/rspec/core/world.rb', line 102
def exclusion_filter @configuration.exclusion_filter end
#fail_if_config_and_cli_options_invalid (private)
[ GitHub ]# File 'rspec-core/lib/rspec/core/world.rb', line 252
def 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
#filter_manager
[ GitHub ]# File 'rspec-core/lib/rspec/core/world.rb', line 69
def filter_manager @configuration.filter_manager end
#inclusion_filter
[ GitHub ]# File 'rspec-core/lib/rspec/core/world.rb', line 97
def inclusion_filter @configuration.inclusion_filter end
#num_example_groups_defined_in(file)
[ GitHub ]# File 'rspec-core/lib/rspec/core/world.rb', line 87
def num_example_groups_defined_in(file) @example_group_counts_by_spec_file[file] end
#ordered_example_groups
Apply ordering strategy from configuration to example groups.
# File 'rspec-core/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)
Find line number of previous declaration.
# File 'rspec-core/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_filtering
Prepares filters so that they apply to example groups when they run.
This is a separate method so that filters can be modified/replaced and examples refiltered during a process’s lifetime, which can be useful for a custom runner.
# File 'rspec-core/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)
Records an example group.
# File 'rspec-core/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
#registered_example_group_files
[ GitHub ]# File 'rspec-core/lib/rspec/core/world.rb', line 74
def registered_example_group_files @example_group_counts_by_spec_file.keys end
#report_filter_message(message)
[ GitHub ]# File 'rspec-core/lib/rspec/core/world.rb', line 205
def ( ) reporter. ( ) unless @configuration.silence_filter_announcements? end
#reporter
[ GitHub ]# File 'rspec-core/lib/rspec/core/world.rb', line 149
def reporter @configuration.reporter end
#reset
Reset world to ‘scratch’ before running suite.
# File 'rspec-core/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
#source_from_file(path)
[ GitHub ]#syntax_highlighter
[ GitHub ]# File 'rspec-core/lib/rspec/core/world.rb', line 164
def syntax_highlighter @syntax_highlighter ||= Formatters::SyntaxHighlighter.new(@configuration) end
#traverse_example_group_trees_until(&block)
Traverses the tree of each top level group. For each it yields the group, then the children, recursively. Halts the traversal of a branch of the tree as soon as the passed block returns true. Note that siblings groups and their sub-trees will continue to be explored. This is intended to make it easy to find the top-most group that satisfies some condition.
# File 'rspec-core/lib/rspec/core/world.rb', line 131
def traverse_example_group_trees_until(&block) example_groups.each do |group| group.traverse_tree_until(&block) end end