Skip to content

Instantly share code, notes, and snippets.

@danbernier
Created December 9, 2015 15:59
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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