Class: Spec::Example::ExampleGroupProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/spec/example/example_group_proxy.rb

Overview

Lightweight proxy for an example group. This is the object that is passed to Spec::Runner::Formatter::BaseFormatter#example_group_started

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(example_group) ⇒ ExampleGroupProxy

:nodoc:



7
8
9
10
11
12
13
14
15
16
# File 'lib/spec/example/example_group_proxy.rb', line 7

def initialize(example_group) # :nodoc:
  @description         = example_group.description
  @nested_descriptions = example_group.nested_descriptions
  @examples            = example_group.example_proxies
  @location            = example_group.location
  @backtrace           = example_group.location # deprecated - see the backtrace method below
  @options             = example_group.options.dup
  @options.delete(:location)
  @options.delete(:scope)
end

Instance Attribute Details

#descriptionObject (readonly)

This is the description passed to the describe() method or any of its aliases



25
26
27
# File 'lib/spec/example/example_group_proxy.rb', line 25

def description
  @description
end

#examplesObject (readonly)

A collection of ExampleGroupProxy objects, one for each example declared in this group.



33
34
35
# File 'lib/spec/example/example_group_proxy.rb', line 33

def examples
  @examples
end

#locationObject (readonly)

The file and line number at which the proxied example group was declared. This is extracted from caller, and is therefore formatted as an individual line in a backtrace.



38
39
40
# File 'lib/spec/example/example_group_proxy.rb', line 38

def location
  @location
end

#nested_descriptionsObject (readonly)

Used by Spec::Runner::Formatter::NestedTextFormatter to access the description of each example group in a nested group separately.



29
30
31
# File 'lib/spec/example/example_group_proxy.rb', line 29

def nested_descriptions
  @nested_descriptions
end

#optionsObject (readonly)

Optional hash passed to the example group declaration. Note that RSpec uses this hash internally and reserves the keys :location and :scope for its own use (and removes them from this hash)



21
22
23
# File 'lib/spec/example/example_group_proxy.rb', line 21

def options
  @options
end

Instance Method Details

#==(other) ⇒ Object

:nodoc:



56
57
58
# File 'lib/spec/example/example_group_proxy.rb', line 56

def ==(other) # :nodoc:
  other.description == description
end

#backtraceObject

Deprecated - use location() instead



41
42
43
44
# File 'lib/spec/example/example_group_proxy.rb', line 41

def backtrace
  Spec::deprecate("ExampleGroupProxy#backtrace","ExampleGroupProxy#location")
  @backtrace
end

#filtered_description(regexp) ⇒ Object

Deprecated - just use gsub on the description instead.



47
48
49
50
51
52
53
54
# File 'lib/spec/example/example_group_proxy.rb', line 47

def filtered_description(regexp)
  Spec::deprecate("ExampleGroupProxy#filtered_description","gsub (or similar) to modify ExampleGroupProxy#description")
  ExampleGroupMethods.build_description_from(
    *nested_descriptions.collect do |description|
      description =~ regexp ? description.gsub($1, "") : description
    end
  )
end