diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..30f4292 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +Copyright (c) 2010 RiverGlide + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + diff --git a/README.md b/README.md index 8331280..5e557a5 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Cuke Salad +# Cuke Salad _Cucumber, washed and ready to eat for Friction-free ATDD/BDD_ @@ -9,7 +9,6 @@ e-mail feedback to * Support more step structures - such as tables as input * Move beyond current examples by documenting CukeSalad with Cucumber -* Make available as a gem * Remembering data between steps * Multiple role/actor scenarios @@ -21,7 +20,7 @@ With CukeSalad you don't need to write step-definitions. Of course, you still have to write some code - but only the code that expresses: -* the roles and the actions they can perform +* the roles and the actions they can perform * the tasks and the actions involved in completing that task ## Goals->Tasks->Actions @@ -37,30 +36,22 @@ Let's see how this works with a simple example... ## Install - gem install bundler - gem update --system - git clone git@github.com:RiverGlide/CukeNarrative.git - bundle install + gem install cukesalad ## Let's Get started -Create a new project outside of the CukeSalad directory structure, e.g.: +Create a new project Calculator: - mkdir ~/projects/Calculator - cd ~/projects/Calculator + cukesalad new Calculator -Inside the root of that project... +Or configure an existing project by running the following command inside the project directory + + cukesalad 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.: - $:.unshift(File.dirname(__FILE__) + '/../../../../lib') #where to find CukeSalad - require 'cukesalad' begin require 'rspec/expectations'; rescue LoadError; require 'spec/expectations'; end @@ -69,7 +60,7 @@ all .rb files beneath the project's `features/` directory. ## Write Features -In `features/`, let's create our first feature file - `A_PlaceToStart.feature`: +In `features/`, let's create our first feature file - `a_place_to_start.feature`: Feature: A Place To Start As Callie, a calculating individual @@ -88,12 +79,12 @@ Let's take a moment to understand this scenario: When I attempt to Then I should '' -To get this working, we don't need to write any steps. +To get this working, we don't need to write any steps. Just explain how to do the _task_ using a class... ## Create Tasks -Explaining how to do a _task_ is easy: +Explaining how to do a _task_ is easy: Create a new file, `features/lib/tasks/switch_on_the_calculator.rb` Remember the step `When I attempt to switch on the calculator` @@ -116,7 +107,7 @@ this example, we need to explain how the `CalculatingIndividual` _role_ works... Remember the step `Given I am a Calculating Individual`? -We explain a _role_ by creating a new file +We explain a _role_ by creating a new file called `features/lib/roles/calculating_individual.rb` module CalculatingIndividual @@ -128,13 +119,13 @@ called `features/lib/roles/calculating_individual.rb` def look_at_the_display @calculator.display end - end + end You'll need a class called Calculator on the load path of course, but that's it. From your project folder, run (_note: '%' is our command prompt_) - % cucumber + % cucumber We now have our first passing Feature, without creating a single step definition! @@ -148,9 +139,9 @@ Let's try another scenario... When I attempt to add: the number '10' to the number '10' Then I should see the answer '20' -Notice that we've reused 'switch on the calculator'. +Notice that we've reused 'switch on the calculator'. -The new _When_ step has a slightly different layout. +The new _When_ step has a slightly different layout. Let's examine that for a second... Notice the ':' (colon) after and the name-value pairs: When I attempt to : '' '' @@ -171,9 +162,9 @@ Notice how the `value_of` lines use symbols that correspond to the wording `'the There is some 'syntactic sugar' that we can use to dress this up a little and make it read nicer... a simple attribute mapping: in_order_to "Add", the_number: :first_number, to_the_number: :second_number do - enter the :first_number + enter the :first_number press :plus - enter the :second_number + enter the :second_number press :equals end @@ -214,10 +205,10 @@ Now all we need to do is modify our `calculating_individual.rb` to receive those Now, you can run cucumber again: - % cucumber + % cucumber -There's no need to write `step_definitions`... -Simply express the _roles_ and the _tasks_ in clear, +There's no need to write `step_definitions`... +Simply express the _roles_ and the _tasks_ in clear, concise, easy to read classes. After adding some more scenarios and tasks and an alternative "Calculating Individual" (see below for why), our finished Calculator directory structure looks like this... @@ -251,14 +242,14 @@ After adding some more scenarios and tasks and an alternative "Calculating Indiv │   └── web_calculator.rb └── spec ├── calculator_spec.rb - └── web_calculator_spec.rb + └── web_calculator_spec.rb -Take a look around the examples and the code to see how it all works. We hope you enjoy reading as much as we enjoyed writing it. +Take a look around the examples and the code to see how it all works. We hope you enjoy reading as much as we enjoyed writing it. ## Alternative Roles -As our features _describe the value of a calculator application and not its -implementation_, we have the opportunity to reuse them. +As our features _describe the value of a calculator application and not its +implementation_, we have the opportunity to reuse them. In the Calculator example, we create a new _role_ in `./features/lib/alternative/roles/calculating_web_user.rb`, which we can swap diff --git a/Rakefile b/Rakefile index ed72ec9..c6cc06a 100644 --- a/Rakefile +++ b/Rakefile @@ -14,6 +14,7 @@ Jeweler::Tasks.new do |gem| # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options gem.name = "cukesalad" gem.homepage = "https://github.com/RiverGlide/CukeSalad" + gem.platform = Gem::Platform::RUBY gem.license = "MIT" gem.summary = %Q{Friction Free BDD/ATDD with cucumber} gem.description = %Q{CukeSalad allows you to focus on the tasks at hand - expressing examples, the roles involved in those examples and the tasks that those roles need to perform with the product under development.} @@ -23,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 = ["cukesalad"] + gem.files.include 'lib/cukesalad/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/cukesalad b/bin/cukesalad new file mode 100755 index 0000000..f3fd8c2 --- /dev/null +++ b/bin/cukesalad @@ -0,0 +1,28 @@ +#!/usr/bin/env ruby + +require 'optparse' +require 'cukesalad/cli' + +OptionParser.new do |opts| + opts.banner = "Usage: cukesalad [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: cukesalad new \nOr: cukesalad 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/cukesalad/cli.rb b/cukesalad/cli.rb new file mode 100644 index 0000000..e545952 --- /dev/null +++ b/cukesalad/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_cukesalad + 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_cukesalad + end + + def setup_cucumber_with_cukesalad + create_dir_structure + configure + end + + private + def set_aruba_path_to_current + @dirs = ["./"] + end + + def create_dir_structure + create_cucumber_structure + create_cukesalad_structure + end + + def create_cucumber_structure + create_and_navigate_to "features" + create_dir "support" + end + + def create_cukesalad_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 'cukesalad'\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/cukesalad/cli_spec.rb b/spec/cukesalad/cli_spec.rb new file mode 100644 index 0000000..47dbdbb --- /dev/null +++ b/spec/cukesalad/cli_spec.rb @@ -0,0 +1,99 @@ +$:.unshift(File.dirname(__FILE__), ".") +require 'spec_helper' +require 'cukesalad/cli' + +# don't override aruba path +module CukeSalad + class CLI + class Structure + def initialize + end + end + end +end + +def dir_exists? file + File.exists?("tmp/aruba/"+file) +end + +def file_content file + IO.read("tmp/aruba/"+file) +end + +alias :file_exists? :dir_exists? + +describe CukeSalad::CLI do + + shared_examples_for "setup cukesalad and cucumber" do + it 'creates features directory' do + dir_exists?(features).should be_true + end + + context 'in features' do + it 'creates support directory' do + dir_exists?(features+'/support').should be_true + end + + context 'in support' do + let(:file) { features+'/support/env.rb' } + + it 'creates a file env.rb' do + file_exists?(file).should be_true + end + + it 'env.rb has the right content' do + content = "require 'cukesalad'\n begin require 'rspec/expectations'; rescue LoadError; require 'spec/expectations'; end" + file_content(file).should == content + end + end + + it 'creates lib directory' do + dir_exists?(features+'/lib').should be_true + end + + context 'in lib' do + it 'creates default directory' do + dir_exists?(features+'/lib/default').should be_true + end + + context 'in features/lib/default' do + it 'creates roles directory' do + dir_exists?(features+'/lib/default/roles').should be_true + end + + it 'creates tasks directory' do + dir_exists?(features+'/lib/default/tasks').should be_true + end + end + end + end + end + + context 'Create new project foobar' do + let(:new_project) { 'foobar' } + let(:features) { new_project + "/features" } + + before(:all) do + CukeSalad::CLI.create_new_project(new_project) + end + + it "creates the project directory" do + dir_exists?(new_project).should be_true + end + + it_should_behave_like "setup cukesalad and cucumber" + end + + context 'Setup existing project' do + let(:features) { 'features' } + + before(:all) do + CukeSalad::CLI.configure_existing_project + end + it_should_behave_like "setup cukesalad and cucumber" + end + + after(:all) do + FileUtils.rm_rf 'tmp' + end +end