Question

I have an rspec scenario that looks like:

    scenario "some description of the scenario", :js => true, :slow => true, :wip => true do
      sleep 60
      ...

But I would like to call sleep conditionally based on what the scenario is tagged with, something like:

    scenario "some description of the scenario", :js => true, :slow => true, :wip => true do
      sleep 60 if tags[:slow] && !tags[:wip]
      ...

I'd appreciate any help.

Was it helpful?

Solution

Since rspec doesn't have a scenario method, I'm guessing that you're using capybara or steak and that it's really just an alias for it. In that case, rspec internally refers to this block of code as an "example," and you can access the meta data like this:

sleep 60 if example.metadata[:slow]  # sleep if example is tagged with :slow => true

You can also put the metadata on the example group, the describe block that encloses the various examples. See this: http://relishapp.com/rspec/rspec-core/v/2-6/dir/metadata/user-defined-metadata

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top