jarib-cuketagger 0.3 → 0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +8 -0
- data/Rakefile +43 -0
- data/bin/cuketagger +2 -118
- data/lib/cuketagger/tag_visitor.rb +28 -0
- data/lib/cuketagger/tagger.rb +87 -0
- data/lib/cuketagger/version.rb +3 -0
- data/lib/cuketagger.rb +12 -0
- metadata +9 -2
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,43 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "rake/clean"
|
4
|
+
require "rake/gempackagetask"
|
5
|
+
require "lib/cuketagger/version"
|
6
|
+
CLEAN.include %w[pkg]
|
7
|
+
|
8
|
+
GEM_NAME = "cuketagger"
|
9
|
+
GEM_VERSION = CukeTagger::Version
|
10
|
+
|
11
|
+
spec = Gem::Specification.new do |s|
|
12
|
+
s.name = GEM_NAME
|
13
|
+
s.version = GEM_VERSION
|
14
|
+
s.has_rdoc = false
|
15
|
+
s.summary = "batch tagging of cucumber features and scenarios"
|
16
|
+
s.description = s.summary
|
17
|
+
s.authors = %w[Jari Bakken]
|
18
|
+
s.email = "jari.bakken@gmail.com"
|
19
|
+
s.homepage = "http://cukes.info"
|
20
|
+
s.files = %w[Rakefile README.markdown] + Dir['lib/**/*']
|
21
|
+
s.bindir = 'bin'
|
22
|
+
s.executables = Dir['bin/*'].map { |f| File.basename(f) }
|
23
|
+
s.add_runtime_dependency 'cucumber', '>= 0.3.96'
|
24
|
+
end
|
25
|
+
|
26
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
27
|
+
pkg.gem_spec = spec
|
28
|
+
end
|
29
|
+
|
30
|
+
namespace :gem do
|
31
|
+
desc "install the gem locally"
|
32
|
+
task :install => [:package] do
|
33
|
+
sh %{sudo #{Gem.ruby} -S gem install pkg/#{GEM_NAME}-#{GEM_VERSION}}
|
34
|
+
end
|
35
|
+
|
36
|
+
desc "Create a .gemspec file"
|
37
|
+
task :spec do
|
38
|
+
file = "#{GEM_NAME.downcase}.gemspec"
|
39
|
+
File.unlink file if ::File.exists?(file)
|
40
|
+
File.open(file, "w+") { |f| f << spec.to_ruby }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
data/bin/cuketagger
CHANGED
@@ -1,121 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# encoding: utf-8
|
3
3
|
|
4
|
-
require "
|
5
|
-
|
6
|
-
require "cucumber/formatter/pretty"
|
7
|
-
require "set"
|
8
|
-
|
9
|
-
class Tagger
|
10
|
-
USAGE = "#{File.basename $0} [-f|--force] [add|remove]:TAG [FILE[:LINE]]+"
|
11
|
-
|
12
|
-
def self.execute(args)
|
13
|
-
new.execute(args)
|
14
|
-
end
|
15
|
-
|
16
|
-
def execute(args)
|
17
|
-
abort(USAGE) if args.empty? || args.first =~ /^(-h|--help)$/
|
18
|
-
opts = {:dry_run => true, :source => true}
|
19
|
-
|
20
|
-
args.each do |arg|
|
21
|
-
case arg
|
22
|
-
when /^(.+?\.feature)(:\d+)?$/
|
23
|
-
add_feature($1, $2)
|
24
|
-
when /^(add|remove):(.+?)$/
|
25
|
-
alterations << [$1.to_sym, $2]
|
26
|
-
when /^(-f|--force)$/
|
27
|
-
opts[:autoformat] = "."
|
28
|
-
opts[:source] = false
|
29
|
-
Term::ANSIColor.coloring = false
|
30
|
-
else
|
31
|
-
abort(USAGE)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
features.accept TagVisitor.new(self, step_mother, $stdout, opts)
|
36
|
-
end
|
37
|
-
|
38
|
-
def process(feature, element, tag_names)
|
39
|
-
return unless should_alter?(feature, element)
|
40
|
-
|
41
|
-
alterations.each do |op, tag_name|
|
42
|
-
case op
|
43
|
-
when :add
|
44
|
-
tag_names.push tag_name
|
45
|
-
when :remove
|
46
|
-
tag_names.delete tag_name
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def should_alter?(feature, element)
|
52
|
-
line = element ? element.line : 0
|
53
|
-
success = features_to_change.include? [feature.file, line]
|
54
|
-
|
55
|
-
if $DEBUG
|
56
|
-
p :feature_class => feature.class, :element_class => element.class, :line => line, :success => success
|
57
|
-
p :features_to_change => features_to_change
|
58
|
-
end
|
59
|
-
|
60
|
-
success
|
61
|
-
end
|
62
|
-
|
63
|
-
private
|
64
|
-
|
65
|
-
def add_feature(path, line)
|
66
|
-
ff = Cucumber::FeatureFile.new(path).parse(step_mother, {})
|
67
|
-
features_to_change << [path, line.to_s[1,line.length].to_i]
|
68
|
-
features.add_feature ff
|
69
|
-
end
|
70
|
-
|
71
|
-
def step_mother
|
72
|
-
@step_mother ||= Cucumber::StepMother.new
|
73
|
-
end
|
74
|
-
|
75
|
-
def features
|
76
|
-
@features ||= Cucumber::Ast::Features.new
|
77
|
-
end
|
78
|
-
|
79
|
-
def alterations
|
80
|
-
@alterations ||= Set.new
|
81
|
-
end
|
82
|
-
|
83
|
-
def features_to_change
|
84
|
-
@features_to_change ||= Set.new
|
85
|
-
end
|
86
|
-
|
87
|
-
end
|
88
|
-
|
89
|
-
class TagVisitor < Cucumber::Formatter::Pretty
|
90
|
-
|
91
|
-
def initialize(tagger, step_mother, io, options)
|
92
|
-
@tagger = tagger
|
93
|
-
super(step_mother, io, options)
|
94
|
-
end
|
95
|
-
|
96
|
-
|
97
|
-
def visit_feature(feature)
|
98
|
-
@current_feature = feature
|
99
|
-
super
|
100
|
-
end
|
101
|
-
|
102
|
-
def visit_feature_element(element)
|
103
|
-
@current_element = element
|
104
|
-
super
|
105
|
-
@current_element = nil
|
106
|
-
end
|
107
|
-
|
108
|
-
def visit_tags(tags)
|
109
|
-
@tagger.process(@current_feature, @current_element, tags.instance_variable_get("@tag_names"))
|
110
|
-
super
|
111
|
-
end
|
112
|
-
|
113
|
-
private
|
114
|
-
|
115
|
-
def record_tag_occurrences(*args)
|
116
|
-
# override to avoid error if options[:include_tags] is nil
|
117
|
-
end
|
118
|
-
|
119
|
-
end
|
120
|
-
|
121
|
-
Tagger.execute(ARGV)
|
4
|
+
require "#{File.dirname(__FILE__)}/../lib/cuketagger"
|
5
|
+
CukeTagger::Tagger.execute(ARGV)
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module CukeTagger
|
2
|
+
module TagVisitor
|
3
|
+
attr_accessor :tagger
|
4
|
+
|
5
|
+
def visit_feature(feature)
|
6
|
+
@current_feature = feature
|
7
|
+
super
|
8
|
+
end
|
9
|
+
|
10
|
+
def visit_feature_element(element)
|
11
|
+
@current_element = element
|
12
|
+
super
|
13
|
+
@current_element = nil
|
14
|
+
end
|
15
|
+
|
16
|
+
def visit_tags(tags)
|
17
|
+
@tagger.process(@current_feature, @current_element, tags.instance_variable_get("@tag_names"))
|
18
|
+
super
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def record_tag_occurrences(*args)
|
24
|
+
# override to avoid error if options[:include_tags] is nil
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
module CukeTagger
|
2
|
+
class Tagger
|
3
|
+
USAGE = "#{File.basename $0} [-v|--version] [-f|--force] [add|remove]:TAG [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
|
+
args.each do |arg|
|
14
|
+
case arg
|
15
|
+
when /^-v|--version$/
|
16
|
+
puts CukeTagger::Version
|
17
|
+
when /^(.+?\.feature)(:\d+)?$/
|
18
|
+
add_feature($1, $2.to_s)
|
19
|
+
when /^(add|remove):(.+?)$/
|
20
|
+
alterations << [$1.to_sym, $2]
|
21
|
+
when /^(-f|--force)$/
|
22
|
+
opts[:autoformat] = "."
|
23
|
+
opts[:source] = false
|
24
|
+
Term::ANSIColor.coloring = false
|
25
|
+
else
|
26
|
+
abort(USAGE)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
formatter = Cucumber::Formatter::Pretty.new(step_mother, $stdout, opts)
|
31
|
+
formatter.extend(TagVisitor)
|
32
|
+
formatter.tagger = self
|
33
|
+
|
34
|
+
features.accept formatter
|
35
|
+
end
|
36
|
+
|
37
|
+
def process(feature, element, tag_names)
|
38
|
+
return unless should_alter?(feature, element)
|
39
|
+
|
40
|
+
alterations.each do |op, tag_name|
|
41
|
+
case op
|
42
|
+
when :add
|
43
|
+
tag_names.push tag_name
|
44
|
+
when :remove
|
45
|
+
tag_names.delete tag_name
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def should_alter?(feature, element)
|
51
|
+
line = element ? element.line : 0
|
52
|
+
success = features_to_change.include? [feature.file, line]
|
53
|
+
|
54
|
+
if $DEBUG
|
55
|
+
p :feature_class => feature.class, :element_class => element.class, :line => line, :success => success
|
56
|
+
p :features_to_change => features_to_change
|
57
|
+
end
|
58
|
+
|
59
|
+
success
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def add_feature(path, line)
|
65
|
+
ff = Cucumber::FeatureFile.new(path).parse(step_mother, {})
|
66
|
+
features_to_change << [path, line[1,line.length].to_i]
|
67
|
+
features.add_feature ff
|
68
|
+
end
|
69
|
+
|
70
|
+
def step_mother
|
71
|
+
@step_mother ||= Cucumber::StepMother.new
|
72
|
+
end
|
73
|
+
|
74
|
+
def features
|
75
|
+
@features ||= Cucumber::Ast::Features.new
|
76
|
+
end
|
77
|
+
|
78
|
+
def alterations
|
79
|
+
@alterations ||= Set.new
|
80
|
+
end
|
81
|
+
|
82
|
+
def features_to_change
|
83
|
+
@features_to_change ||= Set.new
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
end
|
data/lib/cuketagger.rb
ADDED
@@ -0,0 +1,12 @@
|
|
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_visitor"
|
10
|
+
require "cuketagger/tagger"
|
11
|
+
|
12
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jarib-cuketagger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: "0.
|
4
|
+
version: "0.4"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jari
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2009-08-
|
13
|
+
date: 2009-08-23 00:00:00 -07:00
|
14
14
|
default_executable: cuketagger
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -32,6 +32,13 @@ extensions: []
|
|
32
32
|
extra_rdoc_files: []
|
33
33
|
|
34
34
|
files:
|
35
|
+
- Rakefile
|
36
|
+
- README.markdown
|
37
|
+
- lib/cuketagger
|
38
|
+
- lib/cuketagger/tag_visitor.rb
|
39
|
+
- lib/cuketagger/tagger.rb
|
40
|
+
- lib/cuketagger/version.rb
|
41
|
+
- lib/cuketagger.rb
|
35
42
|
- bin/cuketagger
|
36
43
|
has_rdoc: false
|
37
44
|
homepage: http://cukes.info
|