Created
June 21, 2012 07:07
-
-
Save dcadenas/2964334 to your computer and use it in GitHub Desktop.
Doubt about RSpec metadata
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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