Module: RSpec::Core::Metadata::GroupMetadataHash

Includes:
MetadataHash
Defined in:
lib/rspec/core/metadata.rb

Overview

Mixed in to Metadata for an ExampleGroup (extends MetadataHash) to support lazy evaluation of some values.

Instance Method Summary (collapse)

Instance Method Details

- (Object) container_stack

203
204
205
206
207
208
209
210
211
212
# File 'lib/rspec/core/metadata.rb', line 203
def container_stack
  @container_stack ||= begin
                         groups = [group = self]
                         while group.has_key?(:example_group)
                           groups << group[:example_group]
                           group = group[:example_group]
                         end
                         groups
                       end
end

- (Object) described_class

132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/rspec/core/metadata.rb', line 132
def described_class
  warn_about_first_description_arg_behavioral_change_in_rspec_3
  value_for_rspec_2 = described_class_for_rspec_2
  value_for_rspec_3 = described_class_for_rspec_3
  if value_for_rspec_2 != value_for_rspec_3
    RSpec.warn_deprecation(<<-EOS.gsub(/^\s+\|/, ''))
      |The semantics of `described_class` in a nested `describe <SomeClass>`
      |example group are changing in RSpec 3. In RSpec 2.x, `described_class`
      |would return the outermost described class (#{value_for_rspec_2.inspect}).
      |In RSpec 3, it will return the innermost described class (#{value_for_rspec_3.inspect}).
      |In general, we recommend not describing multiple classes or objects in a
      |nested manner as it creates confusion.
      |
      |To make your code compatible with RSpec 3, change from `described_class` to a reference
      |to `#{value_for_rspec_3.inspect}`, or change the arg of the inner `describe` to a string.
      |(Called from #{CallerFilter.first_non_rspec_line})
    EOS
  end
  value_for_rspec_2
end

- (Object) described_class_for_rspec_2

156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/rspec/core/metadata.rb', line 156
def described_class_for_rspec_2
  container_stack.each do |g|
    [:described_class, :describes].each do |key|
      if g.has_key?(key)
        value = g[key]
        return value unless value.nil?
      end
    end
  end
  container_stack.reverse.each do |g|
    candidate = g[:description_args].first
    return candidate unless String === candidate || Symbol === candidate
  end
  nil
end

- (Object) described_class_for_rspec_3

174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/rspec/core/metadata.rb', line 174
def described_class_for_rspec_3
  container_stack.each do |g|
    [:described_class, :describes].each do |key|
      if g.has_key?(key)
        value = g[key]
        return value unless value.nil?
      end
    end
    candidate = g[:description_args].first
    return candidate unless NilClass === candidate || String === candidate || Symbol === candidate
  end
  nil
end

- (Object) first_description_arg

195
196
197
# File 'lib/rspec/core/metadata.rb', line 195
def first_description_arg
  self[:description_args].first
end

- (Object) full_description

199
200
201
# File 'lib/rspec/core/metadata.rb', line 199
def full_description
  build_description_from(*container_stack.reverse.map {|a| a[:description_args]}.flatten)
end

- (Object) warn_about_first_description_arg_behavioral_change_in_rspec_3

190
191
192
193
# File 'lib/rspec/core/metadata.rb', line 190
def warn_about_first_description_arg_behavioral_change_in_rspec_3
  return unless behavior_change = self[:description_arg_behavior_changing_in_rspec_3]
  RSpec.warn_deprecation(behavior_change.warning)
end