对于带有测试的 Ruby 命令行应用程序,推荐的文件夹结构是什么?

What is the recommended folder structure for a Ruby command-line app with tests?

我是 Ruby 开发生态系统的新手,业余时间正在学习 Rails。但是,作为我学习的一部分,我想从头开始构建一个带有单元测试的命令行应用程序。

Ruby 命令行项目的推荐结构是什么?我想到的是

/test
  - person_test.rb
/src
  - person.rb
main.rb
Gemfile
Gemfile.lock

谢谢

Gems 的单元测试

如果您使用的是 MiniTest 或类似工具,则 gem foo 中的预期位置将是 foo/test。如果您使用 RSpec 或 minitest/spec,那么您应该使用 foo/spec

当您使用 Bundler 生成新的 gem 骨架时,它会提供以下默认值:

$ bundle gem foo; tree foo
foo
├── Gemfile
├── README.md
├── Rakefile
├── bin
│   ├── console
│   └── setup
├── foo.gemspec
├── lib
│   ├── foo
│   │   └── version.rb
│   └── foo.rb
└── spec
    ├── foo_spec.rb
    └── spec_helper.rb

4 directories, 10 files

默认 Rakefile 设置为 运行 RSpec,但您当然可以按照自己喜欢的方式实现 Rakefile 的默认任务和测试。