cuki 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.5
1
+ 0.0.6
data/cuki.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "cuki"
8
- s.version = "0.0.5"
8
+ s.version = "0.0.6"
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"]
@@ -39,8 +39,10 @@ Gem::Specification.new do |s|
39
39
  "features/push/tables.feature",
40
40
  "features/push/tags.feature",
41
41
  "features/step_defs/pull_steps.rb",
42
+ "features/step_defs/push_steps.rb",
42
43
  "features/support/env.rb",
43
44
  "lib/cuki.rb",
45
+ "lib/pusher.rb",
44
46
  "spec/cuki_spec.rb",
45
47
  "spec/spec_helper.rb"
46
48
  ]
data/cuki.yaml.sample CHANGED
@@ -1,11 +1,10 @@
1
1
  # edit this and save it as config/cuki.yaml
2
2
  # the mappings associate the page IDs on Confluence with local feature files
3
- # the .feature extension is added automatically
4
3
  ---
5
4
  host: http://mywiki
6
5
  tags:
7
6
  draft: "{info:title=Draft version}"
8
7
  signed_off: "{info:title=Signed-off}"
9
8
  mappings:
10
- 123: products/add_product
11
- 124: products/remove_product
9
+ 123: features/products/add_product.feature
10
+ 124: features/products/remove_product.feature
@@ -21,8 +21,8 @@ Feature: Pull
21
21
  ---
22
22
  host: http://example.com
23
23
  mappings:
24
- 123: products/add_product
25
- 456: products/remove_product
24
+ 123: features/products/add_product.feature
25
+ 456: features/products/remove_product.feature
26
26
  """
27
27
  And a Confluence page on "example.com" with id 123:
28
28
  """
@@ -49,7 +49,7 @@ Feature: Pull
49
49
  This feature describes adding a product
50
50
 
51
51
  """
52
- Then the file "features/products/remove_product.feature" should contain exactly:
52
+ And the file "features/products/remove_product.feature" should contain exactly:
53
53
  """
54
54
  Feature: Remove Product
55
55
 
@@ -6,8 +6,8 @@ Feature: Pull single
6
6
  ---
7
7
  host: http://example.com
8
8
  mappings:
9
- 123: products/add_product
10
- 456: products/remove_product
9
+ 123: features/products/add_product.feature
10
+ 456: features/products/remove_product.feature
11
11
  """
12
12
  And a Confluence page on "example.com" with id 123:
13
13
  """
@@ -25,4 +25,5 @@ Feature: Pull single
25
25
  """
26
26
  When I run `cuki pull features/products/add_product.feature`
27
27
  Then a file named "features/products/add_product.feature" should exist
28
- But the file "features/products/remove_product.feature" should not exist
28
+ But the file "features/products/remove_product.feature" should not exist
29
+
@@ -2,13 +2,12 @@
2
2
  Feature: Tables
3
3
 
4
4
  Scenario: Table with more than one column
5
-
6
5
  Given a file named "config/cuki.yaml" with:
7
6
  """
8
7
  ---
9
8
  host: http://example.com
10
9
  mappings:
11
- 123: products/add_product
10
+ 123: features/products/add_product.feature
12
11
  """
13
12
  And a Confluence page on "example.com" with id 123:
14
13
  """
@@ -38,3 +37,4 @@ Feature: Tables
38
37
  | b | 2 |
39
38
 
40
39
  """
40
+
@@ -1,6 +1,6 @@
1
1
  Feature: Tags
2
2
 
3
- Scenario:
3
+ Scenario:
4
4
  Given a file named "config/cuki.yaml" with:
5
5
  """
6
6
  ---
@@ -9,7 +9,7 @@ Feature: Tags
9
9
  draft: "{info:title=Draft version}"
10
10
  signed_off: "{info:title=Signed-off}"
11
11
  mappings:
12
- 123: products/add_product
12
+ 123: features/products/add_product.feature
13
13
  """
14
14
  And a Confluence page on "example.com" with id 123:
15
15
  """
@@ -30,3 +30,4 @@ Feature: Tags
30
30
  Scenario: Foo
31
31
 
32
32
  """
33
+
@@ -6,14 +6,14 @@ Feature: Textile
6
6
  ---
7
7
  host: http://example.com
8
8
  mappings:
9
- 123: products/add_product
9
+ 123: features/products/add_product.feature
10
10
  """
11
11
  And a Confluence page on "example.com" with id 123:
12
12
  """
13
13
  <input id="content-title" value="Add Product">
14
14
  <div id="markupTextarea">
15
15
  h5. Scenario: Foo
16
-
16
+
17
17
  h6. Scenario Outline: Bar
18
18
  </div>
19
19
  """
@@ -26,7 +26,8 @@ Feature: Textile
26
26
 
27
27
 
28
28
  Scenario: Foo
29
-
29
+
30
30
  Scenario Outline: Bar
31
31
 
32
32
  """
33
+
@@ -1,33 +1,28 @@
1
- @pending
2
1
  Feature: Push
3
2
 
4
- Background:
3
+ @focus @pending
4
+ Scenario: Push a feature with no scenarios
5
5
  Given a file named "config/cuki.yaml" with:
6
6
  """
7
7
  ---
8
8
  host: http://mywiki
9
9
  mappings:
10
- 123: products/add_product
10
+ 123: features/products/add_product.feature
11
11
  """
12
-
13
- Scenario: Push a feature with no scenarios
14
- Given a file named "config/cuki.yaml" with:
12
+ And a file named "features/products/add_product.feature" with:
15
13
  """
16
14
  Feature: Hello world & all
17
15
 
18
16
  This is my feature
19
17
  """
20
- When I run `cuki push features/products/add_product.feature`
21
- Then the feature should be pushed to "http://mywiki/pages/editpage.action?pageId=123"
22
- And the Confluence content should be:
18
+ And a Confluence page exists on "mywiki" with id 123, title "Hello world & all" and content:
23
19
  """
24
20
  This is my feature
25
21
  """
26
- And the Confluence title should be:
27
- """
28
- Hello world & all
29
- """
22
+ When I run `cuki push features/products/add_product.feature`
23
+ Then the push should be successful
30
24
 
25
+ @pending
31
26
  Scenario: Push a feature containing a scenario
32
27
  Given a file named "config/cuki.yaml" with:
33
28
  """
@@ -46,6 +41,7 @@ Feature: Push
46
41
  Then something
47
42
  """
48
43
 
44
+ @pending
49
45
  Scenario: Push a feature containing a scenario outline
50
46
 
51
47
  The first row of the examples table should be a header row.
@@ -74,6 +70,7 @@ Feature: Push
74
70
 
75
71
  """
76
72
 
73
+ @pending
77
74
  Scenario: Push a feature containing a scenario outline with multiple example
78
75
  Pending
79
76
 
@@ -0,0 +1,11 @@
1
+ Then /^the feature should be pushed to "([^"]*)" with title "([^"]*)" with:$/ do |url, title, content|
2
+
3
+ @push_stubs ||= []
4
+ @push_stubs << {
5
+ 'url' => url,
6
+ 'title' => title,
7
+ 'content' => content
8
+ }
9
+
10
+ File.open('push_stubs.json', 'w') { |f| f.write @push_stubs.to_json }
11
+ end
@@ -5,5 +5,13 @@ require 'webmock/cucumber'
5
5
 
6
6
  Before do
7
7
  @dirs = ["."]
8
- FileUtils.rm_rf 'features/products'
8
+ cleanup
9
+ end
10
+
11
+ After do
12
+ cleanup
9
13
  end
14
+
15
+ def cleanup
16
+ FileUtils.rm_rf 'features/products'
17
+ end
data/lib/cuki.rb CHANGED
@@ -3,15 +3,12 @@ require 'httpclient'
3
3
  require 'nokogiri'
4
4
  require 'yaml'
5
5
  require 'CGI'
6
- require 'webmock'
7
6
  require 'json'
8
7
 
9
- include WebMock::API
10
- if File.exist?('stubs.json')
11
- stubs = JSON.parse(File.open('stubs.json').read)
12
- stubs.each_pair do |url, body|
13
- stub_request(:get, url).to_return(:status => 200, :body => body, :headers => {})
14
- end
8
+ # terrible hack
9
+ if File.exist?('stubs.json') || File.exist?('stubs.json')
10
+ require 'webmock'
11
+ include WebMock::API
15
12
  end
16
13
 
17
14
  class Cuki
@@ -23,32 +20,26 @@ class Cuki
23
20
  end
24
21
 
25
22
  def initialize(args)
26
- if args.empty?
27
- puts "No action given"
28
- exit(1)
29
- end
30
- parse_config_file
23
+ validate_args args
24
+ read_config
25
+ configure_http_client
26
+
31
27
  action = args.first
32
28
  if 'pull' == action
29
+ configure_pull_stubs
33
30
  verify_project
34
- configure_http_client
35
31
  file = args[1]
36
32
  if file
37
- puts "got file: #{file}"
38
- key = file.gsub('features/', '').gsub('.feature', '')
39
- puts "key: #{key}"
40
- id = @config['mappings'].invert[key]
41
- filepath = key
42
- process_feature id, filepath
33
+ id = @config['mappings'].invert[file]
34
+ raise "could not get id for #{file}"
35
+ pull_feature id, file
43
36
  else
44
- @config['mappings'].each { |id, filepath| process_feature id, filepath }
37
+ @config['mappings'].each { |id, filepath| pull_feature id, filepath }
45
38
  end
46
39
  #autoformat
47
40
  elsif 'push' == action
48
- feature_to_be_pushed = args[1] # e.g. features/products/add_product.feature
49
- feature_as_in_yaml = feature_to_be_pushed.gsub('features/', '').gsub('.feature', '')
50
- id = @config['mappings'].invert[feature_as_in_yaml]
51
- raise "No mapping found for #{feature_as_in_yaml}" unless id
41
+ configure_push_stubs
42
+ Pusher.push file, @config
52
43
  else
53
44
  puts "Unknown action '#{action}"
54
45
  exit(1)
@@ -63,7 +54,7 @@ class Cuki
63
54
  #autoformat
64
55
  end
65
56
 
66
- def parse_config_file
57
+ def read_config
67
58
  unless File.exist?(CONFIG_PATH)
68
59
  puts "No config file found at #{CONFIG_PATH}"
69
60
  exit(1)
@@ -79,7 +70,7 @@ class Cuki
79
70
  @client.ssl_config.set_client_cert_file(ENV['PEM'], ENV['PEM']) if ENV['PEM']
80
71
  end
81
72
 
82
- def process_feature(id, filepath)
73
+ def pull_feature(id, filepath)
83
74
  @content = ''
84
75
  wiki_link = @config['host'] + '/pages/editpage.action?pageId=' + id.to_s
85
76
  puts "Downloading #{wiki_link}"
@@ -141,15 +132,44 @@ class Cuki
141
132
  end
142
133
 
143
134
  def save_file(filepath)
144
- full_filepath = "features/#{filepath}.feature"
145
- dir_path = File.dirname(full_filepath)
135
+ dir_path = File.dirname(filepath)
146
136
 
147
137
  Dir.mkdir(dir_path) unless File.exists?(dir_path)
148
138
 
149
- File.open(full_filepath, 'w') do |f|
150
- puts "Writing #{full_filepath}"
139
+ File.open(filepath, 'w') do |f|
140
+ puts "Writing #{filepath}"
151
141
  f.puts @content
152
142
  end
153
143
  end
154
144
 
145
+ def configure_pull_stubs
146
+ if File.exist?('stubs.json')
147
+ stubs = JSON.parse(File.open('stubs.json').read)
148
+ stubs.each_pair do |url, body|
149
+ stub_request(:get, url).to_return(:status => 200, :body => body, :headers => {})
150
+ end
151
+ FileUtils.rm 'stubs.json'
152
+ end
153
+ end
154
+
155
+ def configure_push_stubs
156
+ if File.exist?('push_stubs.json')
157
+ stubs = JSON.parse(File.open('push_stubs.json').read)
158
+ stubs.each do |a|
159
+ stub_request(:post, "http://mywiki/").
160
+ with(:body => {"title" => a['title'], "content"=> "\n\n" + a['content']},
161
+ :headers => {'Content-Type'=>'application/x-www-form-urlencoded'}).
162
+ to_return(:status => 200, :body => "", :headers => {})
163
+ end
164
+ FileUtils.rm 'push_stubs.json'
165
+ end
166
+ end
167
+
168
+ def validate_args args
169
+ if args.empty?
170
+ puts "No action given"
171
+ exit(1)
172
+ end
173
+ end
174
+
155
175
  end
data/lib/pusher.rb ADDED
@@ -0,0 +1,12 @@
1
+ class Pusher
2
+
3
+ def self.push(feature_to_be_pushed, config)
4
+
5
+ id = config['mappings'].invert[feature_to_be_pushed]
6
+ raise "No mapping found for #{feature_to_be_pushed}" unless id
7
+
8
+ content = File.open(feature_to_be_pushed).read.gsub(/Feature: .*/, '')
9
+ title = File.open(feature_to_be_pushed).read.match(/Feature: (.*)/)[1]
10
+ response = @client.post(config['host'], {:title => title, :content => content})
11
+
12
+ 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: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 5
10
- version: 0.0.5
9
+ - 6
10
+ version: 0.0.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andy Waite
@@ -150,8 +150,10 @@ files:
150
150
  - features/push/tables.feature
151
151
  - features/push/tags.feature
152
152
  - features/step_defs/pull_steps.rb
153
+ - features/step_defs/push_steps.rb
153
154
  - features/support/env.rb
154
155
  - lib/cuki.rb
156
+ - lib/pusher.rb
155
157
  - spec/cuki_spec.rb
156
158
  - spec/spec_helper.rb
157
159
  homepage: http://github.com/andyw8/cuki