initial commit
This commit is contained in:
commit
0fd2e3755b
17
.gitignore
vendored
Normal file
17
.gitignore
vendored
Normal file
@ -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
|
4
Gemfile
Normal file
4
Gemfile
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
source 'https://rubygems.org'
|
||||||
|
|
||||||
|
# Specify your gem's dependencies in cucumber-step_writer.gemspec
|
||||||
|
gemspec
|
22
LICENSE
Normal file
22
LICENSE
Normal file
@ -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.
|
21
README.md
Normal file
21
README.md
Normal file
@ -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.
|
||||||
|
|
16
cucumber-step_writer.gemspec
Normal file
16
cucumber-step_writer.gemspec
Normal file
@ -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
|
||||||
|
|
1
lib/cucumber-step_writer.rb
Normal file
1
lib/cucumber-step_writer.rb
Normal file
@ -0,0 +1 @@
|
|||||||
|
require "cucumber/step_writer"
|
49
lib/cucumber/step_writer.rb
Normal file
49
lib/cucumber/step_writer.rb
Normal file
@ -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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user