commit 0fd2e3755b5c171913c798f7af96692c6bcaf78a Author: John Bintz Date: Wed Apr 18 15:34:06 2012 -0400 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d87d4be --- /dev/null +++ b/.gitignore @@ -0,0 +1,17 @@ +*.gem +*.rbc +.bundle +.config +.yardoc +Gemfile.lock +InstalledFiles +_yardoc +coverage +doc/ +lib/bundler/man +pkg +rdoc +spec/reports +test/tmp +test/version_tmp +tmp diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..1eb7618 --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' + +# Specify your gem's dependencies in cucumber-step_writer.gemspec +gemspec diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..87b491e --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ +Copyright (c) 2012 John Bintz + +MIT License + +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. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..4d887df --- /dev/null +++ b/README.md @@ -0,0 +1,21 @@ +Formatter for automatically generating step files for Cucumber. It's how I roll. + +If you have a step like this: + +``` gherkin +Given I set something up +``` + +And you set up the formatter like this: + +``` +cucumber -f Cucumber::StepWriter --out features/step_definitions +``` + +Then `features/step_definitions/given/i_set_something_up.rb` will be generated. + +TODO: + +* If you want it to generate for different languages, I take pull requests. +* Otherwise, I'll just add whatever I need when I need it. + diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..f57ae68 --- /dev/null +++ b/Rakefile @@ -0,0 +1,2 @@ +#!/usr/bin/env rake +require "bundler/gem_tasks" diff --git a/cucumber-step_writer.gemspec b/cucumber-step_writer.gemspec new file mode 100644 index 0000000..b212683 --- /dev/null +++ b/cucumber-step_writer.gemspec @@ -0,0 +1,16 @@ +# -*- encoding: utf-8 -*- +Gem::Specification.new do |gem| + gem.authors = ["John Bintz"] + gem.email = ["john@coswellproductions.com"] + gem.description = %q{Write out step files for undefined Cucumber steps.} + gem.summary = %q{Write out step files for undefined Cucumber steps.} + gem.homepage = "" + + gem.files = `git ls-files`.split($\) + gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) } + gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) + gem.name = "cucumber-step_writer" + gem.require_paths = ["lib"] + gem.version = "0.1.0" +end + diff --git a/lib/cucumber-step_writer.rb b/lib/cucumber-step_writer.rb new file mode 100644 index 0000000..c345314 --- /dev/null +++ b/lib/cucumber-step_writer.rb @@ -0,0 +1 @@ +require "cucumber/step_writer" diff --git a/lib/cucumber/step_writer.rb b/lib/cucumber/step_writer.rb new file mode 100644 index 0000000..c2f7c3b --- /dev/null +++ b/lib/cucumber/step_writer.rb @@ -0,0 +1,49 @@ +require 'cucumber/formatter/io' +require 'cucumber/formatter/ansicolor' + +module Cucumber + class StepWriter + include Cucumber::Formatter::Io + include Cucumber::Formatter::ANSIColor + + class << self + def after_write(&block) + if block + @after_write = block + else + @after_write + end + end + end + + def initialize(step_mother, path_or_io, options) + @step_mother, @io = step_mother, ensure_dir(path_or_io, 'step writer') + end + + def after_features(features) + undefined = @step_mother.steps(:undefined) + return if undefined.empty? + + undefined.each do |step| + step_name = Cucumber::Undefined === step.exception ? step.exception.step_name : step.name + step_multiline_class = step.multiline_arg ? step.multiline_arg.class : nil + + path = Pathname(@io).join(step.actual_keyword.downcase.strip, step_name.underscore.gsub(%r{[^\w]+}, '_') + '.rb') + + if !path.file? + puts yellow("Writing new step to #{path}.") + + path.parent.mkpath + path.open('wb') { |fh| fh.print @step_mother.snippet_text(step.actual_keyword, step_name, step_multiline_class) } + end + end + + after_write.call(@io) if after_write + end + + def after_write + self.class.after_write + end + end +end +