cucumber-step_writer 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cucumber-step_writer.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 John Bintz
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ Formatter for automatically generating step files for Cucumber. It's how I roll.
2
+
3
+ If you have a step like this:
4
+
5
+ ``` gherkin
6
+ Given I set something up
7
+ ```
8
+
9
+ And you set up the formatter like this:
10
+
11
+ ```
12
+ cucumber -f Cucumber::StepWriter --out features/step_definitions
13
+ ```
14
+
15
+ Then `features/step_definitions/given/i_set_something_up.rb` will be generated with
16
+ the content of the step stub.
17
+
18
+ If you want to fire an action after steps are generated, like open a directory with
19
+ the list of files so you can rearrange them, add a hook to Cucumber::StepWriter:
20
+
21
+ ``` ruby
22
+ Cucumber::StepWriter.after_write do |dir|
23
+ system %{open #{dir}}
24
+ end
25
+ ```
26
+
27
+ TODO:
28
+
29
+ * If you want it to generate for different languages, I take pull requests.
30
+ * Otherwise, I'll just add whatever I need when I need it.
31
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,16 @@
1
+ # -*- encoding: utf-8 -*-
2
+ Gem::Specification.new do |gem|
3
+ gem.authors = ["John Bintz"]
4
+ gem.email = ["john@coswellproductions.com"]
5
+ gem.description = %q{Write out step files for undefined Cucumber steps.}
6
+ gem.summary = %q{Write out step files for undefined Cucumber steps.}
7
+ gem.homepage = ""
8
+
9
+ gem.files = `git ls-files`.split($\)
10
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
11
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
12
+ gem.name = "cucumber-step_writer"
13
+ gem.require_paths = ["lib"]
14
+ gem.version = "0.1.0"
15
+ end
16
+
@@ -0,0 +1,49 @@
1
+ require 'cucumber/formatter/io'
2
+ require 'cucumber/formatter/ansicolor'
3
+
4
+ module Cucumber
5
+ class StepWriter
6
+ include Cucumber::Formatter::Io
7
+ include Cucumber::Formatter::ANSIColor
8
+
9
+ class << self
10
+ def after_write(&block)
11
+ if block
12
+ @after_write = block
13
+ else
14
+ @after_write
15
+ end
16
+ end
17
+ end
18
+
19
+ def initialize(step_mother, path_or_io, options)
20
+ @step_mother, @io = step_mother, ensure_dir(path_or_io, 'step writer')
21
+ end
22
+
23
+ def after_features(features)
24
+ undefined = @step_mother.steps(:undefined)
25
+ return if undefined.empty?
26
+
27
+ undefined.each do |step|
28
+ step_name = Cucumber::Undefined === step.exception ? step.exception.step_name : step.name
29
+ step_multiline_class = step.multiline_arg ? step.multiline_arg.class : nil
30
+
31
+ path = Pathname(@io).join(step.actual_keyword.downcase.strip, step_name.underscore.gsub(%r{[^\w]+}, '_') + '.rb')
32
+
33
+ if !path.file?
34
+ puts yellow("Writing new step to #{path}.")
35
+
36
+ path.parent.mkpath
37
+ path.open('wb') { |fh| fh.print @step_mother.snippet_text(step.actual_keyword, step_name, step_multiline_class) }
38
+ end
39
+ end
40
+
41
+ after_write.call(@io) if after_write
42
+ end
43
+
44
+ def after_write
45
+ self.class.after_write
46
+ end
47
+ end
48
+ end
49
+
@@ -0,0 +1 @@
1
+ require "cucumber/step_writer"
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cucumber-step_writer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - John Bintz
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-18 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Write out step files for undefined Cucumber steps.
15
+ email:
16
+ - john@coswellproductions.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE
24
+ - README.md
25
+ - Rakefile
26
+ - cucumber-step_writer.gemspec
27
+ - lib/cucumber-step_writer.rb
28
+ - lib/cucumber/step_writer.rb
29
+ homepage: ''
30
+ licenses: []
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubyforge_project:
49
+ rubygems_version: 1.8.11
50
+ signing_key:
51
+ specification_version: 3
52
+ summary: Write out step files for undefined Cucumber steps.
53
+ test_files: []
54
+ has_rdoc: