@private
# File lib/rspec/core/shared_example_group.rb, line 111 def add(context, name, *metadata_args, &block) ensure_block_has_source_location(block) { CallerFilter.first_non_rspec_line } if valid_name?(name) warn_if_key_taken context, name, block shared_example_groups[context][name] = block else metadata_args.unshift name end unless metadata_args.empty? mod = Module.new (class << mod; self; end).__send__(:define_method, :included) do |host| host.class_exec(&block) end RSpec.configuration.include mod, *metadata_args end end
# File lib/rspec/core/shared_example_group.rb, line 130 def find(lookup_contexts, name) lookup_contexts.each do |context| found = shared_example_groups[context][name] return found if found end shared_example_groups[:main][name] end
# File lib/rspec/core/shared_example_group.rb, line 169 def ensure_block_has_source_location(block); end
# File lib/rspec/core/shared_example_group.rb, line 164 def formatted_location(block) block.source_location.join ":" end
# File lib/rspec/core/shared_example_group.rb, line 145 def valid_name?(candidate) case candidate when String, Symbol, Module then true else false end end
# File lib/rspec/core/shared_example_group.rb, line 152 def warn_if_key_taken(context, key, new_block) return unless existing_block = shared_example_groups[context][key] RSpec.warn_with " |WARNING: Shared example group '#{key}' has been previously defined at: | #{formatted_location existing_block} |...and you are now defining it at: | #{formatted_location new_block} |The new definition will overwrite the original one. ".gsub(/^ +\|/, ''), :call_site => nil end