gauge-ruby 0.5.0 → 0.5.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.
- checksums.yaml +4 -4
- data/lib/code_parser.rb +46 -23
- data/lib/configuration.rb +4 -0
- data/lib/connector.rb +1 -0
- data/lib/gauge_messages.rb +6 -0
- data/lib/messages_pb.rb +1 -0
- data/lib/processors/execution_handler.rb +1 -1
- data/lib/processors/execution_hook_processors.rb +24 -10
- data/lib/processors/refactor_step_request_processor.rb +3 -3
- data/lib/util.rb +4 -15
- metadata +14 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: daa34f96744dfd879f22b0030d6cb911b37762cf
|
4
|
+
data.tar.gz: ea35374f79704c7438969ceb7a7551f53bd16261
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c841ed91a33272610d2131242bba2cf426f32ed2c951e8fa94a46cb3668098767075b9d306779401996f194bf2590e987e7125d9fc500a632f3fa06a9f61449d
|
7
|
+
data.tar.gz: 58ebf3f372cb8b4162c32b4762e0ced44bd44bfb6bb768dd6fe0ddce7bbacbbdc88ca845bf3449b1bf8afbbc74bc27ae2be3eae4ade4089c6d8ce08b96ee8233
|
data/lib/code_parser.rb
CHANGED
@@ -21,6 +21,7 @@ require 'method_source'
|
|
21
21
|
require 'fileutils'
|
22
22
|
require 'tempfile'
|
23
23
|
require 'util'
|
24
|
+
require 'messages_pb'
|
24
25
|
|
25
26
|
module Gauge
|
26
27
|
# @api private
|
@@ -30,21 +31,18 @@ module Gauge
|
|
30
31
|
arg_node.children
|
31
32
|
end
|
32
33
|
|
33
|
-
def self.process_node(node, param_positions,
|
34
|
+
def self.process_node(node, param_positions, _new_param_values, new_step_text)
|
34
35
|
new_params = []
|
35
36
|
args = step_args_from_code node
|
36
|
-
|
37
|
+
old_params = args.map { |arg| Unparser.unparse arg }
|
38
|
+
param_positions.sort_by!(&:newPosition).each.with_index do |e, i|
|
37
39
|
if e.oldPosition == -1
|
38
|
-
|
39
|
-
if param == ''
|
40
|
-
param = i
|
41
|
-
end
|
42
|
-
new_params[e.newPosition] = "arg_#{param}"
|
40
|
+
new_params[e.newPosition] = Util.get_param_name(old_params, i)
|
43
41
|
else
|
44
42
|
new_params[e.newPosition] = args[e.oldPosition].children[0]
|
45
43
|
end
|
46
|
-
|
47
|
-
args = new_params.map {|v| Parser::AST::Node.new(:arg, [v])}
|
44
|
+
end
|
45
|
+
args = new_params.map { |v| Parser::AST::Node.new(:arg, [v]) }
|
48
46
|
step = [node.children[0].children[0], node.children[0].children[1], Parser::AST::Node.new(:str, [new_step_text])]
|
49
47
|
c1 = Parser::AST::Node.new(:send, step)
|
50
48
|
c2 = Parser::AST::Node.new(:args, args)
|
@@ -56,9 +54,9 @@ module Gauge
|
|
56
54
|
if ast && step_node?(ast)
|
57
55
|
visitor.call(ast)
|
58
56
|
else
|
59
|
-
children = ast.children.map
|
57
|
+
children = ast.children.map do |node|
|
60
58
|
replace(node, &visitor)
|
61
|
-
|
59
|
+
end
|
62
60
|
return ast.updated(nil, children, nil)
|
63
61
|
end
|
64
62
|
end
|
@@ -67,37 +65,62 @@ module Gauge
|
|
67
65
|
node.type == :block && node.children[0].children.size > 2 && node.children[0].children[1] == :step
|
68
66
|
end
|
69
67
|
|
68
|
+
def self.create_params_diff(old_node, new_node)
|
69
|
+
params_loc = old_node.children[1].loc
|
70
|
+
text = Unparser.unparse new_node.children[1]
|
71
|
+
if old_node.children[1].children.size > 1
|
72
|
+
span = Messages::Span.new(start: params_loc.begin.line, startChar: params_loc.begin.column + 1,
|
73
|
+
end: params_loc.end.line, endChar: params_loc.end.column)
|
74
|
+
else
|
75
|
+
span = Messages::Span.new(start: old_node.loc.begin.line, startChar: old_node.loc.begin.column,
|
76
|
+
end: old_node.children[2].loc.line, endChar: old_node.children[2].loc.column)
|
77
|
+
text = "do#{text.empty? ? text : " |#{text}|"}\n\t"
|
78
|
+
end
|
79
|
+
Messages::TextDiff.new(content: text, span: span)
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.create_diffs(old_node, new_node)
|
83
|
+
step_loc = old_node.children[0].children[2].loc
|
84
|
+
step_text = new_node.children[0].children[2].children[0]
|
85
|
+
span = Messages::Span.new(start: step_loc.begin.line,
|
86
|
+
end: step_loc.end.line,
|
87
|
+
startChar: step_loc.begin.column + 1,
|
88
|
+
endChar: step_loc.end.column)
|
89
|
+
[Messages::TextDiff.new(content: step_text, span: span), create_params_diff(old_node, new_node)]
|
90
|
+
end
|
91
|
+
|
70
92
|
def self.refactor_args(step_text, ast, param_positions, new_param_values, new_step_text)
|
93
|
+
diffs = nil
|
71
94
|
new_ast = replace ast do |node|
|
72
95
|
if node.children[0].children[2].children[0] == step_text
|
73
|
-
|
74
|
-
|
96
|
+
old_node = node.clone
|
97
|
+
node = process_node(node, param_positions, new_param_values, new_step_text)
|
98
|
+
diffs = create_diffs(old_node, node)
|
99
|
+
end
|
75
100
|
node
|
76
101
|
end
|
102
|
+
code = Unparser.unparse new_ast
|
103
|
+
{ content: code, diffs: diffs }
|
77
104
|
end
|
78
|
-
Unparser.unparse new_ast
|
79
|
-
end
|
80
105
|
|
81
106
|
def self.refactor(step_info, param_positions, new_step)
|
82
107
|
ast = code_to_ast File.read(step_info[:locations][0][:file])
|
83
|
-
refactor_args(step_info[:step_text], ast, param_positions,
|
108
|
+
refactor_args(step_info[:step_text], ast, param_positions,
|
109
|
+
new_step.parameters,
|
110
|
+
new_step.parameterizedStepValue)
|
84
111
|
end
|
85
112
|
|
86
|
-
|
113
|
+
private_class_method
|
87
114
|
|
88
115
|
def self.code_to_ast(code)
|
89
116
|
begin
|
90
117
|
buffer = Parser::Source::Buffer.new '(string)'
|
91
118
|
buffer.source = code
|
92
119
|
parser = Parser::CurrentRuby.new
|
93
|
-
|
120
|
+
parser.parse(buffer)
|
94
121
|
rescue Exception => e
|
95
122
|
Gauge::Log.error e.message
|
96
123
|
end
|
97
124
|
end
|
98
|
-
|
99
|
-
def self.include_args(code_string, params)
|
100
|
-
code_string.gsub("do", "do #{params}")
|
101
|
-
end
|
102
125
|
end
|
103
|
-
end
|
126
|
+
end
|
data/lib/configuration.rb
CHANGED
@@ -53,6 +53,7 @@ module Gauge
|
|
53
53
|
class Configuration
|
54
54
|
def initialize
|
55
55
|
@includes=[]
|
56
|
+
@custom_screengrabber=false
|
56
57
|
@screengrabber = -> {
|
57
58
|
file = File.open("#{Dir.tmpdir}/screenshot.png", "w+")
|
58
59
|
`gauge_screenshot #{file.path}`
|
@@ -62,6 +63,8 @@ module Gauge
|
|
62
63
|
}
|
63
64
|
end
|
64
65
|
|
66
|
+
attr_reader :custom_screengrabber
|
67
|
+
|
65
68
|
def self.instance
|
66
69
|
@configuration ||= Configuration.new
|
67
70
|
end
|
@@ -79,6 +82,7 @@ module Gauge
|
|
79
82
|
end
|
80
83
|
|
81
84
|
def screengrabber=(block)
|
85
|
+
@custom_screengrabber=true
|
82
86
|
@screengrabber=block
|
83
87
|
end
|
84
88
|
|
data/lib/connector.rb
CHANGED
@@ -32,6 +32,7 @@ module Gauge
|
|
32
32
|
|
33
33
|
def self.make_connection
|
34
34
|
@@executionSocket = TCPSocket.open(HOST_NAME, Runtime.port_from_env_variable(GAUGE_PORT_ENV))
|
35
|
+
@@executionSocket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
|
35
36
|
end
|
36
37
|
|
37
38
|
def self.message_length(socket)
|
data/lib/gauge_messages.rb
CHANGED
data/lib/messages_pb.rb
CHANGED
@@ -105,6 +105,7 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
|
|
105
105
|
add_message "gauge.messages.FileChanges" do
|
106
106
|
optional :fileName, :string, 1
|
107
107
|
optional :fileContent, :string, 2
|
108
|
+
repeated :diffs, :message, 3, "gauge.messages.TextDiff"
|
108
109
|
end
|
109
110
|
add_message "gauge.messages.RefactorResponse" do
|
110
111
|
optional :success, :bool, 1
|
@@ -62,7 +62,7 @@ module Gauge
|
|
62
62
|
end
|
63
63
|
|
64
64
|
def screenshot_bytes
|
65
|
-
return nil if (ENV['screenshot_on_failure'] || "").downcase == "false" || which("gauge_screenshot").nil?
|
65
|
+
return nil if (ENV['screenshot_on_failure'] || "").downcase == "false" || (which("gauge_screenshot").nil? && !Configuration.instance.custom_screengrabber)
|
66
66
|
begin
|
67
67
|
Configuration.instance.screengrabber.call
|
68
68
|
rescue Exception => e
|
@@ -27,37 +27,51 @@ module Gauge
|
|
27
27
|
def process_execution_start_request(message)
|
28
28
|
Gauge::MethodCache.clear
|
29
29
|
Executor.load_steps(Util.get_step_implementation_dir)
|
30
|
-
handle_hooks_execution(MethodCache.get_before_suite_hooks, message,
|
30
|
+
response = handle_hooks_execution(MethodCache.get_before_suite_hooks, message,message.executionStartingRequest.currentExecutionInfo,false)
|
31
|
+
response.executionStatusResponse.executionResult.message += Gauge::GaugeMessages.instance.pending_messages
|
32
|
+
return response
|
31
33
|
end
|
32
34
|
|
33
35
|
def process_execution_end_request(message)
|
34
|
-
handle_hooks_execution(MethodCache.get_after_suite_hooks, message,
|
36
|
+
response = handle_hooks_execution(MethodCache.get_after_suite_hooks, message,message.executionEndingRequest.currentExecutionInfo, false)
|
37
|
+
response.executionStatusResponse.executionResult.message += Gauge::GaugeMessages.instance.pending_messages
|
38
|
+
return response
|
35
39
|
end
|
36
40
|
|
37
41
|
def process_spec_execution_start_request(message)
|
38
|
-
handle_hooks_execution(MethodCache.get_before_spec_hooks, message,
|
42
|
+
response = handle_hooks_execution(MethodCache.get_before_spec_hooks, message,message.specExecutionStartingRequest.currentExecutionInfo)
|
43
|
+
response.executionStatusResponse.executionResult.message += Gauge::GaugeMessages.instance.pending_messages
|
44
|
+
return response
|
39
45
|
end
|
40
46
|
|
41
47
|
def process_spec_execution_end_request(message)
|
42
|
-
handle_hooks_execution(MethodCache.get_after_spec_hooks, message,
|
48
|
+
response = handle_hooks_execution(MethodCache.get_after_spec_hooks, message,message.specExecutionEndingRequest.currentExecutionInfo)
|
49
|
+
response.executionStatusResponse.executionResult.message += Gauge::GaugeMessages.instance.pending_messages
|
50
|
+
return response
|
43
51
|
end
|
44
52
|
|
45
53
|
def process_scenario_execution_start_request(message)
|
46
|
-
handle_hooks_execution(MethodCache.get_before_scenario_hooks, message,
|
54
|
+
response = handle_hooks_execution(MethodCache.get_before_scenario_hooks, message,message.scenarioExecutionStartingRequest.currentExecutionInfo)
|
55
|
+
response.executionStatusResponse.executionResult.message += Gauge::GaugeMessages.instance.pending_messages
|
56
|
+
return response
|
47
57
|
end
|
48
58
|
|
59
|
+
|
49
60
|
def process_scenario_execution_end_request(message)
|
50
|
-
handle_hooks_execution(MethodCache.get_after_scenario_hooks, message,
|
61
|
+
response = handle_hooks_execution(MethodCache.get_after_scenario_hooks, message,message.scenarioExecutionEndingRequest.currentExecutionInfo)
|
62
|
+
response.executionStatusResponse.executionResult.message += Gauge::GaugeMessages.instance.pending_messages
|
63
|
+
return response
|
51
64
|
end
|
52
65
|
|
53
66
|
def process_step_execution_start_request(message)
|
54
|
-
|
55
|
-
|
67
|
+
response = handle_hooks_execution(MethodCache.get_before_step_hooks, message,message.stepExecutionStartingRequest.currentExecutionInfo)
|
68
|
+
response.executionStatusResponse.executionResult.message += Gauge::GaugeMessages.instance.pending_messages
|
69
|
+
return response
|
56
70
|
end
|
57
71
|
|
58
72
|
def process_step_execution_end_request(message)
|
59
|
-
response = handle_hooks_execution(MethodCache.get_after_step_hooks, message,
|
60
|
-
response.executionStatusResponse.executionResult.message
|
73
|
+
response = handle_hooks_execution(MethodCache.get_after_step_hooks, message,message.stepExecutionEndingRequest.currentExecutionInfo)
|
74
|
+
response.executionStatusResponse.executionResult.message += Gauge::GaugeMessages.instance.pending_messages
|
61
75
|
return response
|
62
76
|
end
|
63
77
|
end
|
@@ -29,11 +29,11 @@ module Gauge
|
|
29
29
|
response = Messages::RefactorResponse.new(success: true)
|
30
30
|
begin
|
31
31
|
step_info = get_step request.oldStepValue.stepValue
|
32
|
-
|
32
|
+
refactored_info = CodeParser.refactor step_info, request.paramPositions, request.newStepValue
|
33
33
|
file = step_info[:locations][0][:file]
|
34
|
-
File.write file,
|
34
|
+
File.write file, refactored_info[:content] if request.saveChanges
|
35
35
|
response.filesChanged.push(file)
|
36
|
-
changes = Messages::FileChanges.new(fileName: file, fileContent:
|
36
|
+
changes = Messages::FileChanges.new(fileName: file, fileContent: refactored_info[:content], diffs: refactored_info[:diffs])
|
37
37
|
response.fileChanges.push(changes)
|
38
38
|
rescue Exception => e
|
39
39
|
response.success = false
|
data/lib/util.rb
CHANGED
@@ -17,21 +17,10 @@
|
|
17
17
|
|
18
18
|
module Gauge
|
19
19
|
class Util
|
20
|
-
def self.
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
!!(var_name =~ /^[0-9]+$/)
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.remove_special_chars(param)
|
28
|
-
new_param = ''
|
29
|
-
param.each_char {|c|
|
30
|
-
if valid_variable_name? c
|
31
|
-
new_param += c
|
32
|
-
end
|
33
|
-
}
|
34
|
-
return new_param
|
20
|
+
def self.get_param_name(params, index)
|
21
|
+
name = "arg_#{index}"
|
22
|
+
return name unless params.include? name
|
23
|
+
get_param_name(params, index + 1)
|
35
24
|
end
|
36
25
|
|
37
26
|
def self.get_step_implementation_dir
|
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.
|
4
|
+
version: 0.5.1
|
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-
|
11
|
+
date: 2018-06-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-protocol-buffers
|
@@ -113,6 +113,9 @@ dependencies:
|
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '1.10'
|
118
|
+
- - ">="
|
116
119
|
- !ruby/object:Gem::Version
|
117
120
|
version: 1.10.0
|
118
121
|
type: :runtime
|
@@ -120,6 +123,9 @@ dependencies:
|
|
120
123
|
version_requirements: !ruby/object:Gem::Requirement
|
121
124
|
requirements:
|
122
125
|
- - "~>"
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '1.10'
|
128
|
+
- - ">="
|
123
129
|
- !ruby/object:Gem::Version
|
124
130
|
version: 1.10.0
|
125
131
|
- !ruby/object:Gem::Dependency
|
@@ -127,6 +133,9 @@ dependencies:
|
|
127
133
|
requirement: !ruby/object:Gem::Requirement
|
128
134
|
requirements:
|
129
135
|
- - "~>"
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '1.10'
|
138
|
+
- - ">="
|
130
139
|
- !ruby/object:Gem::Version
|
131
140
|
version: 1.10.0
|
132
141
|
type: :development
|
@@ -134,6 +143,9 @@ dependencies:
|
|
134
143
|
version_requirements: !ruby/object:Gem::Requirement
|
135
144
|
requirements:
|
136
145
|
- - "~>"
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '1.10'
|
148
|
+
- - ">="
|
137
149
|
- !ruby/object:Gem::Version
|
138
150
|
version: 1.10.0
|
139
151
|
description: Adds Ruby support into Gauge tests
|