Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run multiple specific RSpec tests?

I've got a huge test suite (> 5000 tests) that take an hour to run. 400 are failing, and I have a list of the failing tests like this:

rspec ./spec/models/fullscreen_hidden_view_state_spec.rb:116 # FullscreenHiddenViewState showing a playlist on third element - slide has all the right links and properties
rspec ./spec/features/fullscreen/play_spec.rb:59 # View case in fullscreen presention mode Courtesy section when viewing the cases discussion via the cases hidden share token the Add To button should be hidden
rspec ./spec/features/cases/index_spec.rb:204 # finding a case Filtering by study modality Filtering by modality only shows cases with modality
rspec ./spec/models/playlist_spec.rb[1:2:2:2:1] # Playlist it should behave like an entity with privacy .by_privilege (Playlist examples) for annonymous contains public playlists
rspec ./spec/models/playlist_spec.rb[1:2:2:2:2] # Playlist it should behave like an entity with privacy .by_privilege (Playlist examples) for annonymous works
rspec ./spec/models/playlist_spec.rb[1:2:2:3:1] # Playlist it should behave like an entity with privacy .by_privilege (Playlist examples) for privileged user contains all playlists
rspec ./spec/models/playlist_spec.rb[1:2:2:1:1] # Playlist it should behave like an entity with privacy .by_privilege (Playlist examples) for unprivileged users contains public and the users unlisted playlists
rspec ./spec/models/playlist_spec.rb[1:2:2:1:2] # Playlist it should behave like an entity with privacy .by_privilege (Playlist examples) for unprivileged users works
rspec ./spec/models/user_spec.rb:1004 # User quotas limited_unlisted_cases? user with manage cases privilege should equal false
rspec ./spec/models/user_spec.rb:813 # User quotas #can_add_draft_case? when non-deleted draft case count above the limit for privileged user should equal true
rspec ./spec/models/user_spec.rb:920 # User quotas #allowed_draft_cases user with manage cases privilege should eq -1
rspec ./spec/models/user_spec.rb:962 # User quotas allowed_unlisted_playlists user with manage cases privilege should eq -1
rspec ./spec/models/user_spec.rb:861 # User quotas allowed_unlisted_cases user with manage cases privilege should eq -1

I know I can run each line to run the specific tests, but is there an easy way to run all of them?

like image 384
Mirror318 Avatar asked Feb 14 '18 01:02

Mirror318


People also ask

How do I run a specific test in RSpec?

Running tests by their file or directory names is the most familiar way to run tests with RSpec. RSpec can take a file name or directory name and run the file or the contents of the directory. So you can do: rspec spec/jobs to run the tests found in the jobs directory.

What does bundle exec RSpec do?

bundle exec changes your $PATH , or %PATH% in case of Windows. As a result, by using bundle exec rspec you're calling the RSpec's version which is specified in your Gemfile . rspec ran without Bundler executes the one in your $PATH .


3 Answers

You can use the following syntax to run your specs for multiple files:

rspec path/to/first/file path/to/second/file
like image 143
Vinicius Brasil Avatar answered Oct 09 '22 13:10

Vinicius Brasil


FYI, might not answer this question exactly but it's expected to help other visitors with similar queries.

Multiple files with pattern

If you wish to run spec from some specific folders then you might use

rspec --pattern=./spec/features/**/*_spec.rb

If you want to exclude some files

rspec --pattern=./spec/features/**/*_spec.rb --exclude-pattern="./spec/features/{folder1,folder2}/**/*_spec.rb"

see this for more info https://relishapp.com/rspec/rspec-core/v/3-8/docs/command-line/pattern-option

Multiple files starting with some char or phrase

rspec --pattern="./spec/features/[t]*_spec.rb"

Here, it will run all specs with filename starting with t.

rspec --pattern="./spec/features/[tran|u]*_spec.rb"

Here, it will run all specs with filename starting with tran or u.

to learn more, visit How to run multiple spec files in RSpec using single command in terminal?

like image 40
illusionist Avatar answered Oct 09 '22 15:10

illusionist


You could use the rspec --only-failures option which will only load and run spec files with failures.

Update: As @Grzegorz mentioned in the comments, you have to run all of them first and this command will give the failures from the last run.

like image 5
amrrbakry Avatar answered Oct 09 '22 13:10

amrrbakry