Can I set rspec --format documentation as the default?
Asked Answered
H

3

17

Per the Rspec documentation, by default when you run rspec you get the progress formatter (looks like this: ".....").

There is another formatting option rspec --format documentation that goes through each test one by one. My question: how can I enable --format documentation by default without having to type it in the command line every time?

Halfbeak answered 13/10, 2016 at 14:1 Comment(0)
S
43

Option 1

Add it to .rspec file (or create one in the project's root directory) - options added to it will be applied to every test run within current project:

# .rspec
--color
--format documentation

Option 2

Add it to RSpec.configure block:

RSpec.configure do |config|
  config.formatter = :documentation
end

Option 3

Specify rspec's options globally by adding them to ~/.rspec.

Squall answered 13/10, 2016 at 14:3 Comment(3)
You can also add this to your global config (e.g. ~/.rspec on Mac)Bisayas
Andrey, I was trying to add that line to the .rspec file but it was giving me a syntax error. I'm guessing I was placing the code in the wrong place. The block of code below found me success. Edit: Cool, going to accept your answer. Thanks!Halfbeak
Thanks, for the help!Halfbeak
H
8
RSpec.configure do |config|
  config.color = true
  config.formatter = :documentation
  config.order = 'default'
end
Halfbeak answered 13/10, 2016 at 14:6 Comment(0)
G
5

You can create your own personal RSpec settings by creating a ~/.rspec file:

--color
--format documentation

The project .rspec file should only contain the minimum settings required to run the spec suite to avoid developer wars.

Gentilis answered 13/10, 2016 at 14:9 Comment(1)
This is a somewhat opinionated answer but I would NOT use RSpec.configure to set the format either as this really is a matter of preference.Gentilis

© 2022 - 2024 — McMap. All rights reserved.