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, #append_after, #around, #before, #prepend_before

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
22
# File 'lib/rspec/core/world.rb', line 10

def initialize(configuration=RSpec.configuration)
  @configuration = configuration
  @example_groups = [].extend(Extensions::Ordered::ExampleGroups)
  @shared_example_groups = {}
  @filtered_examples = Hash.new { |hash,group|
    hash[group] = begin
      examples = group.examples.dup
      examples = filter_manager.prune(examples)
      examples.uniq
      examples.extend(Extensions::Ordered::Examples)
    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

#shared_example_groupsObject (readonly)

Returns the value of attribute shared_example_groups.



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

def shared_example_groups
  @shared_example_groups
end

#wants_to_quitObject

Returns the value of attribute wants_to_quit.



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

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



46
47
48
# File 'lib/rspec/core/world.rb', line 46

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



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

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

#exclusion_filterObject



42
43
44
# File 'lib/rspec/core/world.rb', line 42

def exclusion_filter
  @configuration.exclusion_filter
end

#filter_managerObject



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

def filter_manager
  @configuration.filter_manager
end

#inclusion_filterObject



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

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



33
34
35
36
# File 'lib/rspec/core/world.rb', line 33

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



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

def reset
  example_groups.clear
  shared_example_groups.clear
end