Rspec describe, context and it supports metadata in the form of a hash. Syntax as follow:
1234567891011121314
RSpec.describe"some description",:foo=>1,:bardocontext"when some condition",:value=>truedoit"does something",:hihi,:day=>10do|example|expect(exapmle.metadata[:foo]).toeq(1)expect(example.metadata[:value]).tobetrueexpect(example.metadata[:hihi]).tobetrueexpect(example.metadata[:day]).toeq(10)endendend
There are 2 ways that I use metadata in RSpec.
To include shared_examples / shared_context
RSpec includes shared_context and shared_examples with same metadata
RSpec.describe"use metadata as var",:num_elements=>7dolet(:elements)do|example|(1..example.metadata[:num_elements]).map{|n|"element#{n}"}endit"prints elements"doppelementsendend