Method: RSpec::Core::Example#duplicate_with

Defined in:
lib/rspec/core/example.rb

#duplicate_with(metadata_overrides = {}) ⇒ Example

Duplicates the example and overrides metadata with the provided hash.

Parameters:

  • metadata_overrides (Hash) (defaults to: {})

    the hash to override the example metadata

Returns:

  • (Example)

    a duplicate of the example with modified metadata

[View source]

132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/rspec/core/example.rb', line 132

def duplicate_with(={})
   = .clone.merge()

  RSpec::Core::::RESERVED_KEYS.each do |reserved_key|
    .delete reserved_key
  end

  # don't clone the example group because the new example
  # must belong to the same example group (not a clone).
  #
  # block is nil in new_metadata so we have to get it from metadata.
  Example.new(example_group, description.clone,
              , [:block])
end