Rspec 多个规格文件夹 [英] Rspec multiple spec folders

查看:19
本文介绍了Rspec 多个规格文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用 Rspec 构建一个项目,其中我将域代码和基础结构代码分隔在两个不同的文件夹中.这两个文件夹在 spec 文件夹中都有自己的规范.domain/spec 文件夹是包含 spec_helper.rb 文件的文件夹,这是其他文件夹中的测试所需的基础结构/spec

Im currently building a project using Rspec in which I sepparated in two different folders with domain code and infrastructure code. Both folders have their own specs in a spec folder. The domain/spec folder is the one containing the spec_helper.rb file, thats required from the tests inside the other folder infrastructure/spec

我想知道如何在项目的根目录中创建一个 spec 文件夹,包括 spec_helper 文件和测试,并且能够只用一个命令运行所有测试(现在我运行 rspec域/基础设施/)

I'd like to know how to have a spec folder in the root of the project, including the spec_helper file and also tests, and being able to run all the tests with just one command (right now I do it running rspec domain/ infrastructure/)

推荐答案

RSpec 旨在处理 one 文件夹中的所有测试.默认情况下,此文件夹名为 spec/,但您可以使用不同的名称--default-path 选项.

RSpec is designed to work with all tests in one folder. By default, this folder is called spec/, but you can use a different name with the --default-path option.

所以,在我看来,您的选择是:

So, your options as I see it are:

  1. 编辑rspec-core 的代码 让该配置支持多个目录.希望您的 PR 能够获得批准并合并.
  2. 或者,编写一个简单的包装脚本,对两个目录运行 rspec.例如,您可以别名 rspecs='rspec domain/infrastructure/'.
  3. 或者(我会推荐什么!),你可以稍微调整你的测试来使用 spec/domain/spec/infrastructure/ 文件夹——然后一切都会按照惯例,开箱即用.
  1. Edit the source code of rspec-core to let that configuration support multiple directories. Hopefully your PR will be approved and merged.
  2. Or, write a simple wrapper script that runs rspec against both directories. For example, you could alias rspecs='rspec domain/ infrastructure/'.
  3. Or (what I would recommend!), you could just restructure your tests slightly to use spec/domain/ and spec/infrastructure/ folders -- and then everything will just work, by convention, out of the box.

这篇关于Rspec 多个规格文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆