Tutorials/Tips

How to set up a Ruby project structure on Ubuntu 16.10

For about two months now I’ve been learning how to code in Ruby using Learn Ruby the Hard Way. Never mind the title, but it’s actually a very good resource for learning how to program in Ruby. The last few exercises that I’ve gone through could have been written better, but overall, it’s a good book for those just getting into the world of software coding.

Exercise 46 of the book, which deals with how to set up a skeleton directory for a Ruby project, shows how to go about it manually. With the right tools installed, however, the same task can be completed automatically, which is what you’re going to learn how to do in this article.

It will help if you have Git installed already. If not, use this article to install it on your favorite Linux distribution, then come back here to continue with this tutorial.

Welcome back!

To begin, you’ll need to install a couple of applications – ruby-bundler and ruby-rspec-core. The former helps you manage Ruby application dependencies and gives you access to the bundle and bundler commands, while the latter gives you access to rspec, a standalone test runner for Ruby RSpec test suites. RSpec is a testing tool for Ruby. Use the command shown below to install both applications.

With those two installed, you are now ready to create your project’s skeleton structure, which you do with the following command:

After running that command, you’ll be asked the following question. My comments come before each question. Note that your answer to the questions will be applied automatically to future projects you create using the bundle gem command above.

Related Post:  17 alternatives to your default image viewer on Fedora

Once you’ve answered that last question, your project’s files will be generated. The final output will look like this:

Related Post:  Enable AMD SVM to install 64-bit operating systems in Virtualbox 5.1

Now you can start editing those files and fill in items specific to your project. If Git was properly set up with your credentials using this article, your gemspec file should be populated with the global username and email address you configured for Git. Edit that file to fill in the rest of the information specific to your project.

So there you have it – a skeleton structure for your Ruby project.

How do you run a basic test using RSpec? Change into the project’s directory and type the following command:

Ruby language logo

Subscribe to LinuxBSDos.com

Subscribe to receive the latest articles in your Inbox

Trust me, you'll not be spammed...

Please share:

We Recommend These Vendors and Free Offers

Google has got competition, because Presearch is building a blockchain-based search engine controlled by the community. At $0.15 a token, you can participation in Lot 3 of the token sale by clicking here

Open Money is building a solution that will run mainstream software on blockchain tech. Click here to get free tokens that will be the digital currency of the platform

COMSA allows centralized businesses to adopt blockchain technology. The token sale starts soon! Sign up for free by clicking here

Register now for Blockchain & Cryptocurrency Con 2018, international conference on blockchain technnology in Dallas, TX (USA), Feb. 23-24, 2018. Students can register at a 50% discount.

Launch an SSD VPS in Europe, USA, Asia & Australia on Vultr's KVM-based Cloud platform starting at $5:00/month (15 GB SSD, 768 MB of RAM).


Leave a Comment

Your email address will not be published. Required fields are marked *

*