Search code examples
rspecrspec3

What does information in square brackets after a file path mean in RSpec?


The documentation for RSpec mentions the --bisect option , which when run provides a minimal reproduction, such as

rspec ./spec/calculator_10_spec.rb[1:1] ./spec/calculator_1_spec.rb[1:1] --seed 1234

What does the [1:1] bit mean?


Solution

  • From rspec --help:

    **** Filtering/tags ****

    In addition to the following options for selecting specific files, groups, or examples, you can select individual examples by appending the line number(s) to the filename:

    rspec path/to/a_spec.rb:37:87
    

    You can also pass example ids enclosed in square brackets:

    rspec path/to/a_spec.rb[1:5,1:6]
    # run the 5th and 6th examples/groups defined in the 1st group
    

    It's mentioned in the release notes of RSpec 3.3:

    RSpec 3.3 introduces a new way to identify examples and example groups: unique IDs. The IDs are scoped to a particular file and are based on the index of the example or group. 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.