jarib-cuketagger 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/cuketagger +124 -0
- metadata +64 -0
data/bin/cuketagger
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
require "cucumber"
|
5
|
+
require "cucumber/feature_file"
|
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
|
+
# TODO: use optparse?
|
21
|
+
args.each do |arg|
|
22
|
+
case arg
|
23
|
+
when /^(.+?\.feature)(:\d+)?$/
|
24
|
+
add_feature($1, $2)
|
25
|
+
when /^(add|remove):(.+?)$/
|
26
|
+
alterations << added = [$1.to_sym, $2]
|
27
|
+
when /^(-f|--force)$/
|
28
|
+
opts[:autoformat] = "."
|
29
|
+
opts[:source] = false
|
30
|
+
Term::ANSIColor.coloring = false
|
31
|
+
else
|
32
|
+
abort(USAGE)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
features.accept TagVisitor.new(self, step_mother, $stdout, opts)
|
37
|
+
end
|
38
|
+
|
39
|
+
def process(feature, element, tag_names)
|
40
|
+
return unless should_alter?(feature, element)
|
41
|
+
|
42
|
+
alterations.each do |op, tag_name|
|
43
|
+
case op
|
44
|
+
when :add
|
45
|
+
tag_names.push tag_name
|
46
|
+
when :remove
|
47
|
+
tag_names.delete tag_name
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def should_alter?(feature, element)
|
53
|
+
line = element ? element.line : 0
|
54
|
+
success = features_to_change.include? [feature.file, line]
|
55
|
+
|
56
|
+
if $DEBUG
|
57
|
+
p :feature_class => feature.class, :element_class => element.class, :line => line, :success => success
|
58
|
+
p :features_to_change => features_to_change
|
59
|
+
end
|
60
|
+
|
61
|
+
success
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def add_feature(path, line)
|
67
|
+
ff = Cucumber::FeatureFile.new(path).parse(step_mother, {})
|
68
|
+
features_to_change << [path, line.to_s[1,line.length].to_i]
|
69
|
+
features.add_feature ff
|
70
|
+
end
|
71
|
+
|
72
|
+
def step_mother
|
73
|
+
@step_mother ||= Cucumber::StepMother.new
|
74
|
+
end
|
75
|
+
|
76
|
+
def features
|
77
|
+
@features ||= Cucumber::Ast::Features.new
|
78
|
+
end
|
79
|
+
|
80
|
+
def alterations
|
81
|
+
@alterations ||= Set.new
|
82
|
+
end
|
83
|
+
|
84
|
+
def features_to_change
|
85
|
+
@features_to_change ||= Set.new
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
class TagVisitor < Cucumber::Formatter::Pretty
|
91
|
+
|
92
|
+
def initialize(tagger, step_mother, io, options)
|
93
|
+
@tagger = tagger
|
94
|
+
super(step_mother, io, options)
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
def visit_feature(feature)
|
99
|
+
@current_feature = feature
|
100
|
+
super
|
101
|
+
end
|
102
|
+
|
103
|
+
def visit_feature_element(element)
|
104
|
+
@current_element = element
|
105
|
+
super
|
106
|
+
@current_element = nil
|
107
|
+
end
|
108
|
+
|
109
|
+
def visit_tags(tags)
|
110
|
+
@tagger.process(@current_feature, @current_element, tags.instance_variable_get("@tag_names"))
|
111
|
+
super
|
112
|
+
end
|
113
|
+
|
114
|
+
private
|
115
|
+
|
116
|
+
def record_tag_occurrences(*args)
|
117
|
+
# override to avoid error if options[:include_tags] is nil
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
if __FILE__ == $0
|
123
|
+
Tagger.execute(ARGV)
|
124
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jarib-cuketagger
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "0.2"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jari
|
8
|
+
- Bakken
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2009-08-21 00:00:00 -07:00
|
14
|
+
default_executable: cuketagger
|
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.96
|
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
|
+
- bin/cuketagger
|
36
|
+
has_rdoc: false
|
37
|
+
homepage: http://cukes.info
|
38
|
+
licenses:
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: "0"
|
49
|
+
version:
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: "0"
|
55
|
+
version:
|
56
|
+
requirements: []
|
57
|
+
|
58
|
+
rubyforge_project:
|
59
|
+
rubygems_version: 1.3.5
|
60
|
+
signing_key:
|
61
|
+
specification_version: 3
|
62
|
+
summary: batch tagging of cucumber features and scenarios
|
63
|
+
test_files: []
|
64
|
+
|