Class: RSpec::Core::World Private
- Inherits:
-
Object
- Object
- RSpec::Core::World
- Defined in:
- 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.
Instance Attribute Summary collapse
-
#wants_to_quit ⇒ void
private
Used internally to determine what to do when a SIGINT is received.
Instance Method Summary collapse
-
#announce_exclusion_filter(announcements) ⇒ void
private
Add exclusion filters to announcement message.
-
#announce_filters ⇒ void
private
Notify reporter of filters.
-
#announce_inclusion_filter(announcements) ⇒ void
private
Add inclusion filters to announcement message.
-
#example_count(groups = example_groups) ⇒ void
private
Get count of examples to be run.
-
#initialize(configuration = RSpec.configuration) ⇒ World
constructor
private
A new instance of World.
-
#ordered_example_groups ⇒ void
private
Apply ordering strategy from configuration to example groups.
-
#preceding_declaration_line(absolute_file_name, filter_line) ⇒ void
private
Find line number of previous declaration.
-
#prepare_example_filtering ⇒ void
Prepares filters so that they apply to example groups when they run.
-
#record(example_group) ⇒ void
private
Records an example group.
-
#reset ⇒ void
private
Reset world to 'scratch' before running suite.
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.
19 20 21 22 23 24 25 26 |
# File 'lib/rspec/core/world.rb', line 19 def initialize(configuration=RSpec.configuration) @wants_to_quit = false @configuration = configuration configuration.world = self @example_groups = [] @example_group_counts_by_spec_file = Hash.new(0) prepare_example_filtering end |
Instance Attribute Details
#wants_to_quit ⇒ void
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/rspec/core/world.rb', line 11 def wants_to_quit @wants_to_quit end |
Instance Method Details
#announce_exclusion_filter(announcements) ⇒ void
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.
216 217 218 219 220 |
# File 'lib/rspec/core/world.rb', line 216 def announce_exclusion_filter(announcements) return if exclusion_filter.empty? announcements << "exclude #{exclusion_filter.description}" end |
#announce_filters ⇒ void
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.
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/rspec/core/world.rb', line 163 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 if filter_manager.empty? ("No examples found.") elsif exclusion_filter.empty? || inclusion_filter.empty? () end end |
#announce_inclusion_filter(announcements) ⇒ void
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.
207 208 209 210 211 |
# File 'lib/rspec/core/world.rb', line 207 def announce_inclusion_filter(announcements) return if inclusion_filter.empty? announcements << "include #{inclusion_filter.description}" end |
#example_count(groups = example_groups) ⇒ void
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.
101 102 103 104 |
# File 'lib/rspec/core/world.rb', line 101 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_groups ⇒ void
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.
44 45 46 47 |
# File 'lib/rspec/core/world.rb', line 44 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
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.
132 133 134 135 136 137 138 |
# File 'lib/rspec/core/world.rb', line 132 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 ⇒ void
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.
35 36 37 38 39 |
# File 'lib/rspec/core/world.rb', line 35 def prepare_example_filtering @filtered_examples = Hash.new do |hash, group| hash[group] = filter_manager.prune(group.examples) end end |
#record(example_group) ⇒ void
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.
73 74 75 76 |
# File 'lib/rspec/core/world.rb', line 73 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 |
#reset ⇒ void
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.
52 53 54 55 56 57 58 |
# File 'lib/rspec/core/world.rb', line 52 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 |