diff --git a/README.md b/README.md index e830ed2..51d32a9 100644 --- a/README.md +++ b/README.md @@ -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.: diff --git a/Rakefile b/Rakefile index 3ae1420..22db5dc 100644 --- a/Rakefile +++ b/Rakefile @@ -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 diff --git a/VERSION b/VERSION index 6c6aa7c..0ea3a94 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.1.0 \ No newline at end of file +0.2.0 diff --git a/bin/cuke_salad b/bin/cuke_salad new file mode 100755 index 0000000..b69ffde --- /dev/null +++ b/bin/cuke_salad @@ -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 \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 diff --git a/cuke_salad.gemspec b/cuke_salad.gemspec index ff910b4..9e33a7a 100644 --- a/cuke_salad.gemspec +++ b/cuke_salad.gemspec @@ -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{talktous@riverglide.com} + s.executables = ["cuke_salad"] s.extra_rdoc_files = [ + "LICENSE", "README.md" ] s.files = [ @@ -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", @@ -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", @@ -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", diff --git a/lib/cuke_salad/cli.rb b/lib/cuke_salad/cli.rb new file mode 100644 index 0000000..7ea7a55 --- /dev/null +++ b/lib/cuke_salad/cli.rb @@ -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 diff --git a/spec/cuke_salad/cli_spec.rb b/spec/cuke_salad/cli_spec.rb new file mode 100644 index 0000000..f8f7516 --- /dev/null +++ b/spec/cuke_salad/cli_spec.rb @@ -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