How to run a single RSpec test?

后端 未结 17 822

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:20

    @apneadiving answer is a neat way of solving this. However, now we have a new method in Rspec 3.3. We can simply run rspec spec/unit/baseball_spec.rb[#context:#it] instead of using a line number. Taken from here:

    RSpec 3.3 introduces a new way to identify examples[...]

    For example, this command:

    $ rspec spec/unit/baseball_spec.rb[1:2,1:4] …would run the 2nd and 4th example or group defined under the 1st top-level group defined in spec/unit/baseball_spec.rb.

    So instead of doing rspec spec/unit/baseball_spec.rb:42 where it (test in line 42) is the first test, we can simply do rspec spec/unit/baseball_spec.rb[1:1] or rspec spec/unit/baseball_spec.rb[1:1:1] depending on how nested the test case is.

提交回复
热议问题