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
@@ -1,20 +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
-
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_relative 'configuration'
19
7
  module Gauge
20
8
  # @api private
@@ -79,13 +67,28 @@ module Gauge
79
67
  @@steps_map[step_value][:recoverable]
80
68
  end
81
69
 
70
+ def self.relative_filepath(file)
71
+ project_root = Pathname.new(ENV['GAUGE_PROJECT_ROOT'])
72
+ filename = Pathname.new(file).relative_path_from(project_root)
73
+ return project_root.join(filename.to_s.split(":").first)
74
+ end
75
+
82
76
  def self.remove_steps(file)
83
77
  @@steps_map.each_pair do |step, info|
84
- l = info[:locations].reject { |loc| File.identical? loc[:file], file }
78
+ l = info[:locations].reject { |loc| relative_filepath(loc[:file]).eql? relative_filepath(file) }
85
79
  l.empty? ? @@steps_map.delete(step) : @@steps_map[step][:locations] = l
86
80
  end
87
81
  end
88
82
 
83
+ def self.is_file_cached(file)
84
+ @@steps_map.each_pair do |step, info|
85
+ if info[:locations].any? { |loc| relative_filepath(loc[:file]).eql? relative_filepath(file) }
86
+ return true
87
+ end
88
+ end
89
+ return false
90
+ end
91
+
89
92
  def self.multiple_implementation?(step_value)
90
93
  @@steps_map[step_value][:locations].length > 1
91
94
  end
@@ -1,43 +1,32 @@
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
+ # frozen_string_literal: true
2
+ =begin
3
+ * Copyright (c) ThoughtWorks, Inc.
4
+ * Licensed under the Apache License, Version 2.0
5
+ * See LICENSE.txt in the project root for license information.
6
+ =end
18
7
  require_relative '../static_loader'
19
8
  require_relative '../method_cache'
20
9
  module Gauge
21
10
  # @api private
22
11
  module Processors
23
- def process_cache_file_request(message)
24
- if !message.cacheFileRequest.isClosed
25
- ast = CodeParser.code_to_ast(message.cacheFileRequest.content)
26
- StaticLoader.reload_steps(message.cacheFileRequest.filePath, ast)
27
- else
28
- load_from_disk message.cacheFileRequest.filePath
29
- end
30
- nil
31
- end
32
-
33
- def load_from_disk(f)
34
- if File.file? f
12
+ def process_cache_file_request(request)
13
+ f = request.filePath
14
+ status = Messages::CacheFileRequest::FileStatus.resolve(request.status)
15
+ if (status == Messages::CacheFileRequest::FileStatus::CHANGED) || (status == Messages::CacheFileRequest::FileStatus::OPENED)
16
+ ast = CodeParser.code_to_ast(request.content)
17
+ StaticLoader.reload_steps(f, ast)
18
+ elsif status == Messages::CacheFileRequest::FileStatus::CREATED
19
+ if !Gauge::MethodCache.is_file_cached f
20
+ ast = CodeParser.code_to_ast File.read(f)
21
+ StaticLoader.reload_steps(f, ast)
22
+ end
23
+ elsif (status == Messages::CacheFileRequest::FileStatus::CLOSED) && File.file?(f)
35
24
  ast = CodeParser.code_to_ast File.read(f)
36
25
  StaticLoader.reload_steps(f, ast)
37
26
  else
38
27
  StaticLoader.remove_steps(f)
39
28
  end
29
+ Messages::Empty.new
40
30
  end
41
-
42
31
  end
43
- end
32
+ end
@@ -1,36 +1,29 @@
1
- # Copyright 2015 ThoughtWorks, Inc.
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
6
+ require_relative "../datastore"
2
7
 
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.
8
+ module Gauge
9
+ module Processors
10
+ def process_suite_data_store_init_request(_request)
11
+ DataStoreFactory.suite_datastore.clear
12
+ datastore_response
13
+ end
14
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/>.
15
+ def process_spec_data_store_init_request(_request)
16
+ DataStoreFactory.spec_datastore.clear
17
+ datastore_response
18
+ end
17
19
 
18
- require_relative '../datastore'
20
+ def process_scenario_data_store_init_request(_request)
21
+ DataStoreFactory.scenario_datastore.clear
22
+ datastore_response
23
+ end
19
24
 
20
- module Gauge
21
- # @api private
22
- module Processors
23
- def process_datastore_init(message)
24
- case message.messageType
25
- when Messages::Message::MessageType::SuiteDataStoreInit
26
- DataStoreFactory.suite_datastore.clear
27
- when Messages::Message::MessageType::SpecDataStoreInit
28
- DataStoreFactory.spec_datastore.clear
29
- when Messages::Message::MessageType::ScenarioDataStoreInit
30
- DataStoreFactory.scenario_datastore.clear
31
- end
32
- execution_status_response = Messages::ExecutionStatusResponse.new(:executionResult => Messages::ProtoExecutionResult.new(:failed => false, :executionTime => 0))
33
- Messages::Message.new(:messageType => Messages::Message::MessageType::ExecutionStatusResponse, :messageId => message.messageId, :executionStatusResponse => execution_status_response)
25
+ def datastore_response
26
+ Messages::ExecutionStatusResponse.new(:executionResult => Messages::ProtoExecutionResult.new(:failed => false, :executionTime => 0))
34
27
  end
35
28
  end
36
- end
29
+ end
@@ -1,37 +1,25 @@
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
  require_relative "execution_handler"
19
7
 
20
8
  module Gauge
21
9
  module Processors
22
10
  include ExecutionHandler
23
11
 
24
- def process_execute_step_request(message)
25
- step_text = message.executeStepRequest.parsedStepText
26
- parameters = message.executeStepRequest.parameters
12
+ def process_execute_step_request(request)
13
+ step_text = request.parsedStepText
14
+ parameters = request.parameters
27
15
  args = create_param_values parameters
28
16
  start_time= Time.now
29
17
  begin
30
18
  Executor.execute_step step_text, args
31
19
  rescue Exception => e
32
- return handle_failure message, e, time_elapsed_since(start_time), MethodCache.recoverable?(step_text)
20
+ return handle_failure e, time_elapsed_since(start_time), MethodCache.recoverable?(step_text)
33
21
  end
34
- handle_pass message, time_elapsed_since(start_time)
22
+ handle_pass time_elapsed_since(start_time)
35
23
  end
36
24
  end
37
- end
25
+ end
@@ -1,45 +1,41 @@
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
  require 'os'
7
+ require_relative '../table'
19
8
 
20
9
  module Gauge
21
10
  module Processors
22
11
  # @api private
23
12
  module ExecutionHandler
24
- def handle_hooks_execution(hooks, message, currentExecutionInfo, should_filter=true)
13
+ def handle_hooks_execution(hooks, currentExecutionInfo, should_filter=true)
25
14
  start_time= Time.now
26
15
  execution_error = Executor.execute_hooks(hooks, currentExecutionInfo, should_filter)
27
16
  if execution_error == nil
28
- return handle_pass message, time_elapsed_since(start_time)
17
+ return handle_pass time_elapsed_since(start_time)
29
18
  else
30
- return handle_failure message, execution_error, time_elapsed_since(start_time), false
19
+ return handle_failure execution_error, time_elapsed_since(start_time), false
31
20
  end
32
21
  end
33
22
 
34
- def handle_pass(message, execution_time)
23
+ def handle_pass(execution_time)
35
24
  execution_status_response = Messages::ExecutionStatusResponse.new(:executionResult => Messages::ProtoExecutionResult.new(:failed => false, :executionTime => execution_time))
36
- Messages::Message.new(:messageType => Messages::Message::MessageType::ExecutionStatusResponse, :messageId => message.messageId, :executionStatusResponse => execution_status_response)
25
+ execution_status_response.executionResult.screenshotFiles += Gauge::GaugeScreenshot.instance.pending_screenshot
26
+ execution_status_response.executionResult.message += Gauge::GaugeMessages.instance.pending_messages
27
+ execution_status_response
37
28
  end
38
29
 
39
- def handle_failure(message, exception, execution_time, recoverable)
30
+ def get_filepath(stacktrace)
31
+ toptrace = stacktrace.split("\n").first
32
+ MethodCache.relative_filepath toptrace
33
+ end
34
+
35
+ def handle_failure(exception, execution_time, recoverable)
40
36
  project_dir = File.basename(Dir.getwd)
41
37
  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
38
+ filepath = get_filepath(stacktrace)
43
39
  line_number = stacktrace.split("\n").first.split("/").last.split(":")[1]
44
40
  code_snippet = "\n" + '> ' + get_code_snippet(filepath, line_number.to_i)
45
41
  execution_status_response =
@@ -48,10 +44,14 @@ module Gauge
48
44
  :recoverableError => recoverable,
49
45
  :errorMessage => exception.message,
50
46
  :stackTrace => code_snippet + stacktrace,
51
- :executionTime => execution_time,
52
- :screenShot => screenshot_bytes))
53
- Messages::Message.new(:messageType => Messages::Message::MessageType::ExecutionStatusResponse,
54
- :messageId => message.messageId, :executionStatusResponse => execution_status_response)
47
+ :executionTime => execution_time))
48
+ screenshot_file = take_screenshot
49
+ if screenshot_file
50
+ execution_status_response.executionResult.failureScreenshotFile = screenshot_file
51
+ end
52
+ execution_status_response.executionResult.screenshotFiles += Gauge::GaugeScreenshot.instance.pending_screenshot
53
+ execution_status_response.executionResult.message += Gauge::GaugeMessages.instance.pending_messages
54
+ execution_status_response
55
55
  end
56
56
 
57
57
  def get_code_snippet(filename, number)
@@ -60,12 +60,12 @@ module Gauge
60
60
  number.to_s + " | " + line.strip + "\n\n"
61
61
  end
62
62
 
63
- def screenshot_bytes
64
- return nil if (ENV['screenshot_on_failure'] || "").downcase == "false" || which("gauge_screenshot").nil?
63
+ def take_screenshot
64
+ return nil if (ENV['screenshot_on_failure'] || "").downcase == "false" || (which("gauge_screenshot").nil? && !Configuration.instance.custom_screengrabber?)
65
65
  begin
66
- Configuration.instance.screengrabber.call
66
+ GaugeScreenshot.instance.capture_to_file
67
67
  rescue Exception => e
68
- Gauge::Log.error e
68
+ GaugeLog.error e
69
69
  return nil
70
70
  end
71
71
  end
@@ -77,7 +77,7 @@ module Gauge
77
77
  def create_param_values parameters
78
78
  params = []
79
79
  parameters.each do |param|
80
- if ((param.parameterType == Messages::Parameter::ParameterType::Table) ||(param.parameterType == Messages::Parameter::ParameterType::Special_Table))
80
+ if ((param.parameterType == :Table) ||(param.parameterType == :Special_Table))
81
81
  gtable = Gauge::Table.new(param.table)
82
82
  params.push gtable
83
83
  else
@@ -1,22 +1,11 @@
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
  require_relative "execution_handler"
19
7
  require_relative "../gauge_messages"
8
+ require_relative "../gauge_screenshot"
20
9
  require_relative "../executor"
21
10
  require_relative "../method_cache"
22
11
  require_relative "../util"
@@ -24,41 +13,39 @@ module Gauge
24
13
  module Processors
25
14
  include ExecutionHandler
26
15
 
27
- def process_execution_start_request(message)
16
+ def process_execution_start_request(request)
28
17
  Gauge::MethodCache.clear
29
18
  Executor.load_steps(Util.get_step_implementation_dir)
30
- handle_hooks_execution(MethodCache.get_before_suite_hooks, message, message.executionStartingRequest.currentExecutionInfo,false)
19
+ handle_hooks_execution(MethodCache.get_before_suite_hooks,request.currentExecutionInfo,false)
31
20
  end
32
21
 
33
- def process_execution_end_request(message)
34
- handle_hooks_execution(MethodCache.get_after_suite_hooks, message, message.executionEndingRequest.currentExecutionInfo, false)
22
+ def process_execution_end_request(request)
23
+ handle_hooks_execution(MethodCache.get_after_suite_hooks, request.currentExecutionInfo, false)
35
24
  end
36
25
 
37
- def process_spec_execution_start_request(message)
38
- handle_hooks_execution(MethodCache.get_before_spec_hooks, message, message.specExecutionStartingRequest.currentExecutionInfo)
26
+ def process_spec_execution_start_request(request)
27
+ handle_hooks_execution(MethodCache.get_before_spec_hooks,request.currentExecutionInfo)
39
28
  end
40
29
 
41
- def process_spec_execution_end_request(message)
42
- handle_hooks_execution(MethodCache.get_after_spec_hooks, message, message.specExecutionEndingRequest.currentExecutionInfo)
30
+ def process_spec_execution_end_request(request)
31
+ handle_hooks_execution(MethodCache.get_after_spec_hooks,request.currentExecutionInfo)
43
32
  end
44
33
 
45
- def process_scenario_execution_start_request(message)
46
- handle_hooks_execution(MethodCache.get_before_scenario_hooks, message, message.scenarioExecutionStartingRequest.currentExecutionInfo)
34
+ def process_scenario_execution_start_request(request)
35
+ handle_hooks_execution(MethodCache.get_before_scenario_hooks,request.currentExecutionInfo)
47
36
  end
48
37
 
49
- def process_scenario_execution_end_request(message)
50
- handle_hooks_execution(MethodCache.get_after_scenario_hooks, message, message.scenarioExecutionEndingRequest.currentExecutionInfo)
38
+
39
+ def process_scenario_execution_end_request(request)
40
+ handle_hooks_execution(MethodCache.get_after_scenario_hooks,request.currentExecutionInfo)
51
41
  end
52
42
 
53
- def process_step_execution_start_request(message)
54
- Gauge::GaugeMessages.instance.clear
55
- handle_hooks_execution(MethodCache.get_before_step_hooks, message, message.stepExecutionStartingRequest.currentExecutionInfo)
43
+ def process_step_execution_start_request(request)
44
+ handle_hooks_execution(MethodCache.get_before_step_hooks,request.currentExecutionInfo)
56
45
  end
57
46
 
58
- def process_step_execution_end_request(message)
59
- response = handle_hooks_execution(MethodCache.get_after_step_hooks, message, message.stepExecutionEndingRequest.currentExecutionInfo)
60
- response.executionStatusResponse.executionResult.message = Gauge::GaugeMessages.instance.get
61
- return response
47
+ def process_step_execution_end_request(request)
48
+ handle_hooks_execution(MethodCache.get_after_step_hooks,request.currentExecutionInfo)
62
49
  end
63
50
  end
64
51
  end
@@ -1,29 +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/>.
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_relative '../util'
19
7
 
20
8
  module Gauge
21
9
  module Processors
22
- def process_implementation_file_list_request(message)
10
+ def process_implementation_file_list_request(_request)
23
11
  implPath = Util.get_step_implementation_dir
24
12
  fileList = Dir["#{implPath}/**/*.rb"]
25
- r = Messages::ImplementationFileListResponse.new(:implementationFilePaths => fileList)
26
- Messages::Message.new(:messageType => Messages::Message::MessageType::ImplementationFileListResponse, :messageId => message.messageId, :implementationFileListResponse => r)
13
+ Messages::ImplementationFileListResponse.new(:implementationFilePaths => fileList)
27
14
  end
28
15
  end
29
- end
16
+ end