Class: RSpec::Core::World

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

Constant Summary

Constant Summary

Constants included from Hooks

Hooks::HOOK_TYPES, Hooks::SCOPES

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods included from Hooks

#after, #append_after, #around, #before, #prepend_before

Constructor Details

- (World) initialize(configuration = RSpec.configuration)

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::ExampleGroups)
  @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

- (Object) example_groups (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

- (Object) filtered_examples (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

- (Object) wants_to_quit

Returns the value of attribute wantstoquit



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

def wants_to_quit
  @wants_to_quit
end

Instance Method Details

- (Object) announce_exclusion_filter(announcements)



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

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

- (Object) announce_filters



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

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.rules_empty?
      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

- (Object) announce_inclusion_filter(announcements)



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

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

- (Object) configure_group(group)



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

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

- (Object) everything_filtered_message



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

def everything_filtered_message
  "\nAll examples were filtered out"
end

- (Object) example_count



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

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

- (Object) exclusion_filter



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

def exclusion_filter
  @configuration.exclusion_filter
end

- (Object) filter_manager



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

def filter_manager
  @configuration.filter_manager
end

- (Object) inclusion_filter



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

def inclusion_filter
  @configuration.inclusion_filter
end

- (Object) preceding_declaration_line(filter_line)



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

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

- (Object) register(example_group)



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

def register(example_group)
  example_groups << example_group
  example_group
end

- (Object) reporter



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

def reporter
  @configuration.reporter
end

- (Object) reset



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

def reset
  example_groups.clear
  SharedExampleGroup.registry.clear
end