Reading Metadata

Take one more peek at the it block you wrote at the start of the chapter:

 it​ ​'is used by RSpec for metadata'​ ​do​ |example|
  pp example.metadata
 end

As this snippet shows, RSpec hands your block an example argument, from which you can read the metadata. RSpec passes the same kind of block argument in hooks marked as having :example scope:

 RSpec.configure ​do​ |config|
  config.around(​:example​) ​do​ |example|
  pp example.metadata
 end
 end

…and in let declarations:

 RSpec.describe ​'Music storage'​ ​do
 let​(​:s3_client​) ​do​ |example|
  S3Client.for(example.metadata[​:s3_adapter​])
 end
 
 it

Get Effective Testing with RSpec 3 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.