# File lib/rspec/core/shared_example_group/collection.rb, line 6 def initialize(sources, examples) @sources, @examples = sources, examples end
# File lib/rspec/core/shared_example_group/collection.rb, line 10 def [](key) fetch_examples(key) || warn_deprecation_and_fetch_anyway(key) end
# File lib/rspec/core/shared_example_group/collection.rb, line 24 def fetch_anyway(key) @examples.values.inject({}, &:merge)[key] end
# File lib/rspec/core/shared_example_group/collection.rb, line 16 def fetch_examples(key) @examples[source_for key][key] end
# File lib/rspec/core/shared_example_group/collection.rb, line 20 def source_for(key) @sources.reverse.find { |source| @examples[source].has_key? key } end
# File lib/rspec/core/shared_example_group/collection.rb, line 28 def warn_deprecation_and_fetch_anyway(key) if (example = fetch_anyway key) backtrace_line = caller.find { |line| !line.include?('lib/rspec/core') } RSpec.warn_deprecation " Accessing shared_examples defined across contexts is deprecated. Please declare shared_examples within a shared context, or at the top level. This message was generated at: #{backtrace_line} ".gsub(/^ /, '') example end end