cuketagger 0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +8 -0
- data/Rakefile +47 -0
- data/bin/cuketagger +5 -0
- data/lib/cuketagger/tag_formatter.rb +35 -0
- data/lib/cuketagger/tagger.rb +112 -0
- data/lib/cuketagger/version.rb +3 -0
- data/lib/cuketagger.rb +16 -0
- metadata +70 -0
data/README.markdown
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
|
2
|
+
<pre><code>
|
3
|
+
$ sudo gem install jarib-cuketagger
|
4
|
+
$ cuketagger add:wip features/foo.feature:6 features/bar.feature
|
5
|
+
// check that the output is as expected
|
6
|
+
$ cuketagger --force add:wip features/foo.feature:6 features/bar.feature
|
7
|
+
// --force rewrites your files
|
8
|
+
</code></pre>
|
data/Rakefile
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "rake/clean"
|
4
|
+
require "rake/gempackagetask"
|
5
|
+
require "lib/cuketagger/version"
|
6
|
+
require "cucumber/rake/task"
|
7
|
+
CLEAN.include %w[pkg]
|
8
|
+
|
9
|
+
GEM_NAME = "cuketagger"
|
10
|
+
GEM_VERSION = CukeTagger::Version
|
11
|
+
|
12
|
+
spec = Gem::Specification.new do |s|
|
13
|
+
s.name = GEM_NAME
|
14
|
+
s.version = GEM_VERSION
|
15
|
+
s.has_rdoc = false
|
16
|
+
s.summary = "batch tagging of cucumber features and scenarios"
|
17
|
+
s.description = s.summary
|
18
|
+
s.authors = %w[Jari Bakken]
|
19
|
+
s.email = "jari.bakken@gmail.com"
|
20
|
+
s.homepage = "http://cukes.info"
|
21
|
+
s.files = %w[Rakefile README.markdown] + Dir['lib/**/*']
|
22
|
+
s.bindir = 'bin'
|
23
|
+
s.executables = Dir['bin/*'].map { |f| File.basename(f) }
|
24
|
+
s.add_runtime_dependency 'cucumber', '>= 0.3.103'
|
25
|
+
end
|
26
|
+
|
27
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
28
|
+
pkg.gem_spec = spec
|
29
|
+
end
|
30
|
+
|
31
|
+
namespace :gem do
|
32
|
+
desc "install the gem locally"
|
33
|
+
task :install => [:package] do
|
34
|
+
sh %{sudo #{Gem.ruby} -S gem install pkg/#{GEM_NAME}-#{GEM_VERSION}}
|
35
|
+
end
|
36
|
+
|
37
|
+
desc "Create a .gemspec file"
|
38
|
+
task :spec do
|
39
|
+
file = "#{GEM_NAME.downcase}.gemspec"
|
40
|
+
File.unlink file if ::File.exists?(file)
|
41
|
+
File.open(file, "w+") { |f| f << spec.to_ruby }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
Cucumber::Rake::Task.new(:features) do |t|
|
46
|
+
t.cucumber_opts = "--format pretty"
|
47
|
+
end
|
data/bin/cuketagger
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
module CukeTagger
|
2
|
+
module TagFormatter
|
3
|
+
attr_accessor :tagger
|
4
|
+
|
5
|
+
def before_feature(feature)
|
6
|
+
@__current_feature = feature
|
7
|
+
super
|
8
|
+
end
|
9
|
+
|
10
|
+
def before_feature_element(element)
|
11
|
+
@__current_element = element
|
12
|
+
super
|
13
|
+
end
|
14
|
+
|
15
|
+
def after_feature_element(element)
|
16
|
+
@__current_element = nil
|
17
|
+
super
|
18
|
+
end
|
19
|
+
|
20
|
+
def before_tags(tags)
|
21
|
+
@tagger.process(@__current_feature, @__current_element, tags.instance_variable_get("@tag_names"))
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def record_tag_occurrences(*args)
|
27
|
+
# override to avoid error if options[:include_tags] is nil
|
28
|
+
end
|
29
|
+
|
30
|
+
def print_summary(*args)
|
31
|
+
# override
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
module CukeTagger
|
2
|
+
class Tagger
|
3
|
+
USAGE = "#{File.basename $0} [-v|--version] [-f|--force] [add|remove|replace]:TAG[:REPLACEMENT] [FILE[:LINE]]+"
|
4
|
+
|
5
|
+
def self.execute(args)
|
6
|
+
new.execute(args)
|
7
|
+
end
|
8
|
+
|
9
|
+
def execute(args)
|
10
|
+
abort(USAGE) if args.empty? || args.first =~ /^(-h|--help)$/
|
11
|
+
opts = {:dry_run => true, :source => true}
|
12
|
+
|
13
|
+
CukeTagger.log :args, args
|
14
|
+
|
15
|
+
args.each do |arg|
|
16
|
+
case arg
|
17
|
+
when /^-v|--version$/
|
18
|
+
puts CukeTagger::Version
|
19
|
+
when /^(.+?\.feature)(:\d+)?$/
|
20
|
+
add_feature($1, $2.to_s)
|
21
|
+
when /^(add|remove):(.+?)$/
|
22
|
+
alterations << [$1.to_sym, $2]
|
23
|
+
when /^(replace):(.+?):(.+)$/
|
24
|
+
alterations << [$1.to_sym, [$2, $3]]
|
25
|
+
when /^(-f|--force)$/
|
26
|
+
opts[:autoformat] = "."
|
27
|
+
opts[:source] = false
|
28
|
+
Term::ANSIColor.coloring = false
|
29
|
+
else
|
30
|
+
abort(USAGE)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
alterations.uniq!
|
35
|
+
|
36
|
+
CukeTagger.log :alterations, alterations
|
37
|
+
|
38
|
+
formatter = Cucumber::Formatter::Pretty.new(step_mother, $stdout, opts)
|
39
|
+
formatter.extend(TagFormatter)
|
40
|
+
formatter.tagger = self
|
41
|
+
|
42
|
+
walker = Cucumber::Ast::TreeWalker.new(step_mother, [formatter], opts)
|
43
|
+
walker.visit_features features
|
44
|
+
end
|
45
|
+
|
46
|
+
def process(feature, element, tag_names)
|
47
|
+
CukeTagger.log :process, :element => element.class
|
48
|
+
return unless should_alter?(feature, element)
|
49
|
+
|
50
|
+
alterations.each do |op, tag_name|
|
51
|
+
case op
|
52
|
+
when :add
|
53
|
+
tag_names.push "@#{tag_name}"
|
54
|
+
when :remove
|
55
|
+
tag_names.delete "@#{tag_name}"
|
56
|
+
when :replace
|
57
|
+
idx = tag_names.index "@#{tag_name.first}"
|
58
|
+
if idx.nil?
|
59
|
+
$stderr.puts "expected #{tag_name.first.inspect} at #{file_and_line_for(feature, element).join(":")}, skipping"
|
60
|
+
else
|
61
|
+
tag_names[idx] = "@#{tag_name.last}"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def should_alter?(feature, element)
|
68
|
+
fl = file_and_line_for(feature, element)
|
69
|
+
|
70
|
+
CukeTagger.log(:file_and_line => fl, :features_to_change => features_to_change)
|
71
|
+
|
72
|
+
features_to_change.include? fl
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def file_and_line_for(feature, element)
|
78
|
+
line = if element.respond_to?(:line)
|
79
|
+
element.line
|
80
|
+
elsif element.kind_of?(Cucumber::Ast::ScenarioOutline)
|
81
|
+
element.instance_variable_get("@line")
|
82
|
+
else
|
83
|
+
0
|
84
|
+
end
|
85
|
+
|
86
|
+
[feature.file, line]
|
87
|
+
end
|
88
|
+
|
89
|
+
def add_feature(path, line)
|
90
|
+
ff = Cucumber::FeatureFile.new(path).parse(step_mother, {})
|
91
|
+
features_to_change << [path, line[1,line.length].to_i]
|
92
|
+
features.add_feature ff
|
93
|
+
end
|
94
|
+
|
95
|
+
def step_mother
|
96
|
+
@step_mother ||= Cucumber::StepMother.new
|
97
|
+
end
|
98
|
+
|
99
|
+
def features
|
100
|
+
@features ||= Cucumber::Ast::Features.new
|
101
|
+
end
|
102
|
+
|
103
|
+
def alterations
|
104
|
+
@alterations ||= []
|
105
|
+
end
|
106
|
+
|
107
|
+
def features_to_change
|
108
|
+
@features_to_change ||= Set.new
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
end
|
data/lib/cuketagger.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
2
|
+
|
3
|
+
require "cucumber"
|
4
|
+
require "cucumber/feature_file"
|
5
|
+
require "cucumber/formatter/pretty"
|
6
|
+
require "set"
|
7
|
+
|
8
|
+
require "cuketagger/version"
|
9
|
+
require "cuketagger/tag_formatter"
|
10
|
+
require "cuketagger/tagger"
|
11
|
+
|
12
|
+
module CukeTagger
|
13
|
+
def self.log(*args)
|
14
|
+
File.open("/tmp/cuketagger.log", "a") { |file| file.puts args.inspect } if $DEBUG
|
15
|
+
end
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cuketagger
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "0.8"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jari
|
8
|
+
- Bakken
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2009-10-07 00:00:00 +02:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: cucumber
|
18
|
+
type: :runtime
|
19
|
+
version_requirement:
|
20
|
+
version_requirements: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 0.3.103
|
25
|
+
version:
|
26
|
+
description: batch tagging of cucumber features and scenarios
|
27
|
+
email: jari.bakken@gmail.com
|
28
|
+
executables:
|
29
|
+
- cuketagger
|
30
|
+
extensions: []
|
31
|
+
|
32
|
+
extra_rdoc_files: []
|
33
|
+
|
34
|
+
files:
|
35
|
+
- Rakefile
|
36
|
+
- README.markdown
|
37
|
+
- lib/cuketagger/tag_formatter.rb
|
38
|
+
- lib/cuketagger/tagger.rb
|
39
|
+
- lib/cuketagger/version.rb
|
40
|
+
- lib/cuketagger.rb
|
41
|
+
has_rdoc: true
|
42
|
+
homepage: http://cukes.info
|
43
|
+
licenses: []
|
44
|
+
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: "0"
|
55
|
+
version:
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: "0"
|
61
|
+
version:
|
62
|
+
requirements: []
|
63
|
+
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 1.3.5
|
66
|
+
signing_key:
|
67
|
+
specification_version: 3
|
68
|
+
summary: batch tagging of cucumber features and scenarios
|
69
|
+
test_files: []
|
70
|
+
|