Skip to content

Instantly share code, notes, and snippets.

@danbernier
Created December 9, 2015 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danbernier/cac8d7748d17bc2f4fb3 to your computer and use it in GitHub Desktop.
Save danbernier/cac8d7748d17bc2f4fb3 to your computer and use it in GitHub Desktop.
RSpec: Fail any spec typed with a String, not a Symbol
=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