class RSpec::Core::SharedExampleGroup::Registry
@private
Public Instance Methods
add(context, name, *metadata_args, &block)
click to toggle source
# File lib/rspec/core/shared_example_group.rb, line 141 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 return if metadata_args.empty? RSpec.configuration.include SharedExampleGroupModule.new(name, block), *metadata_args end
find(lookup_contexts, name)
click to toggle source
# File lib/rspec/core/shared_example_group.rb, line 155 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
Private Instance Methods
ensure_block_has_source_location(_block)
click to toggle source
# File lib/rspec/core/shared_example_group.rb, line 196 def ensure_block_has_source_location(_block); end
formatted_location(block)
click to toggle source
# File lib/rspec/core/shared_example_group.rb, line 191 def formatted_location(block) block.source_location.join ":" end
valid_name?(candidate)
click to toggle source
# File lib/rspec/core/shared_example_group.rb, line 170 def valid_name?(candidate) case candidate when String, Symbol, Module then true else false end end
warn_if_key_taken(context, key, new_block)
click to toggle source
# File lib/rspec/core/shared_example_group.rb, line 177 def warn_if_key_taken(context, key, new_block) existing_block = shared_example_groups[context][key] return unless existing_block 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