Class: RSpec::Core::World Private

Inherits:
Object show all
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/world.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Internal container for global non-configuration data.

Defined Under Namespace

Modules: Null

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration = RSpec.configuration) ⇒ World

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of World.



26
27
28
29
30
31
32
33
34
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/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

Instance Attribute Details

#example_group_counts_by_spec_fileObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



8
9
10
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/world.rb', line 8

def example_group_counts_by_spec_file
  @example_group_counts_by_spec_file
end

#example_groupsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



8
9
10
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/world.rb', line 8

def example_groups
  @example_groups
end

#filtered_examplesObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



8
9
10
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/world.rb', line 8

def filtered_examples
  @filtered_examples
end

#non_example_failureObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Used internally to signal that a failure outside of an example has occurred, and that therefore the exit status should indicate the run failed.



24
25
26
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/world.rb', line 24

def non_example_failure
  @non_example_failure
end

#rspec_is_quittingObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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”.



18
19
20
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/world.rb', line 18

def rspec_is_quitting
  @rspec_is_quitting
end

#wants_to_quitObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Used internally to determine what to do when a SIGINT is received.



11
12
13
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/world.rb', line 11

def wants_to_quit
  @wants_to_quit
end

Instance Method Details

#all_example_groupsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



115
116
117
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/world.rb', line 115

def all_example_groups
  FlatMap.flat_map(example_groups) { |g| g.descendants }
end

#all_examplesObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



120
121
122
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/world.rb', line 120

def all_examples
  FlatMap.flat_map(all_example_groups) { |g| g.examples }
end

#announce_exclusion_filter(announcements) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Add exclusion filters to announcement message.



226
227
228
229
230
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/world.rb', line 226

def announce_exclusion_filter(announcements)
  return if exclusion_filter.empty?

  announcements << "exclude #{exclusion_filter.description}"
end

#announce_filtersObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Notify reporter of filters.



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/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/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) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Add inclusion filters to announcement message.



217
218
219
220
221
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/world.rb', line 217

def announce_inclusion_filter(announcements)
  return if inclusion_filter.empty?

  announcements << "include #{inclusion_filter.description}"
end

#everything_filtered_messageObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



210
211
212
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/world.rb', line 210

def everything_filtered_message
  "\nAll examples were filtered out"
end

#example_count(groups = example_groups) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Get count of examples to be run.



109
110
111
112
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/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_filterObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



102
103
104
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/world.rb', line 102

def exclusion_filter
  @configuration.exclusion_filter
end

#filter_managerObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



69
70
71
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/world.rb', line 69

def filter_manager
  @configuration.filter_manager
end

#inclusion_filterObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



97
98
99
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/world.rb', line 97

def inclusion_filter
  @configuration.inclusion_filter
end

#num_example_groups_defined_in(file) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



87
88
89
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/world.rb', line 87

def num_example_groups_defined_in(file)
  @example_group_counts_by_spec_file[file]
end

#ordered_example_groupsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Apply ordering strategy from configuration to example groups.



52
53
54
55
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/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) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Find line number of previous declaration.



140
141
142
143
144
145
146
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/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_filteringObject

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.



43
44
45
46
47
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/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) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Records an example group.



81
82
83
84
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/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_filesObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



74
75
76
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/world.rb', line 74

def registered_example_group_files
  @example_group_counts_by_spec_file.keys
end

#report_filter_message(message) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



205
206
207
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/world.rb', line 205

def report_filter_message(message)
  reporter.message(message) unless @configuration.silence_filter_announcements?
end

#reporterObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



149
150
151
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/world.rb', line 149

def reporter
  @configuration.reporter
end

#resetObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Reset world to ‘scratch’ before running suite.



60
61
62
63
64
65
66
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/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

#shared_example_group_registryObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



92
93
94
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/world.rb', line 92

def shared_example_group_registry
  @shared_example_group_registry ||= SharedExampleGroup::Registry.new
end

#source_from_file(path) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



154
155
156
157
158
159
160
161
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/world.rb', line 154

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

#syntax_highlighterObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



164
165
166
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/world.rb', line 164

def syntax_highlighter
  @syntax_highlighter ||= Formatters::SyntaxHighlighter.new(@configuration)
end

#traverse_example_group_trees_until(&block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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.



131
132
133
134
135
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/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