Created
December 9, 2015 15:59
-
-
Save danbernier/cac8d7748d17bc2f4fb3 to your computer and use it in GitHub Desktop.
RSpec: Fail any spec typed with a String, not a Symbol
This file contains 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
=begin | |
It's easy to mistakenly say: | |
describe 'my feature', type: 'feature' do | |
... | |
end | |
...when you really mean: | |
describe 'my feature', type: :feature do | |
end | |
The problems start when parts of the system - your code, or gem code - | |
starts making choices based on that value. If they silently expect it | |
to be a Symbol, it'll be a hard problem to troubleshoot. | |
So let's fail noisily and save ourselves the trouble. | |
=end | |
RSpec.configure do |config| | |
config.before(:each) do |example| | |
example_type = example.metadata[:type] | |
if example_type && !example_type.is_a?(Symbol) | |
raise "Spec at #{example.location} has a type that is NOT a Symbol: #{example_type.inspect}" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment