Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I set rspec --format documentation as the default?

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?

like image 543
Joel Hoelting Avatar asked Oct 13 '16 14:10

Joel Hoelting


People also ask

How do I run an Rspec on a specific file?

To run a single Rspec test file, you can do: rspec spec/models/your_spec. rb to run the tests in the your_spec. rb file.

What is Rails Rspec?

RSpec is a testing tool for Ruby, created for behavior-driven development (BDD). It is the most frequently used testing library for Ruby in production applications. Even though it has a very rich and powerful DSL (domain-specific language), at its core it is a simple tool which you can start using rather quickly.


3 Answers

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.

like image 177
Andrey Deineko Avatar answered Oct 21 '22 22:10

Andrey Deineko


RSpec.configure do |config|
  config.color = true
  config.formatter = :documentation
  config.order = 'default'
end
like image 42
Joel Hoelting Avatar answered Oct 22 '22 00:10

Joel Hoelting


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.

like image 5
max Avatar answered Oct 21 '22 22:10

max