stddtool 0.3.1.1 → 0.5.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/stddtool.rb +210 -227
  3. metadata +17 -4
  4. data/lib/objects.rb +0 -94
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f309b34a2bec721ea88a95c4559f89cc5a91f32f
4
- data.tar.gz: c55c4b861c8c1ba71225f6118f40a6b35195895a
3
+ metadata.gz: a76f2860a1034d498debff40c95430820672f253
4
+ data.tar.gz: 763ba36d5c0b9ade26fc7ce5065d635c96853fb5
5
5
  SHA512:
6
- metadata.gz: 13c35af0badc7f4bef1c6f9f7646b28ad8d4e89aba40e2dfbccc64c1e6e0bb2ee2396e30b6107b3afa5d523ba03639bd4f788e1b7dc5383eb665f87e1cd1303f
7
- data.tar.gz: a49a5bad7524f5d3e85df41dc5539f90b8f06621f260a631bb8372b14994b5cce20da530737e6cce166d8a82287d4211094015ab3bb0eefadf6db82df153e02b
6
+ metadata.gz: 762a58b64e6446448b45b6484ee534e071f9ecf4a03dace0bbcf4dda2ec6b64000c0bab46e8b799df29d27e2e5388c8c0d580d91b5b095b59d7dc44a70b90eff
7
+ data.tar.gz: 775638653d5391ef5121b53701ff25e0d1f15f4181c71fba1bed095821e5c32f03e013e5dbf6a7f2444aa8043b4a0eb070240ee30b4a399d59fc746f1ca7ede2
data/lib/stddtool.rb CHANGED
@@ -6,268 +6,251 @@ require 'ostruct'
6
6
  require 'cucumber/formatter/io'
7
7
  require 'gherkin/formatter/argument'
8
8
  require 'base64'
9
- require 'objects'
10
9
  require 'cucumber/ast/scenario_outline'
11
10
  require 'cucumber/ast/scenario'
11
+ require 'stdd_api'
12
12
 
13
- class STDDTool
14
- AST_CLASSES = {
15
- Cucumber::Ast::Scenario => 'scenario',
16
- Cucumber::Ast::ScenarioOutline => 'scenario_outline'
17
- }
18
-
19
- def initialize(step_mother, io, options)
20
- @buildnr = ENV['BUILD']
21
- @job = ENV['JOB']
22
- @url = ENV['STDD_URL'] ? ENV['STDD_URL'] : ['http://www.stddtool.se']
23
- @proxy = ENV['http_proxy'] ? URI.parse('http://'+ENV['http_proxy']) : OpenStruct.new
24
- # Generate string as runId
25
- o = [('a'..'z'), ('A'..'Z')].map { |i| i.to_a }.flatten
26
- @runID = (0...50).map{ o[rand(o.length)] }.join
27
- @delayed_messages = []
28
- p @runID
29
- @connectionError = nil
30
- p "Initiating STDDTool(#{@url}) formatter for #{@job} : #{@buildnr}"
31
- @inside_outline = false
32
- end
33
13
 
34
- def embed(src, mime_type, label)
35
- p "got embedding"
36
- case(mime_type)
37
- when /^image\/(png|gif|jpg|jpeg)/
38
- p "Encoding image from #{src}"
39
- buf = Base64.encode64(open(src,'rb') { |io| io.read })
40
- embeddingObj=EmbeddingObj.new(mime_type,buf)
41
-
42
- p "starts to post embedding"
43
- postEmbedding(@scenarioID,embeddingObj)
44
- p "posted embedding to scenario with id : #{@scenarioID}"
45
- end
46
- end
47
14
 
48
- def puts(message)
49
- @delayed_messages << message
50
- end
51
15
 
16
+ module Cucumber
17
+ module Formatter
18
+ class STDDTool
19
+ include Io
20
+ attr_reader :runtime
52
21
 
22
+ AST_CLASSES = {
23
+ Cucumber::Ast::Scenario => 'scenario',
24
+ Cucumber::Ast::ScenarioOutline => 'scenario_outline'
25
+ }
53
26
 
54
- def before_feature(feature)
55
- # puts feature.source_tag_names
56
- featureObj=FeatureObj.new(@job,@buildnr,feature.title,feature.description,feature.file,feature.source_tag_names,@runID)
57
- postFeature(featureObj)
27
+ def initialize(runtime, path_or_io, options)
28
+ @runtime, @io, @options = runtime, ensure_io(path_or_io, "stddtool"), options
29
+ @delayed_messages = []
30
+ @io.puts @runID
31
+ @connection_error = nil
32
+ @io.puts "Initiating STDDTool(#{@url}) formatter for #{@project} : #{@module}"
33
+ @inside_outline = false
34
+ @io.flush
58
35
 
59
- @feature_element = FeatureElement.new
60
- @feature_element.tags = Array.new
61
- @feature_element.feature_ID = @featureID
36
+ @stdd_client = STDDAPI::Client.new(ENV['STDD_URL'],ENV['http_proxy'])
62
37
 
63
- end
38
+ #Collect all enviroment-variables
39
+ @customer_name = ENV['CUSTOMER']
40
+ @project_name = ENV['PROJECT']
64
41
 
65
- def tag_name(tag_name)
66
- @feature_element ? @feature_element.tags.push({'name' => tag_name}) : true
67
- end
42
+ @run_name = ENV['RUN']
43
+ @run_source = ENV['SOURCE']
44
+ @run_revision = ENV['REV']
68
45
 
69
- def before_background(background)
70
- # @in_background = true
71
- end
46
+ init_customer_project_and_run(@customer_name,@project_name,@run_name,@run_source,@run_revision)
72
47
 
73
- def after_background(background)
74
- # @in_background = nil
75
- end
48
+ @module_name = ENV['MODULE']
49
+ init_module(@module_name)
76
50
 
77
- def before_step(step)
78
- @delayed_messages = []
79
- @start_time = Time.now
80
- end
51
+ end
81
52
 
82
- def before_step_result(*args)
83
- @duration = Time.now - @start_time
84
- end
53
+ def init_module name
54
+ return if @connection_error
55
+ valid,response = @stdd_client.create_module(@run.id,name,'cucumber',Time.now)
56
+ if(valid)
57
+ @module = response
58
+ else
59
+ @connection_error = response
60
+ puts @connection_error
61
+ end
62
+ end
85
63
 
86
- def before_feature_element(feature_element)
87
- @feature_element.element_type = AST_CLASSES[feature_element.class]
88
- end
64
+ def init_customer_project_and_run customer_name, project_name, run_name, run_source, run_revision
65
+ return if @connection_error
66
+ #Customer
67
+ create_customer_if_not_exist(customer_name)
68
+
69
+ #Project
70
+ create_project_if_not_exists(@customer.id,project_name)
71
+
72
+ #Run
73
+ valid, response = @stdd_client.create_run(@project.id,run_name,run_source,run_revision)
74
+ if(valid)
75
+ @run = response
76
+ else
77
+ @connection_error = response
78
+ puts @connection_error
79
+ end
89
80
 
90
- def background_name(keyword, name, file_colon_line, source_indent)
91
- p "Background #{name}"
92
- @feature_element.name=name
93
- @feature_element.keyword = keyword
94
- postFeatureElement(@feature_element)
95
- end
81
+ end
96
82
 
97
- def scenario_name(keyword, name, file_colon_line, source_indent)
98
- p "scenario #{name}"
99
- @feature_element.name=name
100
- @feature_element.keyword = keyword
101
- postFeatureElement(@feature_element)
102
- end
83
+ def create_customer_if_not_exist customer_name
84
+ return if @connection_error
85
+ # Kontrollera om kunden finns
86
+ valid, response = @stdd_client.get_customer customer_name
103
87
 
104
- def after_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background, file_colon_line)
105
- step_name = step_match.format_args(lambda{|param| "*#{param}*"})
106
- stepObj=StepObj.new(keyword,step_name,status,exception, @duration,@delayed_messages)
107
- postStep(@scenarioID,stepObj)
108
- #end
109
- end
88
+ # Om kunden finns
89
+ if(valid && response)
90
+ puts "Customer already exists"
91
+ else
92
+ puts "Customer does not exist, creating new.."
93
+ # Skapa en kund
94
+ valid, response = @stdd_client.create_customer customer_name
95
+ end
96
+
97
+ if(valid)
98
+ @customer = response
99
+ return true
100
+ else
101
+ @connection_error = response
102
+ puts @connection_error
103
+ return false
104
+ end
105
+
106
+ end
107
+
108
+ def create_project_if_not_exists customer_id,project_name
109
+ return if @connection_error
110
+ # Kontrollera om projektet finns
111
+ valid, response = @stdd_client.get_project customer_id, project_name
112
+
113
+ # Om projektet finns
114
+ if(valid)
115
+ puts "Project already exists"
116
+ @project = response
117
+ return true
118
+ end
119
+
120
+ puts "Project does not exist, creating new.."
121
+ # Skapa ett projekt
122
+ valid, response = @stdd_client.create_project customer_id, project_name
123
+ if valid
124
+ @project = response
125
+ return true
126
+ else
127
+ @connection_error = response
128
+ puts @connection_error
129
+ return false
130
+ end
110
131
 
111
- def postFeature(featureObj)
112
- if @connectionError
113
- p "FEATURE WILL NOT BE REPORTED TO STDDTOOL DUE TO : #{@connectionError}"
114
- return
115
132
  end
116
133
 
117
- p "posting feature #{featureObj.feature_title}"
118
- uri = URI.parse(@url)
119
- begin
120
- http = Net::HTTP::Proxy(@proxy.host, @proxy.port).new(uri.host, uri.port)
121
- request = Net::HTTP::Post.new("/collectionapi/features")
122
- request.add_field('X-Auth-Token', '97f0ad9e24ca5e0408a269748d7fe0a0')
123
- request.body = featureObj.to_json
124
- response = http.request(request)
125
- case response.code
126
- when /20\d/
134
+ def embed(src, mime_type, label)
135
+ return if @connection_error
136
+ @io.puts "got embedding"
137
+ case mime_type
138
+ when /^image\/(png|gif|jpg|jpeg)/
139
+ buf = Base64.encode64(open(src,'rb') { |io| io.read })
140
+ embedding=STDDAPI::Objects::Embedding.new(@scenario.id,mime_type,buf)
141
+
142
+ valid,response = @stdd_client.add_embedding_to_scenario(embedding)
143
+ if(valid)
127
144
  #success
128
145
  else
129
- p response.body
130
- @connectionError = response.body
131
- p @connectionError
146
+ @connection_error = response
147
+ puts @connection_error
148
+ end
132
149
  end
150
+ end
133
151
 
134
- parsed = JSON.parse(response.body)
152
+ def before_feature(feature)
153
+ return if @connection_error
154
+ # puts feature.source_tag_names
155
+ @feature = STDDAPI::Objects::Feature.new(@module.id,feature.title,Time.now)
156
+ @feature.description = feature.description
157
+ @feature.tags = feature.source_tag_names
158
+ @feature.file = feature.file
159
+
160
+ valid,response = @stdd_client.create_feature(@feature)
161
+ if(valid)
162
+ @feature.id = response
163
+ else
164
+ @connection_error = response
165
+ puts @connection_error
166
+ end
167
+
168
+ # @feature_element = FeatureElement.new
169
+ # @feature_element.tags = Array.new
170
+ # @feature_element.feature_ID = @featureID
171
+ @scenario = STDDAPI::Objects::Scenario.new(@feature.id, "",'scenario','Scenario')
172
+ @scenario.tags=Array.new
135
173
 
136
- if parsed["error"]
137
- p parsed["error"]
138
174
  end
139
- @featureID = parsed["_id"]
140
175
 
141
- rescue
176
+ def tag_name(tag_name)
177
+ return if @connection_error
178
+ @scenario ? @scenario.tags.push({'name' => tag_name}) : true
179
+ end
142
180
 
143
- @connectionError = "COULD NOT CONNECT TO HOST AT: #{@url}"
144
- p @connectionError
145
- end
181
+ def before_step(step)
182
+ return if @connection_error
183
+ @delayed_messages = []
184
+ @step_start_time = Time.now
185
+ end
146
186
 
147
- end
187
+ def before_step_result(*args)
188
+ return if @connection_error
189
+ @step_duration = Time.now - @step_start_time
190
+ end
148
191
 
192
+ def before_feature_element(feature_element)
193
+ return if @connection_error
194
+ @scenario.element_type = AST_CLASSES[feature_element.class]
195
+ end
149
196
 
150
- # def before_outline_table(outline_table)
151
- # @inside_outline = true
152
- # end
153
-
154
- # def after_outline_table(outline_table)
155
- # @inside_outline = false
156
- # end
157
-
158
- # def before_examples(examples)
159
- # @inside_outline = true
160
- # end
161
-
162
- # def after_examples(examples)
163
- # @inside_outline = false
164
- # end
165
- # def before_table_row(table_row)
166
- # # @cellArray = Array.new
167
- # end
168
-
169
- # #additional code for scenario-outline
170
-
171
- # def before_outline_table(outline_table)
172
- # p "before outline table"
173
- # @inside_outline = true
174
- # @outline_row = 0
175
- # end
176
-
177
- # def after_outline_table(outline_table)
178
- # p "after outline table"
179
- # @outline_row = nil
180
- # @inside_outline = false
181
- # end
182
-
183
- # def before_examples(examples)
184
- # @examples_array = Array.new
185
- # @examplesRowNumber=0;
186
- # end
187
-
188
- # def examples_name(keyword, name)
189
- # p "keyword: #{keyword}"
190
- # p "name: #{name}"
191
- # end
192
-
193
- # # def after_examples_array(arg1)
194
- # # p "after examples array: #{arg1}"
195
- # # end
196
- # def before_table_row(table_row)
197
- # # @cellArray = Array.new
198
- # end
199
-
200
- # def table_cell_value(value, status)
201
- # scenarioExampleCell=ScenarioExampleCell.new(@examplesRowNumber,value,status)
202
- # postScenarioExampleCell(@scenarioID,scenarioExampleCell)
203
- # end
204
-
205
- # def after_table_row(table_row)
206
-
207
- # p @cellArray
208
- # if table_row.exception
209
- # p "tr exception: #{table_row.exception}"
210
-
211
- # end
212
- # p "after table row"
213
- # if @outline_row
214
- # @outline_row += 1
215
- # end
216
- # @examplesRowNumber = @examplesRowNumber +1
217
- # end
218
-
219
- # def after_examples(examples)
220
- # p "after examples"
221
- # end
222
-
223
-
224
-
225
-
226
- def postStep(scenarioID,stepObj)
227
- return if @connectionError
228
-
229
- p "posting step #{stepObj.step_name}"
230
- uri = URI.parse(@url)
231
- path = "/collectionapi/scenarios/#{scenarioID}"
232
- req = Net::HTTP::Put.new(path, initheader = { 'X-Auth-Token' => '97f0ad9e24ca5e0408a269748d7fe0a0'})
233
- req.body = stepObj.to_json
234
- response = Net::HTTP::Proxy(@proxy.host, @proxy.port).new(uri.host, uri.port).start {|http| http.request(req) }
235
- end
197
+ def background_name(keyword, name, file_colon_line, source_indent)
198
+ return if @connection_error
199
+ @io.puts "Background #{name}"
200
+ @scenario.name=name
201
+ @scenario.keyword = keyword
202
+ post_scenario
236
203
 
237
- def postEmbedding(scenarioID,embeddingObj)
238
- return if @connectionError
204
+ end
239
205
 
240
- uri = URI.parse(@url)
241
- path = "/collectionapi/scenarios/#{scenarioID}"
242
- req = Net::HTTP::Put.new(path, initheader = { 'X-Auth-Token' => '97f0ad9e24ca5e0408a269748d7fe0a0'})
243
- req.body = embeddingObj.to_json
244
- response = Net::HTTP::Proxy(@proxy.host, @proxy.port).new(uri.host, uri.port).start {|http| http.request(req) }
245
- end
206
+ def scenario_name(keyword, name, file_colon_line, source_indent)
207
+ return if @connection_error
208
+ @io.puts "scenario #{name}"
209
+ @scenario.name=name
210
+ @scenario.keyword = keyword
211
+ post_scenario
212
+
213
+ end
246
214
 
247
- def postFeatureElement(feature_element)
248
- return if @connectionError
249
- if @inside_outline
250
- p "in outline"
251
- end
252
- p "posting featureElement #{feature_element.name}"
253
- uri = URI.parse(@url)
254
- http = Net::HTTP::Proxy(@proxy.host, @proxy.port).new(uri.host, uri.port)
255
- request = Net::HTTP::Post.new("/collectionapi/scenarios")
256
- request.add_field('X-Auth-Token', '97f0ad9e24ca5e0408a269748d7fe0a0')
257
- request.body = feature_element.to_json
258
- response = http.request(request)
259
- # puts response.body
260
- parsed = JSON.parse(response.body)
261
- @scenarioID = parsed["_id"]
262
- end
215
+ def post_scenario
216
+ return if @connection_error
217
+ valid,response = @stdd_client.create_scenario(@scenario)
218
+ if(valid)
219
+ @scenario.id = response
220
+ else
221
+ @connection_error = response
222
+ puts @connection_error
223
+ end
224
+ end
263
225
 
264
- # def postScenarioExampleCell(scenarioID,scenarioExampleItem)
265
- # p "posting postScenarioExampleCell"
266
- # uri = URI.parse(@url)
267
- # path = "/collectionapi/scenarios/#{scenarioID}"
268
- # req = Net::HTTP::Put.new(path, initheader = { 'X-Auth-Token' => '97f0ad9e24ca5e0408a269748d7fe0a0'})
269
- # req.body = scenarioExampleItem.to_json
270
- # response = Net::HTTP::Proxy(@proxy.host, @proxy.port).new(uri.host, uri.port).start {|http| http.request(req) }
271
- # end
226
+ def after_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background, file_colon_line)
227
+ return if @connection_error
228
+ step_name = step_match.format_args(lambda{|param| "*#{param}*"})
229
+ @step = STDDAPI::Objects::Step.new(@scenario.id,keyword, step_name)
230
+ @step.status=status
231
+ @step.error_message = exception
232
+ @step.duration = @step_duration
233
+ @step.messages = @delayed_messages
234
+
235
+ valid,response = @stdd_client.add_step_to_scenario(@step)
236
+ if(valid)
237
+ # success
238
+ else
239
+ @connection_error = response
240
+ puts @connection_error
241
+ end
242
+ end
272
243
 
273
- end
244
+ def after_features(features)
245
+ return if @connection_error
246
+ valid, response = @stdd_client.update_module_stopTime(@module.id,Time.now)
247
+ if(valid)
248
+ @module = response
249
+ else
250
+ @connection_error = response
251
+ puts @connection_error
252
+ end
253
+ end
254
+ end
255
+ end
256
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stddtool
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1.1
4
+ version: 0.5.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Danielsson
@@ -11,15 +11,28 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
  date: 2014-02-05 00:00:00.000000000 Z
14
- dependencies: []
15
- description: Cucumber formatter that reports the cucumber testresults to STDDTool
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: stdd_api
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.2.0.1
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ version: 0.2.0.1
29
+ description: Cucumber formatter that reports cucumber testresults to STDDTool
16
30
  email: anton.danielsson@learningwell.se
17
31
  executables: []
18
32
  extensions: []
19
33
  extra_rdoc_files: []
20
34
  files:
21
35
  - lib/stddtool.rb
22
- - lib/objects.rb
23
36
  homepage: https://github.com/antda/cucumber-stddtool
24
37
  licenses:
25
38
  - MIT
data/lib/objects.rb DELETED
@@ -1,94 +0,0 @@
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,:element_type
64
- def to_json
65
- {'featureId' => @feature_ID,'keyword' => @keyword, 'name' => @name,'tags' => @tags,'element_type' => @element_type}.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