gauge-ruby 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -22,12 +22,7 @@ require_relative '../method_cache'
22
22
  module Gauge
23
23
  # @api private
24
24
  module Processors
25
- def process_cache_file_request(message)
26
- cache_file_response(message.cacheFileRequest)
27
- nil
28
- end
29
-
30
- def cache_file_response(request)
25
+ def process_cache_file_request(request)
31
26
  f = request.filePath
32
27
  status = Messages::CacheFileRequest::FileStatus.resolve(request.status)
33
28
  if (status == Messages::CacheFileRequest::FileStatus::CHANGED) || (status == Messages::CacheFileRequest::FileStatus::OPENED)
@@ -15,22 +15,27 @@
15
15
  # You should have received a copy of the GNU General Public License
16
16
  # along with Gauge-Ruby. If not, see <http://www.gnu.org/licenses/>.
17
17
 
18
- require_relative '../datastore'
18
+ require_relative "../datastore"
19
19
 
20
20
  module Gauge
21
- # @api private
22
21
  module Processors
23
- def process_datastore_init(message)
24
- case message.messageType
25
- when :SuiteDataStoreInit
26
- DataStoreFactory.suite_datastore.clear
27
- when :SpecDataStoreInit
28
- DataStoreFactory.spec_datastore.clear
29
- when :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 => :ExecutionStatusResponse, :messageId => message.messageId, :executionStatusResponse => execution_status_response)
22
+ def process_suite_data_store_init_request(_request)
23
+ DataStoreFactory.suite_datastore.clear
24
+ datastore_response
25
+ end
26
+
27
+ def process_spec_data_store_init_request(_request)
28
+ DataStoreFactory.spec_datastore.clear
29
+ datastore_response
30
+ end
31
+
32
+ def process_scenario_data_store_init_request(_request)
33
+ DataStoreFactory.scenario_datastore.clear
34
+ datastore_response
35
+ end
36
+
37
+ def datastore_response
38
+ Messages::ExecutionStatusResponse.new(:executionResult => Messages::ProtoExecutionResult.new(:failed => false, :executionTime => 0))
34
39
  end
35
40
  end
36
- end
41
+ end
@@ -21,17 +21,17 @@ module Gauge
21
21
  module Processors
22
22
  include ExecutionHandler
23
23
 
24
- def process_execute_step_request(message)
25
- step_text = message.executeStepRequest.parsedStepText
26
- parameters = message.executeStepRequest.parameters
24
+ def process_execute_step_request(request)
25
+ step_text = request.parsedStepText
26
+ parameters = request.parameters
27
27
  args = create_param_values parameters
28
28
  start_time= Time.now
29
29
  begin
30
30
  Executor.execute_step step_text, args
31
31
  rescue Exception => e
32
- return handle_failure message, e, time_elapsed_since(start_time), MethodCache.recoverable?(step_text)
32
+ return handle_failure e, time_elapsed_since(start_time), MethodCache.recoverable?(step_text)
33
33
  end
34
- handle_pass message, time_elapsed_since(start_time)
34
+ handle_pass time_elapsed_since(start_time)
35
35
  end
36
36
  end
37
37
  end
@@ -16,34 +16,35 @@
16
16
  # along with Gauge-Ruby. If not, see <http://www.gnu.org/licenses/>.
17
17
 
18
18
  require 'os'
19
+ require_relative '../table'
19
20
 
20
21
  module Gauge
21
22
  module Processors
22
23
  # @api private
23
24
  module ExecutionHandler
24
- def handle_hooks_execution(hooks, message, currentExecutionInfo, should_filter=true)
25
+ def handle_hooks_execution(hooks, currentExecutionInfo, should_filter=true)
25
26
  start_time= Time.now
26
27
  execution_error = Executor.execute_hooks(hooks, currentExecutionInfo, should_filter)
27
28
  if execution_error == nil
28
- return handle_pass message, time_elapsed_since(start_time)
29
+ return handle_pass time_elapsed_since(start_time)
29
30
  else
30
- return handle_failure message, execution_error, time_elapsed_since(start_time), false
31
+ return handle_failure execution_error, time_elapsed_since(start_time), false
31
32
  end
32
33
  end
33
34
 
34
- def handle_pass(message, execution_time)
35
+ def handle_pass(execution_time)
35
36
  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.screenshotFiles += Gauge::GaugeScreenshot.instance.pending_screenshot
37
38
  execution_status_response.executionResult.message += Gauge::GaugeMessages.instance.pending_messages
38
- Messages::Message.new(:messageType => :ExecutionStatusResponse, :messageId => message.messageId, :executionStatusResponse => execution_status_response)
39
+ execution_status_response
39
40
  end
40
41
 
41
42
  def get_filepath(stacktrace)
42
43
  toptrace = stacktrace.split("\n").first
43
- return MethodCache.relative_filepath toptrace
44
+ MethodCache.relative_filepath toptrace
44
45
  end
45
46
 
46
- def handle_failure(message, exception, execution_time, recoverable)
47
+ def handle_failure(exception, execution_time, recoverable)
47
48
  project_dir = File.basename(Dir.getwd)
48
49
  stacktrace = exception.backtrace.select {|x| x.match(project_dir) && !x.match(File.join(project_dir, "vendor"))}.join("\n")+"\n"
49
50
  filepath = get_filepath(stacktrace)
@@ -56,15 +57,13 @@ module Gauge
56
57
  :errorMessage => exception.message,
57
58
  :stackTrace => code_snippet + stacktrace,
58
59
  :executionTime => execution_time))
59
- screenshot = screenshot_bytes
60
- if screenshot
61
- execution_status_response.executionResult.screenShot = screenshot
62
- execution_status_response.executionResult.failureScreenshot = screenshot
60
+ screenshot_file = take_screenshot
61
+ if screenshot_file
62
+ execution_status_response.executionResult.failureScreenshotFile = screenshot_file
63
63
  end
64
- execution_status_response.executionResult.screenshots += Gauge::GaugeScreenshot.instance.pending_screenshot
64
+ execution_status_response.executionResult.screenshotFiles += Gauge::GaugeScreenshot.instance.pending_screenshot
65
65
  execution_status_response.executionResult.message += Gauge::GaugeMessages.instance.pending_messages
66
- Messages::Message.new(:messageType => :ExecutionStatusResponse,
67
- :messageId => message.messageId, :executionStatusResponse => execution_status_response)
66
+ execution_status_response
68
67
  end
69
68
 
70
69
  def get_code_snippet(filename, number)
@@ -73,12 +72,12 @@ module Gauge
73
72
  number.to_s + " | " + line.strip + "\n\n"
74
73
  end
75
74
 
76
- def screenshot_bytes
77
- return nil if (ENV['screenshot_on_failure'] || "").downcase == "false" || (which("gauge_screenshot").nil? && !Configuration.instance.custom_screengrabber)
75
+ def take_screenshot
76
+ return nil if (ENV['screenshot_on_failure'] || "").downcase == "false" || (which("gauge_screenshot").nil? && !Configuration.instance.custom_screengrabber?)
78
77
  begin
79
- Configuration.instance.screengrabber.call
78
+ GaugeScreenshot.instance.capture_to_file
80
79
  rescue Exception => e
81
- Gauge::Log.error e
80
+ GaugeLog.error e
82
81
  return nil
83
82
  end
84
83
  end
@@ -25,63 +25,39 @@ module Gauge
25
25
  module Processors
26
26
  include ExecutionHandler
27
27
 
28
- def process_execution_start_request(message)
28
+ def process_execution_start_request(request)
29
29
  Gauge::MethodCache.clear
30
30
  Executor.load_steps(Util.get_step_implementation_dir)
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
33
- response.executionStatusResponse.executionResult.message += Gauge::GaugeMessages.instance.pending_messages
34
- return response
31
+ handle_hooks_execution(MethodCache.get_before_suite_hooks,request.currentExecutionInfo,false)
35
32
  end
36
33
 
37
- def process_execution_end_request(message)
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
40
- response.executionStatusResponse.executionResult.message += Gauge::GaugeMessages.instance.pending_messages
41
- return response
34
+ def process_execution_end_request(request)
35
+ handle_hooks_execution(MethodCache.get_after_suite_hooks, request.currentExecutionInfo, false)
42
36
  end
43
37
 
44
- def process_spec_execution_start_request(message)
45
- response = handle_hooks_execution(MethodCache.get_before_spec_hooks, message,message.specExecutionStartingRequest.currentExecutionInfo)
46
- response.executionStatusResponse.executionResult.screenshots += Gauge::GaugeScreenshot.instance.pending_screenshot
47
- response.executionStatusResponse.executionResult.message += Gauge::GaugeMessages.instance.pending_messages
48
- return response
38
+ def process_spec_execution_start_request(request)
39
+ handle_hooks_execution(MethodCache.get_before_spec_hooks,request.currentExecutionInfo)
49
40
  end
50
41
 
51
- def process_spec_execution_end_request(message)
52
- response = handle_hooks_execution(MethodCache.get_after_spec_hooks, message,message.specExecutionEndingRequest.currentExecutionInfo)
53
- response.executionStatusResponse.executionResult.screenshots += Gauge::GaugeScreenshot.instance.pending_screenshot
54
- response.executionStatusResponse.executionResult.message += Gauge::GaugeMessages.instance.pending_messages
55
- return response
42
+ def process_spec_execution_end_request(request)
43
+ handle_hooks_execution(MethodCache.get_after_spec_hooks,request.currentExecutionInfo)
56
44
  end
57
45
 
58
- def process_scenario_execution_start_request(message)
59
- response = handle_hooks_execution(MethodCache.get_before_scenario_hooks, message,message.scenarioExecutionStartingRequest.currentExecutionInfo)
60
- response.executionStatusResponse.executionResult.screenshots += Gauge::GaugeScreenshot.instance.pending_screenshot
61
- response.executionStatusResponse.executionResult.message += Gauge::GaugeMessages.instance.pending_messages
62
- return response
46
+ def process_scenario_execution_start_request(request)
47
+ handle_hooks_execution(MethodCache.get_before_scenario_hooks,request.currentExecutionInfo)
63
48
  end
64
49
 
65
50
 
66
- def process_scenario_execution_end_request(message)
67
- response = handle_hooks_execution(MethodCache.get_after_scenario_hooks, message,message.scenarioExecutionEndingRequest.currentExecutionInfo)
68
- response.executionStatusResponse.executionResult.screenshots += Gauge::GaugeScreenshot.instance.pending_screenshot
69
- response.executionStatusResponse.executionResult.message += Gauge::GaugeMessages.instance.pending_messages
70
- return response
51
+ def process_scenario_execution_end_request(request)
52
+ handle_hooks_execution(MethodCache.get_after_scenario_hooks,request.currentExecutionInfo)
71
53
  end
72
54
 
73
- def process_step_execution_start_request(message)
74
- response = handle_hooks_execution(MethodCache.get_before_step_hooks, message,message.stepExecutionStartingRequest.currentExecutionInfo)
75
- response.executionStatusResponse.executionResult.screenshots += Gauge::GaugeScreenshot.instance.pending_screenshot
76
- response.executionStatusResponse.executionResult.message += Gauge::GaugeMessages.instance.pending_messages
77
- return response
55
+ def process_step_execution_start_request(request)
56
+ handle_hooks_execution(MethodCache.get_before_step_hooks,request.currentExecutionInfo)
78
57
  end
79
58
 
80
- def process_step_execution_end_request(message)
81
- response = handle_hooks_execution(MethodCache.get_after_step_hooks, message,message.stepExecutionEndingRequest.currentExecutionInfo)
82
- response.executionStatusResponse.executionResult.screenshots += Gauge::GaugeScreenshot.instance.pending_screenshot
83
- response.executionStatusResponse.executionResult.message += Gauge::GaugeMessages.instance.pending_messages
84
- return response
59
+ def process_step_execution_end_request(request)
60
+ handle_hooks_execution(MethodCache.get_after_step_hooks,request.currentExecutionInfo)
85
61
  end
86
62
  end
87
63
  end
@@ -19,12 +19,7 @@ require_relative '../util'
19
19
 
20
20
  module Gauge
21
21
  module Processors
22
- def process_implementation_file_list_request(message)
23
- r = implementation_files()
24
- Messages::Message.new(:messageType => :ImplementationFileListResponse, :messageId => message.messageId, :implementationFileListResponse => r)
25
- end
26
-
27
- def implementation_files()
22
+ def process_implementation_file_list_request(_request)
28
23
  implPath = Util.get_step_implementation_dir
29
24
  fileList = Dir["#{implPath}/**/*.rb"]
30
25
  Messages::ImplementationFileListResponse.new(:implementationFilePaths => fileList)
@@ -19,16 +19,7 @@ require_relative '../util'
19
19
 
20
20
  module Gauge
21
21
  module Processors
22
- def process_implementation_glob_pattern_request(message)
23
- r = implementation_glob_pattern_response
24
- Messages::Message.new(
25
- messageType: Messages::Message::MessageType::ImplementationFileGlobPatternResponse,
26
- messageId: message.messageId,
27
- implementationFileGlobPatternResponse: r
28
- )
29
- end
30
-
31
- def implementation_glob_pattern_response
22
+ def process_implementation_glob_pattern_request(_request)
32
23
  implPath = Util.get_step_implementation_dir
33
24
  Messages::ImplementationFileGlobPatternResponse.new(globPatterns: ["#{implPath}/**/*.rb"])
34
25
  end
@@ -19,13 +19,7 @@ require_relative '../code_parser'
19
19
 
20
20
  module Gauge
21
21
  module Processors
22
- def refactor_step(message)
23
- request = message.refactorRequest
24
- response = refactor_response(request)
25
- Messages::Message.new(messageType: :RefactorResponse, messageId: message.messageId, refactorResponse: response)
26
- end
27
-
28
- def refactor_response(request)
22
+ def process_refactor_request(request)
29
23
  response = Messages::RefactorResponse.new(success: true)
30
24
  begin
31
25
  step_info = get_step request.oldStepValue.stepValue
@@ -17,15 +17,10 @@
17
17
 
18
18
  module Gauge
19
19
  module Processors
20
- def process_step_name_request(message)
21
- r = step_name_response(message.stepNameRequest)
22
- Messages::Message.new(messageType: :StepNameResponse, messageId: message.messageId, stepNameResponse: r)
23
- end
24
-
25
- def step_name_response(request)
20
+ def process_step_name_request(request)
26
21
  step_value = request.stepValue
27
22
  unless MethodCache.valid_step?(step_value)
28
- return Messages::StepNameResponse.new(isStepPresent: false, stepName: [''], hasAlias: false, fileName: '', span: nil)
23
+ return Messages::StepNameResponse.new(isStepPresent: false, stepName: [""], hasAlias: false, fileName: "", span: nil)
29
24
  end
30
25
  step_text = MethodCache.get_step_text(step_value)
31
26
  has_alias = MethodCache.has_alias?(step_text)
@@ -17,13 +17,7 @@
17
17
 
18
18
  module Gauge
19
19
  module Processors
20
- def process_step_names_request(message)
21
- r = step_names_response
22
- Messages::Message.new(messageType: :StepNamesResponse,
23
- messageId: message.messageId, stepNamesResponse: r)
24
- end
25
-
26
- def step_names_response
20
+ def process_step_names_request(_request)
27
21
  Messages::StepNamesResponse.new(steps: MethodCache.all_steps)
28
22
  end
29
23
  end
@@ -17,12 +17,7 @@
17
17
 
18
18
  module Gauge
19
19
  module Processors
20
- def process_step_positions_request(message)
21
- r = step_positions(message.stepPositionsRequest)
22
- Messages::Message.new(:messageType => :StepPositionsResponse, :messageId => message.messageId, :stepPositionsResponse => r)
23
- end
24
-
25
- def step_positions(request)
20
+ def process_step_positions_request(request)
26
21
  file = request.filePath
27
22
  positions = MethodCache.step_positions(file)
28
23
  p = create_step_position_messages(positions)
@@ -36,4 +31,4 @@ module Gauge
36
31
  end
37
32
  end
38
33
  end
39
- end
34
+ end
@@ -17,14 +17,7 @@
17
17
 
18
18
  module Gauge
19
19
  module Processors
20
- def process_step_validation_request(message)
21
- request = message.stepValidateRequest
22
- Messages::Message.new(messageType: :StepValidateResponse,
23
- messageId: message.messageId,
24
- stepValidateResponse: step_validate_response(request))
25
- end
26
-
27
- def step_validate_response(request)
20
+ def process_step_validation_request(request)
28
21
  response = Messages::StepValidateResponse.new(isValid: true)
29
22
  if !MethodCache.valid_step? request.stepText
30
23
  suggestion = request.stepValue.stepValue.empty? ? '' : create_suggestion(request.stepValue)
@@ -19,12 +19,7 @@ require_relative '../../lib/util'
19
19
 
20
20
  module Gauge
21
21
  module Processors
22
- def process_stub_implementation_code_request(message)
23
- file_diff = implement_stub_response(message.stubImplementationCodeRequest)
24
- Messages::Message.new(messageType: :FileDiff, messageId: message.messageId, fileDiff: file_diff)
25
- end
26
-
27
- def implement_stub_response(request)
22
+ def process_stub_implementation_code_request(request)
28
23
  codes = request.codes
29
24
  file_path = request.implementationFilePath
30
25
  content = ''
@@ -0,0 +1,122 @@
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 "services_services_pb"
19
+ Dir[File.join(File.dirname(__FILE__), "processors/*.rb")].each { |file| require file }
20
+
21
+ module Gauge
22
+ class ExecutionHandler < Messages::Runner::Service
23
+ include Processors
24
+
25
+ def initialize(server)
26
+ @server = server
27
+ end
28
+
29
+ def initialize_suite_data_store(request, _call)
30
+ process_suite_data_store_init_request(request)
31
+ end
32
+
33
+ def initialize_spec_data_store(request, _call)
34
+ process_spec_data_store_init_request(request)
35
+ end
36
+
37
+ def initialize_scenario_data_store(request, _call)
38
+ process_scenario_data_store_init_request(request)
39
+ end
40
+
41
+ def start_execution(request, _call)
42
+ process_execution_start_request(request)
43
+ end
44
+
45
+ def finish_execution(request, _call)
46
+ process_execution_end_request(request)
47
+ end
48
+
49
+ def start_spec_execution(request, _call)
50
+ process_spec_execution_start_request(request)
51
+ end
52
+
53
+ def finish_spec_execution(request, _call)
54
+ process_spec_execution_end_request(request)
55
+ end
56
+
57
+ def start_scenario_execution(request, _call)
58
+ process_scenario_execution_start_request(request)
59
+ end
60
+
61
+ def finish_scenario_execution(request, _call)
62
+ process_scenario_execution_end_request(request)
63
+ end
64
+
65
+ def start_step_execution(request, _call)
66
+ process_step_execution_start_request(request)
67
+ end
68
+
69
+ def finish_step_execution(request, _call)
70
+ process_step_execution_end_request(request)
71
+ end
72
+
73
+ def execute_step(request, _call)
74
+ process_execute_step_request(request)
75
+ end
76
+
77
+ def get_step_names(request, _call)
78
+ process_step_names_request(request)
79
+ end
80
+
81
+ def cache_file(request, _call)
82
+ process_cache_file_request(request)
83
+ end
84
+
85
+ def get_step_positions(request, _call)
86
+ process_step_positions_request(request)
87
+ end
88
+
89
+ def get_implementation_files(request, _call)
90
+ process_implementation_file_list_request(request)
91
+ end
92
+
93
+ def implement_stub(request, _call)
94
+ process_stub_implementation_code_request(request)
95
+ end
96
+
97
+ def refactor(request, _call)
98
+ process_refactor_request(request)
99
+ end
100
+
101
+ def get_step_name(request, _call)
102
+ process_step_name_request(request)
103
+ end
104
+
105
+ def get_glob_patterns(request, _call)
106
+ process_implementation_glob_pattern_request(request)
107
+ end
108
+
109
+ def validate_step(request, _call)
110
+ process_step_validation_request(request)
111
+ end
112
+
113
+ def kill(_request, _call)
114
+ Thread.new do
115
+ sleep 0.1
116
+ @server.stop
117
+ exit(0)
118
+ end.run
119
+ Messages::Empty.new
120
+ end
121
+ end
122
+ end