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

Defining Metadata

RSpec’s metadata solves a very specific problem: where do I keep information about the context my specs are running in? By context, we mean things like:

  • Example configuration (for example, marked as skipped or pending)
  • Source code locations
  • Status of the previous run
  • How one example runs differently than others (for example, needing a web browser or a database)

Without some way of attaching data to examples, you (and the RSpec maintainers!) would be stuck juggling global variables and writing a bunch of bookkeeping code.

RSpec’s solution to this problem couldn’t be simpler: a plain Ruby hash. Every example and example group gets its own such hash, known as the metadata hash. RSpec populates this hash with any metadata you’ve explicitly ...

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