gauge-ruby 0.4.3 → 0.5.4

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 (39) hide show
  1. checksums.yaml +5 -5
  2. data/lib/code_parser.rb +52 -41
  3. data/lib/configuration.rb +37 -26
  4. data/lib/datastore.rb +6 -18
  5. data/lib/executor.rb +29 -36
  6. data/lib/gauge.rb +6 -19
  7. data/lib/gauge_messages.rb +12 -18
  8. data/lib/gauge_runtime.rb +14 -66
  9. data/lib/gauge_screenshot.rb +52 -0
  10. data/lib/log.rb +34 -28
  11. data/lib/messages_pb.rb +331 -0
  12. data/lib/method_cache.rb +21 -18
  13. data/lib/processors/cache_file_processor.rb +20 -31
  14. data/lib/processors/datastore_init_processor.rb +23 -30
  15. data/lib/processors/execute_step_request_processor.rb +11 -23
  16. data/lib/processors/execution_handler.rb +33 -33
  17. data/lib/processors/execution_hook_processors.rb +23 -36
  18. data/lib/processors/implementation_file_list_processor.rb +8 -21
  19. data/lib/processors/implementation_glob_pattern_processor.rb +15 -0
  20. data/lib/processors/kill_request_processor.rb +5 -17
  21. data/lib/processors/refactor_step_request_processor.rb +16 -28
  22. data/lib/processors/step_name_request_processor.rb +15 -30
  23. data/lib/processors/step_names_request_processor.rb +8 -22
  24. data/lib/processors/step_positions_request_processor.rb +9 -22
  25. data/lib/processors/step_validation_request_processor.rb +23 -37
  26. data/lib/processors/stub_implementation_processor.rb +10 -22
  27. data/lib/service_handlers.rb +110 -0
  28. data/lib/services_pb.rb +15 -0
  29. data/lib/services_services_pb.rb +165 -0
  30. data/lib/spec_pb.rb +272 -0
  31. data/lib/static_loader.rb +10 -22
  32. data/lib/table.rb +5 -17
  33. data/lib/util.rb +31 -44
  34. metadata +80 -21
  35. data/lib/api.pb.rb +0 -273
  36. data/lib/connector.rb +0 -45
  37. data/lib/message_processor.rb +0 -59
  38. data/lib/messages.pb.rb +0 -413
  39. data/lib/spec.pb.rb +0 -319
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 86bb6e44e272971e83b2bef3c38dd92106cae506
4
- data.tar.gz: cfdf3a81e93b61c3acc54da0a123630781043860
2
+ SHA256:
3
+ metadata.gz: a3bcf9ae0d69a23863f652540236e9684432da817c26b989d0c7c07c6e147662
4
+ data.tar.gz: 6e56286778ec606b7ccd20035e7b58192b6c72c8a398c7ba0619b613cc8fb6b3
5
5
  SHA512:
6
- metadata.gz: 36640d7d7936fc4600b7dc1040b922f893bd72ff4e1a514251fefba70a16459009c508031c57e328c59b87da07e4845622409f5da1c4539a66426fa074660042
7
- data.tar.gz: 220d4b472ee354d203bcbe35ab54f40f33be040d9eb8b664fc6e5001b0c5888f5000cd508fb4de196f6ed7a831641a2ee54f156247846a97af9846495016a341
6
+ metadata.gz: 11c74029d398ba60279ae148bd7e5b53a1bec7202ae6730ca19d9e0f48d1bc1108c7f66add8828ed2571e9152616f6421cd571d2f86e82ea373a494474e4f309
7
+ data.tar.gz: ef8d048a3af560c04777f683c0cd61032e809c1afde5f9acee97171abf435297e54065d11c3f8cbf4900bcff304b0ef5b97df7813005d6f3e0c8f1bd1f9f168e
@@ -1,26 +1,15 @@
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
-
1
+ =begin
2
+ * Copyright (c) ThoughtWorks, Inc.
3
+ * Licensed under the Apache License, Version 2.0
4
+ * See LICENSE.txt in the project root for license information.
5
+ =end
18
6
  require 'parser/current'
19
7
  require 'unparser'
20
8
  require 'method_source'
21
9
  require 'fileutils'
22
10
  require 'tempfile'
23
11
  require 'util'
12
+ require 'messages_pb'
24
13
 
25
14
  module Gauge
26
15
  # @api private
@@ -30,21 +19,18 @@ module Gauge
30
19
  arg_node.children
31
20
  end
32
21
 
33
- def self.process_node(node, param_positions, new_param_values, new_step_text)
22
+ def self.process_node(node, param_positions, _new_param_values, new_step_text)
34
23
  new_params = []
35
24
  args = step_args_from_code node
36
- param_positions.sort_by!(&:newPosition).each.with_index {|e, i|
25
+ old_params = args.map { |arg| Unparser.unparse arg }
26
+ param_positions.sort_by!(&:newPosition).each.with_index do |e, i|
37
27
  if e.oldPosition == -1
38
- param = Util.remove_special_chars new_param_values[e.newPosition].downcase.split.join('_')
39
- if param == ''
40
- param = i
41
- end
42
- new_params[e.newPosition] = "arg_#{param}"
28
+ new_params[e.newPosition] = Util.get_param_name(old_params, i)
43
29
  else
44
30
  new_params[e.newPosition] = args[e.oldPosition].children[0]
45
31
  end
46
- }
47
- args = new_params.map {|v| Parser::AST::Node.new(:arg, [v])}
32
+ end
33
+ args = new_params.map { |v| Parser::AST::Node.new(:arg, [v]) }
48
34
  step = [node.children[0].children[0], node.children[0].children[1], Parser::AST::Node.new(:str, [new_step_text])]
49
35
  c1 = Parser::AST::Node.new(:send, step)
50
36
  c2 = Parser::AST::Node.new(:args, args)
@@ -56,9 +42,9 @@ module Gauge
56
42
  if ast && step_node?(ast)
57
43
  visitor.call(ast)
58
44
  else
59
- children = ast.children.map {|node|
45
+ children = ast.children.map do |node|
60
46
  replace(node, &visitor)
61
- }
47
+ end
62
48
  return ast.updated(nil, children, nil)
63
49
  end
64
50
  end
@@ -67,37 +53,62 @@ module Gauge
67
53
  node.type == :block && node.children[0].children.size > 2 && node.children[0].children[1] == :step
68
54
  end
69
55
 
56
+ def self.create_params_diff(old_node, new_node)
57
+ params_loc = old_node.children[1].loc
58
+ text = Unparser.unparse new_node.children[1]
59
+ if old_node.children[1].children.size > 1
60
+ span = Messages::Span.new(start: params_loc.begin.line, startChar: params_loc.begin.column + 1,
61
+ end: params_loc.end.line, endChar: params_loc.end.column)
62
+ else
63
+ span = Messages::Span.new(start: old_node.loc.begin.line, startChar: old_node.loc.begin.column,
64
+ end: old_node.children[2].loc.line, endChar: old_node.children[2].loc.column)
65
+ text = "do#{text.empty? ? text : " |#{text}|"}\n\t"
66
+ end
67
+ Messages::TextDiff.new(content: text, span: span)
68
+ end
69
+
70
+ def self.create_diffs(old_node, new_node)
71
+ step_loc = old_node.children[0].children[2].loc
72
+ step_text = new_node.children[0].children[2].children[0]
73
+ span = Messages::Span.new(start: step_loc.begin.line,
74
+ end: step_loc.end.line,
75
+ startChar: step_loc.begin.column + 1,
76
+ endChar: step_loc.end.column)
77
+ [Messages::TextDiff.new(content: step_text, span: span), create_params_diff(old_node, new_node)]
78
+ end
79
+
70
80
  def self.refactor_args(step_text, ast, param_positions, new_param_values, new_step_text)
81
+ diffs = nil
71
82
  new_ast = replace ast do |node|
72
83
  if node.children[0].children[2].children[0] == step_text
73
- process_node(node, param_positions, new_param_values, new_step_text)
74
- else
84
+ old_node = node.clone
85
+ node = process_node(node, param_positions, new_param_values, new_step_text)
86
+ diffs = create_diffs(old_node, node)
87
+ end
75
88
  node
76
89
  end
90
+ code = Unparser.unparse new_ast
91
+ { content: code, diffs: diffs }
77
92
  end
78
- Unparser.unparse new_ast
79
- end
80
93
 
81
94
  def self.refactor(step_info, param_positions, new_step)
82
95
  ast = code_to_ast File.read(step_info[:locations][0][:file])
83
- refactor_args(step_info[:step_text], ast, param_positions, new_step.parameters, new_step.parameterizedStepValue)
96
+ refactor_args(step_info[:step_text], ast, param_positions,
97
+ new_step.parameters,
98
+ new_step.parameterizedStepValue)
84
99
  end
85
100
 
86
- private
101
+ private_class_method
87
102
 
88
103
  def self.code_to_ast(code)
89
104
  begin
90
105
  buffer = Parser::Source::Buffer.new '(string)'
91
106
  buffer.source = code
92
107
  parser = Parser::CurrentRuby.new
93
- return parser.parse(buffer)
108
+ parser.parse(buffer)
94
109
  rescue Exception => e
95
- Gauge::Log.error e.message
110
+ GaugeLog.error e
96
111
  end
97
112
  end
98
-
99
- def self.include_args(code_string, params)
100
- code_string.gsub("do", "do #{params}")
101
- end
102
113
  end
103
- end
114
+ end
@@ -1,22 +1,8 @@
1
- # Copyright 2015 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
- # Gauge runtime for Ruby language. Read more about Gauge: http://getgauge.io
19
-
1
+ =begin
2
+ * Copyright (c) ThoughtWorks, Inc.
3
+ * Licensed under the Apache License, Version 2.0
4
+ * See LICENSE.txt in the project root for license information.
5
+ =end
20
6
  # @api public
21
7
  module Gauge
22
8
  class << self
@@ -53,12 +39,12 @@ module Gauge
53
39
  class Configuration
54
40
  def initialize
55
41
  @includes=[]
42
+ @screenshot_writer = true
43
+ @custom_screengrabber = false
56
44
  @screengrabber = -> {
57
- file = File.open("#{Dir.tmpdir}/screenshot.png", "w+")
58
- `gauge_screenshot #{file.path}`
59
- file_content = File.binread(file.path)
60
- File.delete file
61
- return file_content
45
+ file_name = Util.unique_screenshot_file
46
+ `gauge_screenshot #{file_name}`
47
+ return File.basename(file_name)
62
48
  }
63
49
  end
64
50
 
@@ -79,7 +65,26 @@ module Gauge
79
65
  end
80
66
 
81
67
  def screengrabber=(block)
82
- @screengrabber=block
68
+ GaugeLog.warning("[DEPRECATED] Use custom_screenshot_writer instead.")
69
+ @screenshot_writer = false
70
+ set_screengrabber(block)
71
+ end
72
+
73
+ def custom_screenshot_writer=(block)
74
+ @screenshot_writer = true
75
+ set_screengrabber(block)
76
+ end
77
+
78
+ def screenshot_writer?
79
+ @screenshot_writer
80
+ end
81
+
82
+ def custom_screengrabber?
83
+ @custom_screengrabber
84
+ end
85
+
86
+ def screenshot_dir
87
+ ENV['gauge_screenshots_dir']
83
88
  end
84
89
 
85
90
  def self.include_configured_modules
@@ -88,5 +93,11 @@ module Gauge
88
93
  main=TOPLEVEL_BINDING.eval('self')
89
94
  self.instance.includes.each &main.method(:include)
90
95
  end
96
+
97
+ private
98
+ def set_screengrabber(block)
99
+ @custom_screengrabber = true
100
+ @screengrabber=block
101
+ end
91
102
  end
92
- end
103
+ end
@@ -1,20 +1,8 @@
1
- # Copyright 2015 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
-
1
+ =begin
2
+ * Copyright (c) ThoughtWorks, Inc.
3
+ * Licensed under the Apache License, Version 2.0
4
+ * See LICENSE.txt in the project root for license information.
5
+ =end
18
6
  module Gauge
19
7
  # @api public
20
8
  class DataStore
@@ -81,4 +69,4 @@ module Gauge
81
69
  @@spec_datastore = DataStore.new
82
70
  @@scenario_datastore = DataStore.new
83
71
  end
84
- end
72
+ end
@@ -1,27 +1,16 @@
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/>.
1
+ =begin
2
+ * Copyright (c) ThoughtWorks, Inc.
3
+ * Licensed under the Apache License, Version 2.0
4
+ * See LICENSE.txt in the project root for license information.
5
+ =end
17
6
  require 'ruby-debug-ide'
18
7
  require_relative 'gauge'
19
8
 
20
- ATTACH_DEBUGGER_EVENT = "Runner Ready for Debugging"
9
+ ATTACH_DEBUGGER_EVENT = 'Runner Ready for Debugging'
21
10
 
22
11
  module Gauge
23
12
  class DebugOptions
24
- attr_accessor :host, :port, :notify_dispatcher
13
+ attr_accessor :host, :port, :notify_dispatcher, :socket_path, :skip_wait_for_start
25
14
  end
26
15
 
27
16
  # @api private
@@ -30,10 +19,11 @@ module Gauge
30
19
  start_debugger
31
20
  Dir["#{dir}/**/*.rb"].each do |x|
32
21
  begin
22
+ GaugeLog.debug "Loading step implemetations from #{x} dirs"
33
23
  ENV['GAUGE_STEP_FILE'] = x
34
24
  require x
35
25
  rescue Exception => e
36
- Gauge::Log.error "[ERROR] Cannot import #{x}. Reason: #{e.message}"
26
+ GaugeLog.error "Cannot import #{x}. Reason: #{e.message}"
37
27
  end
38
28
  end
39
29
  end
@@ -42,9 +32,10 @@ module Gauge
42
32
  if ENV['DEBUGGING']
43
33
  options = DebugOptions.new
44
34
  options.host = '127.0.0.1'
45
- options.port = ENV["DEBUG_PORT"].to_i
35
+ options.port = ENV['DEBUG_PORT'].to_i
46
36
  options.notify_dispatcher = false
47
- Gauge::Log.info ATTACH_DEBUGGER_EVENT
37
+ options.skip_wait_for_start = false
38
+ GaugeLog.info ATTACH_DEBUGGER_EVENT
48
39
  Debugger.prepare_debugger(options)
49
40
  end
50
41
  end
@@ -59,22 +50,24 @@ module Gauge
59
50
  end
60
51
 
61
52
  def self.execute_hooks(hooks, currentExecutionInfo, should_filter)
62
- begin
63
- hooks.each do |hook|
64
- if !should_filter || hook[:options][:tags].length == 0
65
- next hook[:block].call(currentExecutionInfo)
66
- end
67
- tags = currentExecutionInfo.currentSpec.tags + currentExecutionInfo.currentScenario.tags
68
- intersection = (tags & hook[:options][:tags])
69
- if (hook[:options][:operator] == 'OR' && intersection.length > 0) ||
70
- (hook[:options][:operator] == 'AND' && intersection.length == hook[:options][:tags].length)
71
- hook[:block].call(currentExecutionInfo)
72
- end
53
+ hooks.each do |hook|
54
+ if !should_filter || hook[:options][:tags].empty?
55
+ next hook[:block].call(currentExecutionInfo)
56
+ end
57
+ tags = currentExecutionInfo.currentSpec.tags + get_scenario_tags(currentExecutionInfo)
58
+ intersection = (tags & hook[:options][:tags])
59
+ if (hook[:options][:operator] == 'OR' && !intersection.empty?) ||
60
+ (hook[:options][:operator] == 'AND' && intersection.length == hook[:options][:tags].length)
61
+ hook[:block].call(currentExecutionInfo)
73
62
  end
74
- return nil
75
- rescue Exception => e
76
- return e
77
63
  end
64
+ nil
65
+ rescue Exception => e
66
+ e
67
+ end
68
+
69
+ def self.get_scenario_tags(info)
70
+ !info.currentScenario.nil? ? info.currentScenario.tags : []
78
71
  end
79
72
  end
80
- end
73
+ end
@@ -1,21 +1,8 @@
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
- require_relative 'connector'
1
+ =begin
2
+ * Copyright (c) ThoughtWorks, Inc.
3
+ * Licensed under the Apache License, Version 2.0
4
+ * See LICENSE.txt in the project root for license information.
5
+ =end
19
6
  require_relative 'method_cache'
20
7
  require_relative 'configuration'
21
8
 
@@ -107,7 +94,7 @@ module Kernel
107
94
  step_texts = args - opts
108
95
  opts = { continue_on_failure: false }.merge opts.reduce({}, :merge)
109
96
  step_texts.each do |text|
110
- step_value = Gauge::Connector.step_value(text)
97
+ step_value = Gauge::Util.step_value(text)
111
98
  si = { location: { file: ENV['GAUGE_STEP_FILE'], span: {} },
112
99
  block: block, step_text: text,
113
100
  recoverable: opts[:continue_on_failure] }
@@ -1,20 +1,8 @@
1
- # Copyright 2015 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
-
1
+ =begin
2
+ * Copyright (c) ThoughtWorks, Inc.
3
+ * Licensed under the Apache License, Version 2.0
4
+ * See LICENSE.txt in the project root for license information.
5
+ =end
18
6
  # @api public
19
7
  module Gauge
20
8
  class << self
@@ -39,12 +27,18 @@ module Gauge
39
27
  @gauge_messages ||= GaugeMessages.new
40
28
  end
41
29
 
30
+ def pending_messages()
31
+ pending_messages = @messages.select { |m| m != nil}
32
+ @messages = []
33
+ pending_messages
34
+ end
35
+
42
36
  def write(message)
43
37
  @messages.push(message)
44
38
  end
45
39
 
46
40
  def get
47
- @messages
41
+ @messages.select { |m| m != nil}
48
42
  end
49
43
 
50
44
  def clear