如何全局配置RSpec以保持'--color'和'--format specdoc'选项打开

Evo*_*lve 155 ruby rspec colors configuration-files

如何在Ubuntu中为RSpec设置全局配置.

具体来说, - color和--format specdoc在我的所有项目中保持打开状态(即每次我在任何地方运行rspec).

aby*_*byx 236

正如您在此处的文档中所看到的,预期用途是创建~/.rspec并在其中放置您的选项,例如--color.

~/.rspec使用该--color选项快速创建文件,只需运行:

echo '--color' >> ~/.rspec 
Run Code Online (Sandbox Code Playgroud)

  • 即使使用寻呼机,如果你想要颜色,也需要`--tty`. (17认同)
  • I also set `--format documentation` in `~/.rspec`. (3认同)
  • 使用`.rspec`或`spec_helper.rb`的利弊是什么?@shamaoke @christoph (2认同)
  • `〜/ .rspec`解决方案的一大优点是可移植性.例如,我们的CI服务器不能很好地处理颜色输出.使用用户dir配置文件,我们可以轻松地采用不同的环境. (2认同)
  • 另一个相关的注释是,您可以在项目级别创建.rspec文件,并将其应用于该项目.只是觉得有些人可能也想知道这里. (2认同)

Sha*_*oke 149

也可以spec_helper.rb在所有项目中使用文件.该文件应包括以下内容:

RSpec.configure do |config|
  # Use color in STDOUT
  config.color = true

  # Use color not only in STDOUT but also in pagers and files
  config.tty = true

  # Use the specified formatter
  config.formatter = :documentation # :progress, :html,
                                    # :json, CustomFormatterClass
end
Run Code Online (Sandbox Code Playgroud)

任何示例文件都必须要求帮助程序才能使用该选项.

  • 搜索有关RSpec配置和格式化程序的信息会带来一个到这个页面,所以我很感激这个答案,即使它是针对错误的问题:-) (8认同)
  • `color_enabled`现在是`color` (3认同)

Chr*_*nig 12

在您的spec_helper.rb文件中,包含以下选项:

RSpec.configure do |config|
  config.color_enabled = true
end
Run Code Online (Sandbox Code Playgroud)

然后,您必须在每个*_spec.rb文件中要求使用该选项.


fer*_*nyb 6

如果您使用rake运行rspec测试,那么您可以编辑spec/spec.opts

http://rspec.info/rails/runners.html

  • ./spec.opts已经被删除.Rails 3希望将文件命名为./.rspec或〜/ .rspec (9认同)