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

Viewed 371

I'm new to the Ruby development ecosystem and learning Rails in my spare time. However, I would like to build a command-line app from scratch with unit tests as a part of my learning.

What is the recommended structure for a Ruby command-line project? The one I came up with is

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

Thanks

1 Answers

Unit Tests for Gems

If you're using MiniTest or similar, the expected place within gem foo would be foo/test. If you're using RSpec or minitest/spec, then you'd use foo/spec instead.

When you generate a new gem skeleton with Bundler it provides the following defaults:

$ 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

The default Rakefile is set up to run RSpec, but you can certainly implement the Rakefile's default task and your tests any way you'd like.

Related