Class: RSpec::Core::SharedExampleGroup::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/core/shared_example_group.rb

Instance Method Summary collapse

Instance Method Details

#add(context, name, *metadata_args, &block) ⇒ Object



148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/rspec/core/shared_example_group.rb', line 148

def add(context, name, *, &block)
  unless block
    RSpec.warning "Shared example group #{name} was defined without a "\
                  "block and will have no effect. Please define a "\
                  "block or remove the definition."
  end

  if RSpec.configuration. == :trigger_inclusion
    return legacy_add(context, name, *, &block)
  end

  unless valid_name?(name)
    raise ArgumentError, "Shared example group names can only be a string, " \
                         "symbol or module but got: #{name.inspect}"
  end

  ensure_block_has_source_location(block) { CallerFilter.first_non_rspec_line }
  warn_if_key_taken context, name, block

   = Metadata.build_hash_from()
  shared_module = SharedExampleGroupModule.new(name, block, )
  shared_example_groups[context][name] = shared_module
end

#find(lookup_contexts, name) ⇒ Object



172
173
174
175
176
177
178
179
# File 'lib/rspec/core/shared_example_group.rb', line 172

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