Skip to content

Commit

Permalink
cli for setting up project
Browse files Browse the repository at this point in the history
  • Loading branch information
despo committed Apr 15, 2011
1 parent fe6ad8e commit f3930b6
Show file tree
Hide file tree
Showing 7 changed files with 190 additions and 11 deletions.
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,14 @@ Let's see how this works with a simple example...

## Let's Get started

Create a new project:
Create a new project Calculator:

mkdir ~/projects/Calculator
cd ~/projects/Calculator
cuke_salad new Calculator

Inside the root of that project...
Or configure an existing project by running the following command inside the project directory

cuke_salad configure

mkdir features
mkdir features/support
mkdir features/lib/default/roles
mkdir features/lib/default/tasks

In idiomatic Cucumber style, we use `features/support/env.rb` to require _CukeSalad_ and
define the location of our project's _roles_ and _tasks_ e.g.:
Expand Down
3 changes: 2 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ Jeweler::Tasks.new do |gem|
# The following two lines need to be commented out in order to gain access to the version rake tasks
gem_version = File.exist?('VERSION') ? File.read('VERSION') : ""
gem.version = gem_version

gem.executables = ["cuke_salad"]
gem.files.include 'lib/cuke_salad/cli.rb'
end

Jeweler::RubygemsDotOrgTasks.new
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.0
0.2.0
27 changes: 27 additions & 0 deletions bin/cuke_salad
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
##!/usr/bin/env ruby
require 'optparse'
require 'cuke_salad/cli'

OptionParser.new do |opts|
opts.banner = "Usage: cuke_salad [new | configure] project_name"

begin
opts.parse!(ARGV)
rescue OptionParser::ParseError => e
warn e.message
puts opts
exit 1
end
end

if ARGV.empty?
abort "Usage: cuke_salad new <project name>\nOr: cuke_salad configure"
elsif ARGV.first == 'new'
project = ARGV[1]
puts "Creating project #{project}..."
CukeSalad::CLI.create_new_project project
puts "Done!"
elsif ARGV.first == 'configure'
CukeSalad::CLI.configure_existing_project
puts "Done!"
end
10 changes: 9 additions & 1 deletion cuke_salad.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ Gem::Specification.new do |s|

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["RiverGlide"]
s.date = %q{2011-04-14}
s.date = %q{2011-04-15}
s.default_executable = %q{cuke_salad}
s.description = %q{CukeSalad allows you to focus on the task at hand - expressing examples, the roles involved in those examples and what those roles can do with the product under development.}
s.email = %q{[email protected]}
s.executables = ["cuke_salad"]
s.extra_rdoc_files = [
"LICENSE",
"README.md"
]
s.files = [
Expand Down Expand Up @@ -41,7 +44,10 @@ Gem::Specification.new do |s|
"Gemfile",
"Gemfile.lock",
"README.md",
"Rakefile",
"VERSION",
"cucumber.yml",
"cuke_salad.gemspec",
"features/a_new_cuke_salad_project.feature",
"features/define_a_role.feature",
"features/define_a_task.feature",
Expand All @@ -61,6 +67,7 @@ Gem::Specification.new do |s|
"lib/actor.rb",
"lib/codify/const_name.rb",
"lib/cuke_salad.rb",
"lib/cuke_salad/cli.rb",
"lib/director.rb",
"lib/specifics.rb",
"lib/task_author.rb",
Expand Down Expand Up @@ -92,6 +99,7 @@ Gem::Specification.new do |s|
"examples/Calculator/spec/web_calculator_spec.rb",
"spec/actor_spec.rb",
"spec/codify/as_const_name_spec.rb",
"spec/cuke_salad/cli_spec.rb",
"spec/director_spec.rb",
"spec/spec_helper.rb",
"spec/specifics_spec.rb",
Expand Down
68 changes: 68 additions & 0 deletions lib/cuke_salad/cli.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
require 'aruba/api'
module CukeSalad
class CLI

def self.create_new_project project
structure = Structure.new
structure.setup project
end

def self.configure_existing_project project=nil
`cd #{project}` if project
structure = Structure.new
structure.setup_cucumber_with_cuke_salad
end

class Structure
include Aruba::Api

def initialize
set_aruba_path_to_current
end

def setup project
create_and_navigate_to project
setup_cucumber_with_cuke_salad
end

def setup_cucumber_with_cuke_salad
create_dir_structure
configure
end

private
def set_aruba_path_to_current
@dirs = ["./"]
end

def create_dir_structure
create_cucumber_structure
create_cuke_salad_structure
end

def create_cucumber_structure
create_and_navigate_to "features"
create_dir "support"
end

def create_cuke_salad_structure
create_and_navigate_to "lib"
create_and_navigate_to "default"
create_dir "roles"
create_dir "tasks"
cd "../../../"
end

def configure
cd "features/support"
content = "require 'cuke_salad'\n begin require 'rspec/expectations'; rescue LoadError; require 'spec/expectations'; end"
append_to_file "env.rb",content
end

def create_and_navigate_to directory
create_dir directory
cd directory
end
end
end
end
78 changes: 78 additions & 0 deletions spec/cuke_salad/cli_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
$:.unshift(File.dirname(__FILE__), ".")
require 'spec_helper'
require 'cuke_salad/cli'

describe CukeSalad::CLI do
let(:project) { 'Foobar' }
let(:features) { project+'/features'}

shared_examples_for "setup cuke_salad and cucumber" do
it 'Can create features directory' do
dir_exists?(features).should be_true
end

it 'can create features/support directory' do
dir_exists?(features+'/support').should be_true
end

context 'in cuke_salad/features/support' do
let(:file) { features+'/support/env.rb' }

it 'can create a file env.rb' do
File.exists?(file).should be_true
end

it 'with a given content' do
content = "require 'cuke_salad'\n begin require 'rspec/expectations'; rescue LoadError; require 'spec/expectations'; end"
IO.read(file).should == content
end
end

it 'can create lib directory' do
dir_exists?(features+'/lib').should be_true
end

it 'can create lib/default directory' do
dir_exists?(features+'/lib/default').should be_true
end

it 'can create features/lib/roles directory' do
dir_exists?(features+'/lib/default/roles').should be_true
end

it 'can create tasks directory' do
dir_exists?(features+'/lib/default/tasks').should be_true
end
end


context 'Create new project Foobar' do

before(:all) do
cli = CukeSalad::CLI.create_new_project(project)
end

it "Can create the project directory" do
dir_exists?(project).should be_true
end

it_should_behave_like "setup cuke_salad and cucumber"
end

context 'Setup existing project' do
before(:all) do
`cd Foobar`
CukeSalad::CLI.configure_existing_project
end
it_should_behave_like "setup cuke_salad and cucumber"
end


def dir_exists? file
File.exists?(file)
end

after(:all) do
FileUtils.rm_rf project
end
end

0 comments on commit f3930b6

Please sign in to comment.