如何全局配置 RSpec 以保持“--color”和“--格式规范文档”选项已打开

发布于 2024-08-13 17:41:08 字数 111 浏览 3 评论 0原文

如何在 Ubuntu 中设置 RSpec 的全局配置。

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

How do I set global configuration for RSpec in Ubuntu.

Specifically so, --color and --format specdoc stay turned on, across all my projects (ie every time I run rspec anywhere).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

生来就爱笑 2024-08-20 17:41:08

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

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

echo '--color' >> ~/.rspec 

As you can see in the docs here, the intended use is creating ~/.rspec and in it putting your options, such as --color.

To quickly create an ~/.rspec file with the --color option, just run:

echo '--color' >> ~/.rspec 
你好,陌生人 2024-08-20 17:41:08

还可以在所有项目中使用 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

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

One can also use a spec_helper.rb file in all projects. The file should include the following:

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

Any example file must require the helper to be able to use that options.

满身野味 2024-08-20 17:41:08

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

RSpec.configure do |config|
  config.color_enabled = true
end

然后,您必须在每个应使用该选项的 *_spec.rb 文件中进行 require。

In your spec_helper.rb file, include the following option:

RSpec.configure do |config|
  config.color_enabled = true
end

You then must require in each *_spec.rb file that should use that option.

樱娆 2024-08-20 17:41:08

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

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

If you use rake to run rspec tests then you can edit spec/spec.opts

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

凡尘雨 2024-08-20 17:41:08

或者像我一样将 alias spec=spec --color --format specdoc 添加到您的 ~/.bashrc 文件中。

Or simply add alias spec=spec --color --format specdoc to your ~/.bashrc file like me.

著墨染雨君画夕 2024-08-20 17:41:08

需要注意的一件事是运行 RSpec 的不同方式的影响。

我试图在spec/spec_helper.rb中使用以下代码打开该选项 -

Rspec.configure do |config|
  config.tty = $stdout.tty?
end
  1. 直接调用“rspec”二进制文件 - 或者作为“bundle exec rspec”并检查$stdout.tty?将返回 true。
  2. 调用“rake spec”任务 - 或作为“bundle exec rake spec” - Rake 将在单独的进程中调用 rspec,而 $stdout.tty?将返回 false。

最后我使用了 ~/.rspec 选项,仅使用 --tty 作为其内容。对我来说效果很好,可以保持我们的 CI 服务器输出干净。

One thing to be aware of is the impact of the different ways of running RSpec.

I was trying to turn on the option with the following code in spec/spec_helper.rb -

Rspec.configure do |config|
  config.tty = $stdout.tty?
end
  1. calling the 'rspec' binary directly - or as 'bundle exec rspec' and checking $stdout.tty? will return true.
  2. invoking the 'rake spec' task - or as 'bundle exec rake spec' - Rake will invoke rspec in a separate process, and $stdout.tty? will return false.

In the end I used the ~/.rspec option, with just --tty as its contents. Works well for me and keeps our CI server output clean.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文