cuki 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile CHANGED
@@ -9,3 +9,8 @@ group :development do
9
9
  gem "jeweler", "~> 1.6.4"
10
10
  gem "rcov", ">= 0"
11
11
  end
12
+
13
+ group :test do
14
+ gem "rspec"
15
+ gem "cucumber"
16
+ end
data/Gemfile.lock CHANGED
@@ -1,24 +1,46 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
+ builder (3.0.0)
5
+ cucumber (1.1.0)
6
+ builder (>= 2.1.2)
7
+ diff-lcs (>= 1.1.2)
8
+ gherkin (~> 2.5.0)
9
+ json (>= 1.4.6)
10
+ term-ansicolor (>= 1.0.6)
11
+ diff-lcs (1.1.3)
12
+ gherkin (2.5.1)
13
+ json (>= 1.4.6)
4
14
  git (1.2.5)
5
15
  httpclient (2.2.1)
6
16
  jeweler (1.6.4)
7
17
  bundler (~> 1.0)
8
18
  git (>= 1.2.5)
9
19
  rake
20
+ json (1.6.1)
10
21
  nokogiri (1.5.0)
11
22
  rake (0.9.2)
12
23
  rcov (0.9.11)
24
+ rspec (2.6.0)
25
+ rspec-core (~> 2.6.0)
26
+ rspec-expectations (~> 2.6.0)
27
+ rspec-mocks (~> 2.6.0)
28
+ rspec-core (2.6.4)
29
+ rspec-expectations (2.6.0)
30
+ diff-lcs (~> 1.1.2)
31
+ rspec-mocks (2.6.0)
13
32
  shoulda (2.11.3)
33
+ term-ansicolor (1.0.6)
14
34
 
15
35
  PLATFORMS
16
36
  ruby
17
37
 
18
38
  DEPENDENCIES
19
39
  bundler (~> 1.0.0)
40
+ cucumber
20
41
  httpclient
21
42
  jeweler (~> 1.6.4)
22
43
  nokogiri
23
44
  rcov
45
+ rspec
24
46
  shoulda
data/README.rdoc CHANGED
@@ -27,11 +27,11 @@ Cuki expects a configuration file in config/cuki.yml. See the sample provided.
27
27
 
28
28
  Run it from the command line:
29
29
 
30
- bundle exec cuki
30
+ bundle exec cuki pull
31
31
 
32
- or, if using Bundler binstubs:
32
+ or, if using binstubs:
33
33
 
34
- bin/cuki
34
+ bin/cuki pull
35
35
 
36
36
  == Options
37
37
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
data/bin/cuki CHANGED
@@ -2,4 +2,4 @@
2
2
  $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
3
3
  require 'cuki'
4
4
 
5
- Cuki.invoke
5
+ Cuki.invoke(ARGV)
data/cuki.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "cuki"
8
- s.version = "0.0.3"
8
+ s.version = "0.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Andy Waite"]
12
- s.date = "2011-10-14"
12
+ s.date = "2011-10-15"
13
13
  s.description = ""
14
14
  s.email = "andy@andywaite.com"
15
15
  s.executables = ["cuki"]
data/cuki.yaml.sample CHANGED
@@ -2,9 +2,10 @@
2
2
  # the mappings associate the page IDs on Confluence with local feature files
3
3
  # the .feature extension is added automatically
4
4
  ---
5
- base: http://mywiki/pages/editpage.action?pageId=
5
+ host: http://mywiki
6
6
  tags:
7
7
  draft: "{info:title=Draft version}"
8
+ signed_off: "{info:title=Signed-off}"
8
9
  mappings:
9
10
  123: products/add_product
10
11
  124: products/remove_product
data/lib/cuki.rb CHANGED
@@ -6,35 +6,43 @@ require 'CGI'
6
6
 
7
7
  class Cuki
8
8
 
9
- # we're assuming that the acceptance criteria starts at this point and continues to the end of the page
10
- START_INDICATOR = /\d\. \*Specification\*/
9
+ CONFIG_PATH = 'config/cuki.yaml'
11
10
 
12
- def self.invoke
13
- new
11
+ def self.invoke(args)
12
+ new(args)
14
13
  end
15
14
 
16
- def initialize
17
- autoformat
18
- read_config
19
- configure_http_client
20
- @mappings.each { |key, value| process_mapping key, value }
21
- autoformat
15
+ def initialize(args)
16
+ raise "No command given" if args.empty?
17
+ parse_config_file
18
+ command = args.first
19
+ if 'pull' == command
20
+ verify_project
21
+ configure_http_client
22
+ @config['mappings'].each { |id, filepath| process_feature id, filepath }
23
+ autoformat
24
+ elsif 'push' == command
25
+ feature_to_be_pushed = args[1] # e.g. features/products/add_product.feature
26
+ feature_as_in_yaml = feature_to_be_pushed.gsub('features/', '').gsub('.feature', '')
27
+ id = @config['mappings'].invert[feature_as_in_yaml]
28
+ raise "No mapping found for #{feature_as_in_yaml}" unless id
29
+ else
30
+ raise "Unknown command '#{command}"
31
+ end
22
32
  end
23
33
 
24
34
  private
25
35
 
26
- def read_config
27
- config_path = 'config/cuki.yaml'
28
-
29
- config = YAML::load( File.open( config_path ) )
30
-
31
- @base = config["base"]
32
- raise "base not found in #{config_path}" unless @base
33
-
34
- @mappings = config["mappings"]
35
- raise "mappings not found in #{config_path}" unless @mappings
36
-
37
- @tag_mappings = config['tags']
36
+ def verify_project
37
+ # check features folder exists
38
+ raise "features folder not found" unless File.exists?('features')
39
+ autoformat
40
+ end
41
+
42
+ def parse_config_file
43
+ @config = YAML::load( File.open( CONFIG_PATH ) )
44
+ raise "Host not found in #{CONFIG_PATH}" unless @config["host"]
45
+ raise "Mappings not found in #{CONFIG_PATH}" unless @config["mappings"]
38
46
  end
39
47
 
40
48
  def configure_http_client
@@ -43,76 +51,66 @@ class Cuki
43
51
  @client.ssl_config.set_client_cert_file(ENV['PEM'], ENV['PEM']) if ENV['PEM']
44
52
  end
45
53
 
46
- def process_mapping(key, value)
47
- wiki_link = @base + key.to_s
48
-
54
+ def process_feature(id, filepath)
55
+ @content = ''
56
+ wiki_link = @config['host'] + '/pages/editpage.action?pageId=' + id.to_s
49
57
  puts "Downloading #{wiki_link}"
50
-
51
58
  response = @client.get wiki_link
52
-
53
59
  doc = Nokogiri(response.body)
60
+
61
+ process_tags
54
62
 
55
- title = doc.css('title').text
56
-
57
- wiki_text = CGI.unescapeHTML(doc.css('#markupTextarea').text)
58
- wiki_text.gsub(' ', '')
59
-
60
- cuke_text = ''
61
-
62
- tags = []
63
- if @tag_mappings
64
- @tag_mappings.each do |tag, snippet|
65
- tags << "@#{tag}" if wiki_text.include?(snippet)
66
- end
67
- end
68
-
69
- cuke_text += tags.join(' ') + "\n" unless [] == tags
70
-
71
- title = title.split(' - ').first
72
-
73
- # assuming that title is format REF - TITLE - PROJECT NAME - WIKI NAME
74
- cuke_text += "Feature: " + title + "\n\n"
75
-
76
- cuke_text += "#{wiki_link}\n\n"
77
-
78
- if wiki_text.match(START_INDICATOR)
79
- cuke_text += wiki_text.split(START_INDICATOR).last
80
- else
81
- cuke_text += wiki_text.split(START_INDICATOR).last
82
- end
63
+ @content += "Feature: " + doc.at('#content-title')[:value] + "\n\n"
64
+ @content += "#{wiki_link}\n\n"
65
+ @content += CGI.unescapeHTML(doc.css('#markupTextarea').text)
83
66
 
67
+ clean
68
+ save_file filepath
69
+ end
70
+
71
+ def autoformat
72
+ `cucumber -a . --dry-run -P` unless ENV['SKIP_AUTOFORMAT']
73
+ end
74
+
75
+ def clean
76
+
77
+ @content.gsub('&nbsp;', '')
78
+
84
79
  # remove the double pipes used for table headers in Confluence
85
- cuke_text.gsub!('||', '|')
80
+ @content.gsub!('||', '|')
86
81
 
87
82
  # remove other noise
88
- cuke_text.gsub!("\r\n", "\n")
89
- cuke_text.gsub!("\\\\\n", '')
90
- cuke_text.gsub!('\\', '')
83
+ @content.gsub!("\r\n", "\n")
84
+ @content.gsub!("\\\\\n", '')
85
+ @content.gsub!('\\', '')
91
86
 
92
87
  # remove any unwanted headers
93
- cuke_text.gsub!(/h\d\. /, '')
94
-
95
- # remove an other confluence markup
96
- cuke_text.gsub!(/\{.*\}/, '')
97
-
98
- # check features folder exists
99
- raise "features folder not found" unless File.exists?('features')
100
-
101
- file_path = "features/#{value}.feature"
102
- dir_path = File.dirname(file_path)
103
-
104
- unless File.exists?(dir_path)
105
- Dir.mkdir(dir_path)
106
- end
88
+ @content.gsub!(/h\d\. /, '')
107
89
 
108
- File.open(file_path, 'w') do |f|
109
- puts "Writing #{file_path}"
110
- f.puts cuke_text
90
+ # remove any other confluence markup
91
+ @content.gsub!(/\{.*\}/, '')
92
+ end
93
+
94
+ def process_tags
95
+ tags = []
96
+ if @config['tags']
97
+ @config['tags'].each do |tag, snippet|
98
+ tags << "@#{tag}" if @content.include?(snippet)
99
+ end
111
100
  end
101
+ @content += tags.join(' ') + "\n" unless tags.empty?
112
102
  end
113
103
 
114
- def autoformat
115
- `cucumber -a . --dry-run -P` unless ENV['SKIP_AUTOFORMAT']
104
+ def save_file(filepath)
105
+ full_filepath = "features/#{filepath}.feature"
106
+ dir_path = File.dirname(full_filepath)
107
+
108
+ Dir.mkdir(dir_path) unless File.exists?(dir_path)
109
+
110
+ File.open(full_filepath, 'w') do |f|
111
+ puts "Writing #{full_filepath}"
112
+ f.puts @content
113
+ end
116
114
  end
117
115
 
118
116
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cuki
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andy Waite
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-10-14 00:00:00 Z
18
+ date: 2011-10-15 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  requirement: &id001 !ruby/object:Gem::Requirement