How to run only one test in rspec
Mostly while developing its extremely convenient to be able to run just one particular describe block or it block.
Rspec lets you do that using a combination of
focus: true as well as adding some configuration.
Open your spec_helper.rb file and add the following line to your configuration
Once thats done, you can simply use the focus: true parameter in your tests as follows
RSpec.configure do |config| .....some stuff.... config.filter_run :focus config.run_all_when_everything_filtered = true .....more of some stuff.... end
Now when you run your tests using
# To run one describe block describe MyCustomClass, focus: true do ... end # To run just one it block it 'tests something meaningful', focus: true do # test something here end
rails spec, only the one that has focus: true will be executed.
Pro Tip: Just make sure to remove the
focus: truebefore merging your changes upstream to maintain the sanity and friendliness of your teammates.