Class: RSpec::Core::World Private

Inherits:
Object
  • Object
show all
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

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



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rspec/core/world.rb', line 13

def initialize(configuration=RSpec.configuration)
  @configuration = configuration
  @example_groups = []
  @example_group_counts_by_spec_file = Hash.new(0)
  @filtered_examples = Hash.new do |hash, group|
    hash[group] = begin
      examples = group.examples.dup
      examples = filter_manager.prune(examples)
      examples.uniq!
      examples
    end
  end
end

Instance Attribute Details

#wants_to_quitvoid

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.



156
157
158
159
160
# File 'lib/rspec/core/world.rb', line 156

def announce_exclusion_filter(announcements)
  return if exclusion_filter.empty?

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

#announce_filtersvoid

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.



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/rspec/core/world.rb', line 108

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
      reporter.message("Run options: #{filter_announcements[0]}")
    else
      reporter.message("Run options:\n  #{filter_announcements.join("\n  ")}")
    end
  end

  if @configuration.run_all_when_everything_filtered? && example_count.zero?
    reporter.message("#{everything_filtered_message}; ignoring #{inclusion_filter.description}")
    filtered_examples.clear
    inclusion_filter.clear
  end

  return unless example_count.zero?

  example_groups.clear
  if filter_manager.empty?
    reporter.message("No examples found.")
  elsif exclusion_filter.empty? || inclusion_filter.empty?
    reporter.message(everything_filtered_message)
  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.



147
148
149
150
151
# File 'lib/rspec/core/world.rb', line 147

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.



80
81
82
83
# File 'lib/rspec/core/world.rb', line 80

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

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.



30
31
32
33
# File 'lib/rspec/core/world.rb', line 30

def ordered_example_groups
  ordering_strategy = @configuration.ordering_registry.fetch(:global)
  ordering_strategy.order(@example_groups)
end

#preceding_declaration_line(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.



94
95
96
97
98
# File 'lib/rspec/core/world.rb', line 94

def preceding_declaration_line(filter_line)
  declaration_line_numbers.sort.inject(nil) do |highest_prior_declaration_line, line|
    line <= filter_line ? line : highest_prior_declaration_line
  end
end

#register(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.

Register an example group.



51
52
53
54
55
# File 'lib/rspec/core/world.rb', line 51

def register(example_group)
  example_groups << example_group
  @example_group_counts_by_spec_file[example_group.[:file_path]] += 1
  example_group
end

#resetvoid

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.



38
39
40
41
# File 'lib/rspec/core/world.rb', line 38

def reset
  example_groups.clear
  @shared_example_group_registry = nil
end