gauge-ruby 0.5.1 → 0.5.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: daa34f96744dfd879f22b0030d6cb911b37762cf
4
- data.tar.gz: ea35374f79704c7438969ceb7a7551f53bd16261
3
+ metadata.gz: d082650420924a2bbabb264df5849ebe1ce6eb9d
4
+ data.tar.gz: 887f18dcb515c433222548583f30bd0342b04f52
5
5
  SHA512:
6
- metadata.gz: c841ed91a33272610d2131242bba2cf426f32ed2c951e8fa94a46cb3668098767075b9d306779401996f194bf2590e987e7125d9fc500a632f3fa06a9f61449d
7
- data.tar.gz: 58ebf3f372cb8b4162c32b4762e0ced44bd44bfb6bb768dd6fe0ddce7bbacbbdc88ca845bf3449b1bf8afbbc74bc27ae2be3eae4ade4089c6d8ce08b96ee8233
6
+ metadata.gz: 1ccdd5acea8a6f3a89c5939ba88e51028b4032d4c0202ca1d688dc5eb4f75be78b2d1544780062207c8be2af09728c08f28f18da8ab680482dd8f1f0ed6accbe
7
+ data.tar.gz: 766b7a496aa60f3446914a6126ded77efb71697dd3408cd2101b0638a03373eb093d6330278520757fc9c09ae14c7ea1e1a0c26ba3d59fb0538a60da3935a0e7
@@ -55,11 +55,11 @@ module Gauge
55
55
  @includes=[]
56
56
  @custom_screengrabber=false
57
57
  @screengrabber = -> {
58
- file = File.open("#{Dir.tmpdir}/screenshot.png", "w+")
59
- `gauge_screenshot #{file.path}`
60
- file_content = File.binread(file.path)
61
- File.delete file
62
- return file_content
58
+ file_name = "#{Dir.tmpdir}/screenshot.png"
59
+ `gauge_screenshot #{file_name}`
60
+ file_content = File.binread(file_name)
61
+ File.delete file_name
62
+ return file_content
63
63
  }
64
64
  end
65
65
 
@@ -40,17 +40,17 @@ module Gauge
40
40
  end
41
41
 
42
42
  def pending_messages()
43
- pending_messages = @messages
43
+ pending_messages = @messages.select { |m| m != nil}
44
44
  @messages = []
45
45
  pending_messages
46
- end
46
+ end
47
47
 
48
48
  def write(message)
49
49
  @messages.push(message)
50
50
  end
51
51
 
52
52
  def get
53
- @messages
53
+ @messages.select { |m| m != nil}
54
54
  end
55
55
 
56
56
  def clear
@@ -0,0 +1,53 @@
1
+ # Copyright 2018 ThoughtWorks, Inc.
2
+
3
+ # This file is part of Gauge-Ruby.
4
+
5
+ # Gauge-Ruby is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+
10
+ # Gauge-Ruby is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with Gauge-Ruby. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ module Gauge
19
+ class << self
20
+ def capture
21
+ GaugeScreenshot.instance.capture
22
+ end
23
+ end
24
+
25
+ class GaugeScreenshot
26
+ def initialize
27
+ @screenshots = []
28
+ end
29
+
30
+ def self.instance
31
+ @gauge_screenshots ||= GaugeScreenshot.new
32
+ end
33
+
34
+ def capture
35
+ @screenshots.push(Configuration.instance.screengrabber.call)
36
+ end
37
+
38
+ def pending_screenshot
39
+ pending_screenshot = @screenshots
40
+ clear
41
+ pending_screenshot
42
+ end
43
+
44
+ def get
45
+ @screenshots
46
+ end
47
+
48
+ def clear
49
+ @screenshots = []
50
+ end
51
+
52
+ end
53
+ end
@@ -79,13 +79,28 @@ module Gauge
79
79
  @@steps_map[step_value][:recoverable]
80
80
  end
81
81
 
82
+ def self.relative_filepath(file)
83
+ project_root = Pathname.new(ENV['GAUGE_PROJECT_ROOT'])
84
+ filename = Pathname.new(file).relative_path_from(project_root)
85
+ return project_root.join(filename.to_s.split(":").first)
86
+ end
87
+
82
88
  def self.remove_steps(file)
83
89
  @@steps_map.each_pair do |step, info|
84
- l = info[:locations].reject { |loc| File.fnmatch? loc[:file], file }
90
+ l = info[:locations].reject { |loc| relative_filepath(loc[:file]).eql? relative_filepath(file) }
85
91
  l.empty? ? @@steps_map.delete(step) : @@steps_map[step][:locations] = l
86
92
  end
87
93
  end
88
94
 
95
+ def self.is_file_cached(file)
96
+ @@steps_map.each_pair do |step, info|
97
+ if info[:locations].any? { |loc| relative_filepath(loc[:file]).eql? relative_filepath(file) }
98
+ return true
99
+ end
100
+ end
101
+ return false
102
+ end
103
+
89
104
  def self.multiple_implementation?(step_value)
90
105
  @@steps_map[step_value][:locations].length > 1
91
106
  end
@@ -34,8 +34,10 @@ module Gauge
34
34
  ast = CodeParser.code_to_ast(request.content)
35
35
  StaticLoader.reload_steps(f, ast)
36
36
  elsif status == Messages::CacheFileRequest::FileStatus::CREATED
37
- ast = CodeParser.code_to_ast File.read(f)
38
- StaticLoader.reload_steps(f, ast)
37
+ if !Gauge::MethodCache.is_file_cached f
38
+ ast = CodeParser.code_to_ast File.read(f)
39
+ StaticLoader.reload_steps(f, ast)
40
+ end
39
41
  elsif (status == Messages::CacheFileRequest::FileStatus::CLOSED) && File.file?(f)
40
42
  ast = CodeParser.code_to_ast File.read(f)
41
43
  StaticLoader.reload_steps(f, ast)
@@ -33,13 +33,20 @@ module Gauge
33
33
 
34
34
  def handle_pass(message, execution_time)
35
35
  execution_status_response = Messages::ExecutionStatusResponse.new(:executionResult => Messages::ProtoExecutionResult.new(:failed => false, :executionTime => execution_time))
36
+ execution_status_response.executionResult.screenshots += Gauge::GaugeScreenshot.instance.pending_screenshot
37
+ execution_status_response.executionResult.message += Gauge::GaugeMessages.instance.pending_messages
36
38
  Messages::Message.new(:messageType => :ExecutionStatusResponse, :messageId => message.messageId, :executionStatusResponse => execution_status_response)
37
39
  end
38
40
 
41
+ def get_filepath(stacktrace)
42
+ toptrace = stacktrace.split("\n").first
43
+ return MethodCache.relative_filepath toptrace
44
+ end
45
+
39
46
  def handle_failure(message, exception, execution_time, recoverable)
40
47
  project_dir = File.basename(Dir.getwd)
41
48
  stacktrace = exception.backtrace.select {|x| x.match(project_dir) && !x.match(File.join(project_dir, "vendor"))}.join("\n")+"\n"
42
- filepath = stacktrace.split("\n").first.split(":").first
49
+ filepath = get_filepath(stacktrace)
43
50
  line_number = stacktrace.split("\n").first.split("/").last.split(":")[1]
44
51
  code_snippet = "\n" + '> ' + get_code_snippet(filepath, line_number.to_i)
45
52
  execution_status_response =
@@ -50,7 +57,12 @@ module Gauge
50
57
  :stackTrace => code_snippet + stacktrace,
51
58
  :executionTime => execution_time))
52
59
  screenshot = screenshot_bytes
53
- execution_status_response.executionResult.screenShot = screenshot if !screenshot.nil?
60
+ if screenshot
61
+ execution_status_response.executionResult.screenShot = screenshot
62
+ execution_status_response.executionResult.failureScreenshot = screenshot
63
+ end
64
+ execution_status_response.executionResult.screenshots += Gauge::GaugeScreenshot.instance.pending_screenshot
65
+ execution_status_response.executionResult.message += Gauge::GaugeMessages.instance.pending_messages
54
66
  Messages::Message.new(:messageType => :ExecutionStatusResponse,
55
67
  :messageId => message.messageId, :executionStatusResponse => execution_status_response)
56
68
  end
@@ -17,6 +17,7 @@
17
17
 
18
18
  require_relative "execution_handler"
19
19
  require_relative "../gauge_messages"
20
+ require_relative "../gauge_screenshot"
20
21
  require_relative "../executor"
21
22
  require_relative "../method_cache"
22
23
  require_relative "../util"
@@ -28,30 +29,35 @@ module Gauge
28
29
  Gauge::MethodCache.clear
29
30
  Executor.load_steps(Util.get_step_implementation_dir)
30
31
  response = handle_hooks_execution(MethodCache.get_before_suite_hooks, message,message.executionStartingRequest.currentExecutionInfo,false)
32
+ response.executionStatusResponse.executionResult.screenshots += Gauge::GaugeScreenshot.instance.pending_screenshot
31
33
  response.executionStatusResponse.executionResult.message += Gauge::GaugeMessages.instance.pending_messages
32
34
  return response
33
35
  end
34
36
 
35
37
  def process_execution_end_request(message)
36
38
  response = handle_hooks_execution(MethodCache.get_after_suite_hooks, message,message.executionEndingRequest.currentExecutionInfo, false)
39
+ response.executionStatusResponse.executionResult.screenshots += Gauge::GaugeScreenshot.instance.pending_screenshot
37
40
  response.executionStatusResponse.executionResult.message += Gauge::GaugeMessages.instance.pending_messages
38
41
  return response
39
42
  end
40
43
 
41
44
  def process_spec_execution_start_request(message)
42
45
  response = handle_hooks_execution(MethodCache.get_before_spec_hooks, message,message.specExecutionStartingRequest.currentExecutionInfo)
46
+ response.executionStatusResponse.executionResult.screenshots += Gauge::GaugeScreenshot.instance.pending_screenshot
43
47
  response.executionStatusResponse.executionResult.message += Gauge::GaugeMessages.instance.pending_messages
44
48
  return response
45
49
  end
46
50
 
47
51
  def process_spec_execution_end_request(message)
48
52
  response = handle_hooks_execution(MethodCache.get_after_spec_hooks, message,message.specExecutionEndingRequest.currentExecutionInfo)
53
+ response.executionStatusResponse.executionResult.screenshots += Gauge::GaugeScreenshot.instance.pending_screenshot
49
54
  response.executionStatusResponse.executionResult.message += Gauge::GaugeMessages.instance.pending_messages
50
55
  return response
51
56
  end
52
57
 
53
58
  def process_scenario_execution_start_request(message)
54
59
  response = handle_hooks_execution(MethodCache.get_before_scenario_hooks, message,message.scenarioExecutionStartingRequest.currentExecutionInfo)
60
+ response.executionStatusResponse.executionResult.screenshots += Gauge::GaugeScreenshot.instance.pending_screenshot
55
61
  response.executionStatusResponse.executionResult.message += Gauge::GaugeMessages.instance.pending_messages
56
62
  return response
57
63
  end
@@ -59,18 +65,21 @@ module Gauge
59
65
 
60
66
  def process_scenario_execution_end_request(message)
61
67
  response = handle_hooks_execution(MethodCache.get_after_scenario_hooks, message,message.scenarioExecutionEndingRequest.currentExecutionInfo)
68
+ response.executionStatusResponse.executionResult.screenshots += Gauge::GaugeScreenshot.instance.pending_screenshot
62
69
  response.executionStatusResponse.executionResult.message += Gauge::GaugeMessages.instance.pending_messages
63
70
  return response
64
71
  end
65
72
 
66
73
  def process_step_execution_start_request(message)
67
74
  response = handle_hooks_execution(MethodCache.get_before_step_hooks, message,message.stepExecutionStartingRequest.currentExecutionInfo)
75
+ response.executionStatusResponse.executionResult.screenshots += Gauge::GaugeScreenshot.instance.pending_screenshot
68
76
  response.executionStatusResponse.executionResult.message += Gauge::GaugeMessages.instance.pending_messages
69
77
  return response
70
78
  end
71
79
 
72
80
  def process_step_execution_end_request(message)
73
81
  response = handle_hooks_execution(MethodCache.get_after_step_hooks, message,message.stepExecutionEndingRequest.currentExecutionInfo)
82
+ response.executionStatusResponse.executionResult.screenshots += Gauge::GaugeScreenshot.instance.pending_screenshot
74
83
  response.executionStatusResponse.executionResult.message += Gauge::GaugeMessages.instance.pending_messages
75
84
  return response
76
85
  end
@@ -16,6 +16,8 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
16
16
  repeated :postHookMessages, :string, 9
17
17
  repeated :preHookMessage, :string, 10
18
18
  repeated :postHookMessage, :string, 11
19
+ repeated :preHookScreenshots, :bytes, 12
20
+ repeated :postHookScreenshots, :bytes, 13
19
21
  end
20
22
  add_message "gauge.messages.ProtoItem" do
21
23
  optional :itemType, :enum, 1, "gauge.messages.ProtoItem.ItemType"
@@ -55,6 +57,8 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
55
57
  repeated :postHookMessages, :string, 16
56
58
  repeated :preHookMessage, :string, 17
57
59
  repeated :postHookMessage, :string, 18
60
+ repeated :preHookScreenshots, :bytes, 19
61
+ repeated :postHookScreenshots, :bytes, 20
58
62
  end
59
63
  add_message "gauge.messages.Span" do
60
64
  optional :start, :int64, 1
@@ -73,6 +77,8 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
73
77
  optional :stepExecutionResult, :message, 4, "gauge.messages.ProtoStepExecutionResult"
74
78
  repeated :preHookMessages, :string, 5
75
79
  repeated :postHookMessages, :string, 6
80
+ repeated :preHookScreenshots, :bytes, 7
81
+ repeated :postHookScreenshots, :bytes, 8
76
82
  end
77
83
  add_message "gauge.messages.ProtoConcept" do
78
84
  optional :conceptStep, :message, 1, "gauge.messages.ProtoStep"
@@ -130,6 +136,8 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
130
136
  optional :executionTime, :int64, 6
131
137
  repeated :message, :string, 7
132
138
  optional :errorType, :enum, 8, "gauge.messages.ProtoExecutionResult.ErrorType"
139
+ optional :failureScreenshot, :bytes, 9
140
+ repeated :screenshots, :bytes, 10
133
141
  end
134
142
  add_enum "gauge.messages.ProtoExecutionResult.ErrorType" do
135
143
  value :ASSERTION, 0
@@ -140,6 +148,7 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
140
148
  optional :errorMessage, :string, 2
141
149
  optional :screenShot, :bytes, 3
142
150
  optional :tableRowIndex, :int32, 4
151
+ optional :failureScreenshot, :bytes, 5
143
152
  end
144
153
  add_message "gauge.messages.ProtoSuiteResult" do
145
154
  repeated :specResults, :message, 1, "gauge.messages.ProtoSpecResult"
@@ -158,6 +167,8 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
158
167
  repeated :postHookMessages, :string, 14
159
168
  repeated :preHookMessage, :string, 15
160
169
  repeated :postHookMessage, :string, 16
170
+ repeated :preHookScreenshots, :bytes, 17
171
+ repeated :postHookScreenshots, :bytes, 18
161
172
  end
162
173
  add_message "gauge.messages.ProtoSpecResult" do
163
174
  optional :protoSpec, :message, 1, "gauge.messages.ProtoSpec"
@@ -29,10 +29,10 @@ module Gauge
29
29
  end
30
30
 
31
31
  def self.traverse(ast, &visitor)
32
- return if ast.class != Parser::AST::Node
33
- if ast && step_node?(ast)
32
+ return if !ast || ast.class != Parser::AST::Node
33
+ if step_node?(ast)
34
34
  visitor.call(ast)
35
- elsif ast&.children
35
+ elsif ast.children
36
36
  ast.children.each {|node|
37
37
  traverse(node, &visitor)
38
38
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gauge-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gauge Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-15 00:00:00.000000000 Z
11
+ date: 2019-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-protocol-buffers
@@ -164,6 +164,7 @@ files:
164
164
  - lib/gauge.rb
165
165
  - lib/gauge_messages.rb
166
166
  - lib/gauge_runtime.rb
167
+ - lib/gauge_screenshot.rb
167
168
  - lib/log.rb
168
169
  - lib/lsp_pb.rb
169
170
  - lib/lsp_server.rb