stddtool 0.2.0.1 → 0.3.0.1

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/objects.rb +94 -0
  3. data/lib/stddtool.rb +132 -105
  4. metadata +7 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fac96c7c24541622c6fcfe701d73c106ae143064
4
- data.tar.gz: f027bdf2ba5cc8c645a0886829d130446fd5920b
3
+ metadata.gz: 077fd40fe9c43147cf5fb0ca724a2e387d5867bd
4
+ data.tar.gz: 0cdcb5a34b8695185588b153317aa08d2f76dbdc
5
5
  SHA512:
6
- metadata.gz: 09176bf4f77b85f35715400e0a770448b7b606412e35888752566add9b3037546a37ec837afe8e2e45faa5d0cea158bc90a41416be8c5d5c08c10ae6bbc9b944
7
- data.tar.gz: 6500e54ae3b68e693b61240a2e7d3d6f7fdb03b7118f98fdf56eadcef2ab11883a726405b1a6233a2d0b9a740007b6d92ac9b4c18af2113fba04d760cd6e6ea4
6
+ metadata.gz: b170a4f3f2d4eaa474943f5a30dcc45fda584c7b7d655ae6689bd84e8819eb780f2a057d732f2100004f4b156b58bce020d4e761e9a3e0a686495852f4b063e0
7
+ data.tar.gz: e63220e45323fc4da1e4e3eee97aaf6722fca36d17523d5d0c66868dc6e710447b09568e5640f0863fba6667cccb2c5ce8a5c33364bd69b1015a1b6d47951424
data/lib/objects.rb ADDED
@@ -0,0 +1,94 @@
1
+ # encoding: utf-8
2
+
3
+ class FeatureObj
4
+ def initialize(job,build,title,description,file,tags,runId)
5
+ @id = title.downcase.gsub(' ', '-')
6
+ @job = job
7
+ @build = build
8
+ @feature_title=title
9
+ @feature_description = description
10
+ @feature_file = file
11
+ @runID = runId
12
+
13
+ tagArr = Array.new
14
+ tags.each do |tag|
15
+ tagArr.push({'name' => tag})
16
+ end
17
+
18
+ @feature_tags = tagArr
19
+
20
+ end
21
+ attr_accessor :feature_title
22
+ def to_json
23
+ {
24
+ 'id' => @id,
25
+ 'job' => @job,
26
+ 'build' => @build,
27
+ 'runID' => @runID,
28
+ 'title' => @feature_title,
29
+ 'description' => @feature_description ,
30
+ 'file' => @feature_file,
31
+ 'tags' => @feature_tags,
32
+ }.to_json
33
+ end
34
+ end
35
+
36
+
37
+ class StepObj
38
+ def initialize(keyword, name, status,exception,duration,messages)
39
+ @step_keyword=keyword
40
+ @step_name=name
41
+ @step_status=status
42
+ @step_exception = exception
43
+ @step_duration = duration
44
+ @step_messages = messages
45
+ end
46
+ attr_accessor :step_name
47
+ def to_json
48
+ {'$addToSet' =>
49
+ {'steps' =>{'keyword' => @step_keyword,
50
+ 'name' => @step_name ,
51
+ 'result' => {'status' =>@step_status,'error_message'=> @step_exception,'duration'=>@step_duration},
52
+ 'messages' => @step_messages
53
+ }
54
+ }
55
+ }.to_json
56
+ end
57
+ end
58
+
59
+ class FeatureElement
60
+ def initialize()
61
+ tags = Array.new
62
+ end
63
+ attr_accessor :feature_ID,:keyword,:tags,:name
64
+ def to_json
65
+ {'featureId' => @feature_ID,'keyword' => @keyword, 'name' => @name,'tags' => @tags}.to_json
66
+ end
67
+ end
68
+
69
+ class EmbeddingObj
70
+ def initialize(mime_type,data)
71
+ @mime_type = mime_type
72
+ @data=data
73
+ end
74
+ def to_json
75
+ {'$addToSet' =>{'embeddings' =>{'mime_type' => @mime_type,'data' => @data}}}.to_json
76
+ end
77
+ end
78
+
79
+ # class ScenarioExampleCell
80
+ # def initialize(row,value,status)
81
+ # @row = row
82
+ # @value=value
83
+ # @status=status
84
+ # end
85
+ # def to_json
86
+ # {"$addToSet" =>
87
+ # {"outline.#{@row.to_s}" =>{
88
+ # "value" => @value,
89
+ # "status" => @status
90
+ # }
91
+ # }
92
+ # }.to_json
93
+ # end
94
+ # end
data/lib/stddtool.rb CHANGED
@@ -7,27 +7,33 @@ require 'cucumber/formatter/io'
7
7
  require 'gherkin/formatter/argument'
8
8
  require 'base64'
9
9
 
10
+ require 'objects'
11
+
10
12
  class STDDTool
11
13
 
12
14
  def initialize(step_mother, io, options)
13
15
  @buildnr = ENV['BUILD']
14
16
  @job = ENV['JOB']
15
- @url = ENV['STDD_URL'] ? ENV['STDD_URL'] : ['www.stddtool.se']
17
+ @url = ENV['STDD_URL'] ? ENV['STDD_URL'] : ['http://www.stddtool.se']
16
18
  @proxy = ENV['http_proxy'] ? URI.parse('http://'+ENV['http_proxy']) : OpenStruct.new
17
19
  # Generate string as runId
18
20
  o = [('a'..'z'), ('A'..'Z')].map { |i| i.to_a }.flatten
19
21
  @runID = (0...50).map{ o[rand(o.length)] }.join
20
22
  @delayed_messages = []
21
23
  p @runID
24
+ @connectionError = nil
22
25
  p "Initiating STDDTool(#{@url}) formatter for #{@job} : #{@buildnr}"
26
+ @inside_outline = false
23
27
  end
24
28
 
25
29
  def embed(src, mime_type, label)
26
30
  p "got embedding"
27
31
  case(mime_type)
28
32
  when /^image\/(png|gif|jpg|jpeg)/
33
+ p "Encoding image from #{src}"
29
34
  buf = Base64.encode64(open(src) { |io| io.read })
30
35
  embeddingObj=EmbeddingObj.new(mime_type,buf)
36
+
31
37
  p "starts to post embedding"
32
38
  postEmbedding(@scenarioID,embeddingObj)
33
39
  p "posted embedding to scenario with id : #{@scenarioID}"
@@ -44,15 +50,24 @@ require 'base64'
44
50
  # puts feature.source_tag_names
45
51
  featureObj=FeatureObj.new(@job,@buildnr,feature.title,feature.description,feature.file,feature.source_tag_names,@runID)
46
52
  postFeature(featureObj)
53
+
54
+ @feature_element = FeatureElement.new
55
+ @feature_element.tags = Array.new
56
+ @feature_element.feature_ID = @featureID
57
+
58
+ end
59
+
60
+ def tag_name(tag_name)
61
+ @feature_element ? @feature_element.tags.push({'name' => tag_name}) : true
47
62
  end
48
63
 
49
64
  def before_background(background)
50
65
  # @in_background = true
51
- end
66
+ end
52
67
 
53
- def after_background(background)
54
- # @in_background = nil
55
- end
68
+ def after_background(background)
69
+ # @in_background = nil
70
+ end
56
71
 
57
72
  def before_step(step)
58
73
  @delayed_messages = []
@@ -66,54 +81,124 @@ require 'base64'
66
81
 
67
82
  def background_name(keyword, name, file_colon_line, source_indent)
68
83
  p "Background #{name}"
69
- scenarioObj=ScenarioObj.new(@featureID,keyword,name)
70
- postScenario(scenarioObj)
84
+ @feature_element.name=name
85
+ @feature_element.keyword = keyword
86
+ postFeatureElement(@feature_element)
71
87
  end
72
88
 
73
89
  def scenario_name(keyword, name, file_colon_line, source_indent)
74
90
  p "scenario #{name}"
75
- scenarioObj=ScenarioObj.new(@featureID,keyword,name)
76
- postScenario(scenarioObj)
91
+ @feature_element.name=name
92
+ @feature_element.keyword = keyword
93
+ postFeatureElement(@feature_element)
77
94
  end
78
95
 
79
-
80
96
  def after_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background, file_colon_line)
81
- # if @in_background == true
82
- # # do nothing. background gets reported as step anyway
83
- # else
84
- step_name = step_match.format_args(lambda{|param| "*#{param}*"})
85
- # message = "#{step_name} #{status}"
86
- # puts keyword + " " + message
97
+ step_name = step_match.format_args(lambda{|param| "*#{param}*"})
87
98
  stepObj=StepObj.new(keyword,step_name,status,exception, @duration,@delayed_messages)
88
99
  postStep(@scenarioID,stepObj)
89
100
  #end
90
101
  end
91
102
 
92
103
  def postFeature(featureObj)
93
- uri = URI.parse(@url)
94
- http = Net::HTTP::Proxy(@proxy.host, @proxy.port).new(uri.host, uri.port)
95
- request = Net::HTTP::Post.new("/collectionapi/features")
96
- request.add_field('X-Auth-Token', '97f0ad9e24ca5e0408a269748d7fe0a0')
97
- request.body = featureObj.to_json
98
- response = http.request(request)
99
- case response.code
100
- when /20\d/
101
- #success
102
- else
103
- p response.body
104
- exit
104
+ if @connectionError
105
+ p "FEATURE WILL NOT BE REPORTED TO STDDTOOL DUE TO : #{@connectionError}"
106
+ return
105
107
  end
106
- parsed = JSON.parse(response.body)
107
108
 
108
- if parsed["error"]
109
- p parsed["error"]
109
+ p "posting feature #{featureObj.feature_title}"
110
+ uri = URI.parse(@url)
111
+ begin
112
+ http = Net::HTTP::Proxy(@proxy.host, @proxy.port).new(uri.host, uri.port)
113
+ request = Net::HTTP::Post.new("/collectionapi/features")
114
+ request.add_field('X-Auth-Token', '97f0ad9e24ca5e0408a269748d7fe0a0')
115
+ request.body = featureObj.to_json
116
+ response = http.request(request)
117
+ case response.code
118
+ when /20\d/
119
+ #success
120
+ else
121
+ p response.body
122
+ @connectionError = response.body
123
+ p @connectionError
124
+ end
125
+
126
+ parsed = JSON.parse(response.body)
127
+
128
+ if parsed["error"]
129
+ p parsed["error"]
130
+ end
131
+ @featureID = parsed["_id"]
132
+
133
+ rescue
134
+
135
+ @connectionError = "COULD NOT CONNECT TO HOST AT: #{@url}"
136
+ p @connectionError
110
137
  end
111
- @featureID = parsed["_id"]
112
138
 
113
139
  end
114
140
 
141
+ # #additional code for scenario-outline
142
+
143
+ # def before_outline_table(outline_table)
144
+ # p "before outline table"
145
+ # @inside_outline = true
146
+ # @outline_row = 0
147
+ # end
148
+
149
+ # def after_outline_table(outline_table)
150
+ # p "after outline table"
151
+ # @outline_row = nil
152
+ # @inside_outline = false
153
+ # end
154
+
155
+ # def before_examples(examples)
156
+ # @examples_array = Array.new
157
+ # @examplesRowNumber=0;
158
+ # end
159
+
160
+ # def examples_name(keyword, name)
161
+ # p "keyword: #{keyword}"
162
+ # p "name: #{name}"
163
+ # end
164
+
165
+ # # def after_examples_array(arg1)
166
+ # # p "after examples array: #{arg1}"
167
+ # # end
168
+ # def before_table_row(table_row)
169
+ # # @cellArray = Array.new
170
+ # end
171
+
172
+ # def table_cell_value(value, status)
173
+ # scenarioExampleCell=ScenarioExampleCell.new(@examplesRowNumber,value,status)
174
+ # postScenarioExampleCell(@scenarioID,scenarioExampleCell)
175
+ # end
176
+
177
+ # def after_table_row(table_row)
178
+
179
+ # p @cellArray
180
+ # if table_row.exception
181
+ # p "tr exception: #{table_row.exception}"
182
+
183
+ # end
184
+ # p "after table row"
185
+ # if @outline_row
186
+ # @outline_row += 1
187
+ # end
188
+ # @examplesRowNumber = @examplesRowNumber +1
189
+ # end
190
+
191
+ # def after_examples(examples)
192
+ # p "after examples"
193
+ # end
194
+
195
+
196
+
115
197
 
116
198
  def postStep(scenarioID,stepObj)
199
+ return if @connectionError
200
+
201
+ p "posting step #{stepObj.step_name}"
117
202
  uri = URI.parse(@url)
118
203
  path = "/collectionapi/scenarios/#{scenarioID}"
119
204
  req = Net::HTTP::Put.new(path, initheader = { 'X-Auth-Token' => '97f0ad9e24ca5e0408a269748d7fe0a0'})
@@ -122,6 +207,8 @@ require 'base64'
122
207
  end
123
208
 
124
209
  def postEmbedding(scenarioID,embeddingObj)
210
+ return if @connectionError
211
+
125
212
  uri = URI.parse(@url)
126
213
  path = "/collectionapi/scenarios/#{scenarioID}"
127
214
  req = Net::HTTP::Put.new(path, initheader = { 'X-Auth-Token' => '97f0ad9e24ca5e0408a269748d7fe0a0'})
@@ -129,91 +216,31 @@ require 'base64'
129
216
  response = Net::HTTP::Proxy(@proxy.host, @proxy.port).new(uri.host, uri.port).start {|http| http.request(req) }
130
217
  end
131
218
 
132
- def postScenario(scenarioObj)
219
+ def postFeatureElement(feature_element)
220
+ return if @connectionError
221
+
222
+ p "posting featureElement #{feature_element.name}"
133
223
  uri = URI.parse(@url)
134
224
  http = Net::HTTP::Proxy(@proxy.host, @proxy.port).new(uri.host, uri.port)
135
225
  request = Net::HTTP::Post.new("/collectionapi/scenarios")
136
226
  request.add_field('X-Auth-Token', '97f0ad9e24ca5e0408a269748d7fe0a0')
137
- request.body = scenarioObj.to_json
227
+ request.body = feature_element.to_json
138
228
  response = http.request(request)
139
229
  # puts response.body
140
230
  parsed = JSON.parse(response.body)
141
231
  @scenarioID = parsed["_id"]
142
232
  end
143
233
 
144
- end
145
-
146
- class FeatureObj
147
- def initialize(job,build,title,description,file,tags,runId)
148
- @id = title.downcase.gsub(' ', '-')
149
- @job = job
150
- @build = build
151
- @feature_title=title
152
- @feature_description = description
153
- @feature_file = file
154
- @runID = runId
155
-
156
- tagArr = Array.new
157
- tags.each do |tag|
158
- tagArr.push({'name' => tag})
159
- end
160
-
161
- @feature_tags = tagArr
162
-
163
- end
164
- def to_json
165
- {
166
- 'id' => @id,
167
- 'job' => @job,
168
- 'build' => @build,
169
- 'runID' => @runID,
170
- 'title' => @feature_title,
171
- 'description' => @feature_description ,
172
- 'file' => @feature_file,
173
- 'tags' => @feature_tags,
174
- }.to_json
175
- end
176
- end
234
+ # def postScenarioExampleCell(scenarioID,scenarioExampleItem)
235
+ # p "posting postScenarioExampleCell"
236
+ # uri = URI.parse(@url)
237
+ # path = "/collectionapi/scenarios/#{scenarioID}"
238
+ # req = Net::HTTP::Put.new(path, initheader = { 'X-Auth-Token' => '97f0ad9e24ca5e0408a269748d7fe0a0'})
239
+ # req.body = scenarioExampleItem.to_json
240
+ # response = Net::HTTP::Proxy(@proxy.host, @proxy.port).new(uri.host, uri.port).start {|http| http.request(req) }
241
+ # end
177
242
 
178
243
 
179
- class StepObj
180
- def initialize(keyword, name, status,exception,duration,messages)
181
- @step_keyword=keyword
182
- @step_name=name
183
- @step_status=status
184
- @step_exception = exception
185
- @step_duration = duration
186
- @step_messages = messages
187
- end
188
- def to_json
189
- {'$addToSet' =>
190
- {'steps' =>{'keyword' => @step_keyword,
191
- 'name' => @step_name ,
192
- 'result' => {'status' =>@step_status,'error_message'=> @step_exception,'duration'=>@step_duration},
193
- 'messages' => @step_messages
194
- }
195
- }
196
- }.to_json
197
- end
198
- end
199
244
 
200
- class ScenarioObj
201
- def initialize(featureID,keyword, name )
202
- @feature_ID = featureID
203
- @scenario_keyword=keyword
204
- @scenario_name=name
205
- end
206
- def to_json
207
- {'featureId' => @feature_ID,'keyword' => @scenario_keyword, 'name' => @scenario_name}.to_json
208
- end
209
- end
210
245
 
211
- class EmbeddingObj
212
- def initialize(mime_type,data)
213
- @mime_type = mime_type
214
- @data=data
215
- end
216
- def to_json
217
- {'$addToSet' =>{'embeddings' =>{'mime_type' => @mime_type,'data' => @data}}}.to_json
218
- end
219
246
  end
metadata CHANGED
@@ -1,22 +1,25 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stddtool
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0.1
4
+ version: 0.3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Danielsson
8
+ - Anders Åslund
9
+ - Learningwell West
8
10
  autorequire:
9
11
  bindir: bin
10
12
  cert_chain: []
11
- date: 2013-09-09 00:00:00.000000000 Z
13
+ date: 2014-01-29 00:00:00.000000000 Z
12
14
  dependencies: []
13
- description: Cucumber formatter that reports the cucumber-test-results to STDDTool
15
+ description: Cucumber formatter that reports the cucumber testresults to STDDTool
14
16
  email: anton.danielsson@learningwell.se
15
17
  executables: []
16
18
  extensions: []
17
19
  extra_rdoc_files: []
18
20
  files:
19
21
  - lib/stddtool.rb
22
+ - lib/objects.rb
20
23
  homepage: https://github.com/antda/cucumber-stddtool
21
24
  licenses:
22
25
  - MIT
@@ -40,5 +43,5 @@ rubyforge_project:
40
43
  rubygems_version: 2.0.3
41
44
  signing_key:
42
45
  specification_version: 4
43
- summary: Cucumber formatter for STDD-Tool
46
+ summary: Cucumber formatter for STDDTool
44
47
  test_files: []