O'Reilly logo

Effective Testing with RSpec 3 by Myron Marston, Ian Dees

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required