Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Bash script to initialise skeleton Ruby (not Rails) project. Pass in the name of the project and it will create the file structure and some initial files, as per this tutorial: Also initialises the folder as a git repository and does an initial commit. Finally, the script runs a smoke test to ensure…
if [[ -z $name ]]; then
echo "Please specify a name for the Ruby project"
# Setup directory structure
mkdir $name
cd $name
mkdir bin data doc ext tests lib lib/$name
# Create empty files
touch Rakefile
touch $name.gemspec
touch bin/$name # TODO: Check: Is this file supposed to be empty?
touch lib/$name.rb # TODO: Check: Is this file supposed to be empty?
touch tests/test_$name.rb
# Add content to files
# Rakefile
cat >Rakefile << EOL
require 'rake/testtask' do |t|
t.libs << "tests"
t.test_files = FileList['tests/test*.rb']
t.verbose = true
# Gemspec
cat >$name.gemspec << EOL
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) do |spec| = '$name'
spec.version = '0.0.1'
spec.authors = ["Your Name"] = [""]
spec.summary = %q{Short summary of your project}
spec.description = %q{Longer description of your project.}
spec.homepage = ""
spec.license = "MIT"
spec.files = ['lib/$name.rb']
spec.executables = ['bin/$name']
spec.test_files = ['tests/test_$name.rb']
spec.require_paths = ["lib"]
# Tests
cat >tests/test_$name.rb << EOL
require "./lib/$name.rb"
require "test/unit"
class Test$name < Test::Unit::TestCase
def test_sample
assert_equal(4, 2+2)
# Setup as a git repository
git init
git add --all
git commit -m "Initial commit of Ruby project $name"
# Run smoke test
rake test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment