Back

Ruby project get started with minitest and bundler

added on :: 15 October 2014

This could be used to create a Ruby gem as well as an  Ruby program. To get the directory structure ready as well as rake tasks and testing working highly recommend to use bundler. So this is my kind of Ruby project boilerplate.


bundle gem robo


      create  robo/Gemfile
      create  robo/Rakefile
      create  robo/LICENSE.txt
      create  robo/README.md
      create  robo/.gitignore
      create  robo/robo.gemspec
      create  robo/lib/robo.rb
      create  robo/lib/robo/version.rb

firstly update the gemspect.rb file

  spec.authors       = ["anthony"]
  spec.email          = [“me@example.com"]
  spec.summary       = %q{the awesome app}
  spec.description   = %q{hopefully this would be awesome}




if you want just to run a ruby file

open robo.rb file and puts “Hello World” to that

 puts "Hello World"


to run it on the command line

>  ruby robo.rb

 

then add files to the lib diectory to your hearts content and require such as

require_relative 'robocop'

or

require
File.expand_path("../robocop.rb", __FILE__)


Now add minutest

Open  the “Gemfile”

source 'https://rubygems.org'

# Specify your gem's dependencies in robo.gemspec
gemspec
gem 'minitest'



and bundle install


Then you would see the Gemfile.lock

 
 then open the  “Rakefile”

require "bundler/gem_tasks"
require 'rake/testtask'

Rake::TestTask.new do |t|
  t.libs << "test"
  t.pattern = "test/**/*_test.rb"
end

task :default => :test


That would enable you to run "rake test" to run all tests.


then create your test directory in the root level

add a “unit”  directory (this is optional)

create the test file
robo_test.rb

add your first test

 require File.join(File.dirname(__FILE__), '..', 'test_helper.rb')

class TestMeme < Minitest::Test

    def test_that_life_is_good
      assert_equal "hello world",  Robo.say_hello
    end

end



if all is good do a 'rake test' you would see

 # Running:

"hello world"
.

Finished in 0.001135s, 881.0573 runs/s, 881.0573 assertions/s.

1 runs, 1 assertions, 0 failures, 0 errors, 0 skips


Then push the code to Github

 touch README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin git@github.com:iamfree-com/robo.git
git push -u origin master


Then go to the hills :-)


Back