There's not a built-in way to do this. The metadata inheritance is intentional and is very useful.
module SetMetadataKeysToNil
def describe(description, user_metadata={})
user_metadata.merge!(metadata_hash_with_nil_values)
super
end
def it(description, user_metadata={})
user_metadata.merge!(metadata_hash_with_nil_values)
super
end
private
def metadata_hash_with_nil_values
user_keys = metadata.keys - RSpec::Core::Metadata::RESERVED_KEYS
user_keys -= [:parent_example_group, :example_group]
user_keys.each_with_object({}) do |key, hash|
hash[key] = nil
end
end
end
RSpec.configure do |rspec|
rspec.extend SetMetadataKeysToNil
end