class RSpec::Core::SharedExampleGroup::Collection

Public Class Methods

new(sources, examples) click to toggle source
# File lib/rspec/core/shared_example_group/collection.rb, line 6
def initialize(sources, examples)
  @sources, @examples = sources, examples
end

Public Instance Methods

[](key) click to toggle source
# File lib/rspec/core/shared_example_group/collection.rb, line 10
def [](key)
  fetch_examples(key) || warn_deprecation_and_fetch_anyway(key)
end

Private Instance Methods

fetch_anyway(key) click to toggle source
# File lib/rspec/core/shared_example_group/collection.rb, line 24
def fetch_anyway(key)
  @examples.values.inject({}, &:merge)[key]
end
fetch_examples(key) click to toggle source
# File lib/rspec/core/shared_example_group/collection.rb, line 16
def fetch_examples(key)
  @examples[source_for key][key]
end
source_for(key) click to toggle source
# 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
warn_deprecation_and_fetch_anyway(key) click to toggle source
# 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