How to run a single RSpec test?

后端 未结 17 790

I have the following file:

/spec/controllers/groups_controller_spec.rb

What command in terminal do I use to run just that spec and in what

17条回答
  •  一生所求
    2020-12-04 05:06

    My preferred method for running specific tests is slightly different - I added the lines

      RSpec.configure do |config|
        config.filter_run :focus => true
        config.run_all_when_everything_filtered = true
      end
    

    To my spec_helper file.

    Now, whenever I want to run one specific test (or context, or spec), I can simply add the tag "focus" to it, and run my test as normal - only the focused test(s) will run. If I remove all the focus tags, the run_all_when_everything_filtered kicks in and runs all the tests as normal.

    It's not quite as quick and easy as the command line options - it does require you to edit the file for the test you want to run. But it gives you a lot more control, I feel.

提交回复
热议问题