Today I Learned

hashrocket A Hashrocket project

Filter RSpec Tests by Type

Sometimes I just want to run model rspec tests, or run everything except for those slow feature tests in my rails app. Today I learned you can do that with the --tag option.

To only run model specs:

$ bundle exec rspec --tag type:model

To exclude feature specs (using the ~):

$ bundle exec rspec --tag ~type:feature

What's convenient is rspec-rails will infer the type of the spec based on it's location in the spec/ directory, so even if you don't explicitly tag your tests with type: :model these filters will still work.

rspec --tag option docs

See More #rails TILs
Looking for help? Hashrocket has been an industry leader in Ruby on Rails since 2008. Rails is a core skill for each developer at Hashrocket, and we'd love to take a look at your project. Contact us and find out how we can help you.