Is it possible to make metadata not inherited from parent example group to the child?

59 views
Skip to first unread message

Dmitriy Konovalov

unread,
Mar 31, 2014, 3:41:06 AM3/31/14
to rs...@googlegroups.com
Hi everybody,

I want to create an rspec formatter that will out the xml for the mind map building. I'm QA and want to create checklists based on test scenarios  created in spec files. And it works now, but I'd like to use a lot of Mind map features like tags, icons, links, attached descriptions for each node. And I use metadata for this point. 
The trouble is: when I assign some metadata tags to example group all nested ones are inherit these tags, so all nested nodes in mind map file will have all these info until be override.

So the question is:

Is there some possibility to temporarily turn off the tags-inheriting feature? otherwise I need to override all tags each time for each node to 'nil' (now it works for me fine, but makes the code awful to read):


describe 'Sidebar', link: nil, user_story: nil do
  describe 'Album info widget', link: 'https://www.google.com', user_story: true do
    it 'something', link: nil, user_story: nil
  end
  describe 'Photo Albums widget', link: 'https://www.google.com', user_story: true do
    it 'something', link: nil, user_story: nil
  end
end

Myron Marston

unread,
Mar 31, 2014, 11:35:10 AM3/31/14
to rs...@googlegroups.com
There's not a built-in way to do this. The metadata inheritance is intentional and is very useful.

You can do something like this:

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

HTH,
Myron
Reply all
Reply to author
Forward
0 new messages