Skip to content

Instantly share code, notes, and snippets.

@dcadenas
Created June 21, 2012 07:07
Show Gist options
  • Select an option

  • Save dcadenas/2964334 to your computer and use it in GitHub Desktop.

Select an option

Save dcadenas/2964334 to your computer and use it in GitHub Desktop.
Doubt about RSpec metadata
#Which is the best alternative? A is clearer but is it slower? is there a better way?
#A: The block will be run in all examples, do_something_with will only be run when my_metadata defined
RSpec.configure do |config|
config.before(:each) do |example|
do_something_with(example.metadata[:my_metadata]) if example.metadata.has_key?(:my_metadata)
example.run
end
end
#B: The block will be run only when my_metadata is defined
RSpec.configure do |config|
config.before(:each, :my_metadata => ->(value){ true }) do |example|
do_something_with(example.metadata[:my_metadata])
example.run
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment