Class: RSpec::Core::World

Inherits:
Object
  • Object
show all
Includes:
Hooks
Defined in:
lib/rspec/core/world.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Hooks

#after, #around, #before, #hooks, #run_hook, #run_hook!, #run_hook_filtered

Methods included from MetadataHashBuilder::Common

#build_metadata_hash_from

Constructor Details

#initialize(configuration = RSpec.configuration) ⇒ World

Returns a new instance of World.



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rspec/core/world.rb', line 10

def initialize(configuration=RSpec.configuration)
  @configuration = configuration
  @example_groups = [].extend(Extensions::Ordered)
  @filtered_examples = Hash.new { |hash,group|
    hash[group] = begin
      examples = group.examples.dup
      examples = filter_manager.prune(examples)
      examples.uniq
      examples.extend(Extensions::Ordered)
    end
  }
end

Instance Attribute Details

#example_groupsObject (readonly)

Returns the value of attribute example_groups.



7
8
9
# File 'lib/rspec/core/world.rb', line 7

def example_groups
  @example_groups
end

#filtered_examplesObject (readonly)

Returns the value of attribute filtered_examples.



7
8
9
# File 'lib/rspec/core/world.rb', line 7

def filtered_examples
  @filtered_examples
end

#wants_to_quitObject

Returns the value of attribute wants_to_quit.



7
8
9
# File 'lib/rspec/core/world.rb', line 7

def wants_to_quit
  @wants_to_quit
end

Instance Method Details

#announce_exclusion_filter(announcements) ⇒ Object



112
113
114
115
116
# File 'lib/rspec/core/world.rb', line 112

def announce_exclusion_filter(announcements)
  unless exclusion_filter.empty_without_conditional_filters?
    announcements << "exclude #{exclusion_filter.description}"
  end
end

#announce_filtersObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/rspec/core/world.rb', line 66

def announce_filters
  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

  if example_count.zero?
    example_groups.clear
    if filter_manager.empty?
      reporter.message("No examples found.")
    elsif exclusion_filter.empty_without_conditional_filters?
      message = everything_filtered_message
      if @configuration.run_all_when_everything_filtered?
        message << "; ignoring #{inclusion_filter.description}"
      end
      reporter.message(message)
    elsif inclusion_filter.empty?
      reporter.message(everything_filtered_message)
    end
  end
end

#announce_inclusion_filter(announcements) ⇒ Object



106
107
108
109
110
# File 'lib/rspec/core/world.rb', line 106

def announce_inclusion_filter(announcements)
  unless inclusion_filter.empty?
    announcements << "include #{inclusion_filter.description}"
  end
end

#configure_group(group) ⇒ Object



44
45
46
# File 'lib/rspec/core/world.rb', line 44

def configure_group(group)
  @configuration.configure_group(group)
end

#everything_filtered_messageObject



102
103
104
# File 'lib/rspec/core/world.rb', line 102

def everything_filtered_message
  "\nAll examples were filtered out"
end

#example_countObject



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

def example_count
  example_groups.collect {|g| g.descendants}.flatten.inject(0) { |sum, g| sum += g.filtered_examples.size }
end

#exclusion_filterObject



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

def exclusion_filter
  @configuration.exclusion_filter
end

#filter_managerObject



27
28
29
# File 'lib/rspec/core/world.rb', line 27

def filter_manager
  @configuration.filter_manager
end

#find_hook(hook, scope, group, example = nil) ⇒ Object



118
119
120
# File 'lib/rspec/core/world.rb', line 118

def find_hook(hook, scope, group, example = nil)
  @configuration.find_hook(hook, scope, group, example)
end

#inclusion_filterObject



36
37
38
# File 'lib/rspec/core/world.rb', line 36

def inclusion_filter
  @configuration.inclusion_filter
end

#preceding_declaration_line(filter_line) ⇒ Object



56
57
58
59
60
# File 'lib/rspec/core/world.rb', line 56

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) ⇒ Object



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

def register(example_group)
  example_groups << example_group
  example_group
end

#reporterObject



62
63
64
# File 'lib/rspec/core/world.rb', line 62

def reporter
  @configuration.reporter
end

#resetObject



23
24
25
# File 'lib/rspec/core/world.rb', line 23

def reset
  example_groups.clear
end

#shared_example_groupsObject



48
49
50
# File 'lib/rspec/core/world.rb', line 48

def shared_example_groups
  @shared_example_groups ||= {}
end