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

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

#container_stackObject



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

#described_classObject



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("      |The semantics of `described_class` in a nested `describe <SomeClass>`\n      |example group are changing in RSpec 3. In RSpec 2.x, `described_class`\n      |would return the outermost described class (\#{value_for_rspec_2.inspect}).\n      |In RSpec 3, it will return the innermost described class (\#{value_for_rspec_3.inspect}).\n      |In general, we recommend not describing multiple classes or objects in a\n      |nested manner as it creates confusion.\n      |\n      |To make your code compatible with RSpec 3, change from `described_class` to a reference\n      |to `\#{value_for_rspec_3.inspect}`, or change the arg of the inner `describe` to a string.\n      |(Called from \#{CallerFilter.first_non_rspec_line})\n    EOS\n  end\n\n  value_for_rspec_2\nend\n".gsub(/^\s+\|/, ''))

#described_class_for_rspec_2Object



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

#described_class_for_rspec_3Object



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

#first_description_argObject



195
196
197
# File 'lib/rspec/core/metadata.rb', line 195

def first_description_arg
  self[:description_args].first
end

#full_descriptionObject



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

#warn_about_first_description_arg_behavioral_change_in_rspec_3Object



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