I want to create a small Ruby project with 10 ~ 20 classes/files. I need some gems and I want to use RSpec as a test framework.
I might want to build a gem later on, but that is not certain.
Is there some how-to or guide that shows me how to set up the basic structure of my project?
Questions that I have are:
- Where do I put all my custom Errors/Exceptions?
- Are there some conventions out there for naming directories like lib, bin, src etc?
- Where do I put test data or documents?
- Where do I require all my files so I have access to them in my project?
I know I could do everything from scratch, but I would like some guidance. There are some good gems out there that I could copy, but I am not certain what I really need and what I can delete.
I looked at http://gembundler.com/, but it stops after setting up Bundler.
Best Answer
To get a good start, you can use the
bundle gem
command andrspec --init
.lib
spec
spec/fixtures/
lib/my_lib.rb
. You can define your exceptions in that file, too, or in their own files -- according to your own preference.ext/my_lib
bin
When in doubt, just look at how other gems are laid out.
Further information:
You should add rspec as a development dependency in your gemspec to make things easier for other developers
gem.add_development_dependency 'rspec'
andgem.add_development_dependency 'rake'
near the bottom.Bundler.setup
andrequire 'my_lib'
to the top of spec/spec_helper.rb to ensure your gem dependencies are loaded when you run your specs.require "rspec/core/rake_task"
andtask :default => :spec
to your Rakefile, so that runningrake
will run your specs.While you're working on your newest creation, guard-rspec can save you time and hassle by automatically running your specs as files change, alerting you to spec failures.
After you're happy with your creation, push it up to github
Then, when you're ready to release your gem on Rubygems.org, run
rake release
, which will walk you through the steps.Further References