Module: Gauge::Processors Private

Includes:
ExecutionHandler
Included in:
ExecutionHandler
Defined in:
lib/processors/cache_file_processor.rb,
lib/processors/execution_handler.rb,
lib/processors/kill_request_processor.rb,
lib/processors/datastore_init_processor.rb,
lib/processors/execution_hook_processors.rb,
lib/processors/step_name_request_processor.rb,
lib/processors/step_names_request_processor.rb,
lib/processors/stub_implementation_processor.rb,
lib/processors/execute_step_request_processor.rb,
lib/processors/refactor_step_request_processor.rb,
lib/processors/step_positions_request_processor.rb,
lib/processors/step_validation_request_processor.rb,
lib/processors/implementation_file_list_processor.rb,
lib/processors/implementation_glob_pattern_processor.rb

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Defined Under Namespace

Modules: ExecutionHandler

Instance Method Summary collapse

Methods included from ExecutionHandler

#create_param_values, #get_code_snippet, #get_filepath, #handle_failure, #handle_hooks_execution, #handle_pass, #take_screenshot, #time_elapsed_since

Instance Method Details

#create_step_position_messages(positions) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



15
16
17
18
19
20
# File 'lib/processors/step_positions_request_processor.rb', line 15

def create_step_position_messages(positions)
  positions.map do |p|
    span = Gauge::Messages::Span.new(:start => p[:span].begin.line, :end => p[:span].end.line, :startChar => p[:span].begin.column, :endChar => p[:span].end.column)
    Messages::StepPositionsResponse::StepPosition.new(:stepValue => p[:stepValue], :span => span)
  end
end

#create_suggestion(step_value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



28
29
30
31
32
33
# File 'lib/processors/step_validation_request_processor.rb', line 28

def create_suggestion(step_value)
  count = -1
  step_text = step_value.stepValue.gsub(/{}/) { "<arg#{count += 1}>" }
  params = step_value.parameters.map.with_index { |_v, i| "arg#{i}" }.join ', '
  "step '#{step_text}' do |#{params}|\n\traise 'Unimplemented Step'\nend"
end

#datastore_responseObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



25
26
27
# File 'lib/processors/datastore_init_processor.rb', line 25

def datastore_response
  Messages::ExecutionStatusResponse.new(:executionResult => Messages::ProtoExecutionResult.new(:failed => false, :executionTime => 0))
end

#get_step(step_text) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



27
28
29
30
31
# File 'lib/processors/refactor_step_request_processor.rb', line 27

def get_step(step_text)
  md = MethodCache.multiple_implementation? step_text
  raise "Multiple step implementations found for => '#{step_text}'" if md
  MethodCache.get_step_info(step_text)
end

#process_cache_file_request(request) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/processors/cache_file_processor.rb', line 12

def process_cache_file_request(request)
  f = request.filePath
  status =  Messages::CacheFileRequest::FileStatus.resolve(request.status)
  if (status == Messages::CacheFileRequest::FileStatus::CHANGED) || (status == Messages::CacheFileRequest::FileStatus::OPENED)
    ast = CodeParser.code_to_ast(request.content)
    StaticLoader.reload_steps(f, ast)
  elsif status == Messages::CacheFileRequest::FileStatus::CREATED
    if !Gauge::MethodCache.is_file_cached f
      ast = CodeParser.code_to_ast File.read(f)
      StaticLoader.reload_steps(f, ast)
    end
  elsif (status == Messages::CacheFileRequest::FileStatus::CLOSED) && File.file?(f)
    ast = CodeParser.code_to_ast File.read(f)
    StaticLoader.reload_steps(f, ast)
  else
    StaticLoader.remove_steps(f)
  end
  Messages::Empty.new
end

#process_execute_step_request(request) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/processors/execute_step_request_processor.rb', line 12

def process_execute_step_request(request)
  step_text = request.parsedStepText
  parameters = request.parameters
  args = create_param_values parameters
  start_time= Time.now
  begin
    Executor.execute_step step_text, args
  rescue Exception => e
    return handle_failure e, time_elapsed_since(start_time), MethodCache.recoverable?(step_text)
  end
  handle_pass time_elapsed_since(start_time)
end

#process_execution_end_request(request) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



22
23
24
# File 'lib/processors/execution_hook_processors.rb', line 22

def process_execution_end_request(request)
  handle_hooks_execution(MethodCache.get_after_suite_hooks, request.currentExecutionInfo, false)
end

#process_execution_start_request(request) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



16
17
18
19
20
# File 'lib/processors/execution_hook_processors.rb', line 16

def process_execution_start_request(request)
  Gauge::MethodCache.clear
  Executor.load_steps(Util.get_step_implementation_dir)
  handle_hooks_execution(MethodCache.get_before_suite_hooks,request.currentExecutionInfo,false)
end

#process_implementation_file_list_request(_request) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



10
11
12
13
14
# File 'lib/processors/implementation_file_list_processor.rb', line 10

def process_implementation_file_list_request(_request)
  implPath = Util.get_step_implementation_dir
  fileList = Dir["#{implPath}/**/*.rb"]
  Messages::ImplementationFileListResponse.new(:implementationFilePaths => fileList)
end

#process_implementation_glob_pattern_request(_request) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



10
11
12
13
# File 'lib/processors/implementation_glob_pattern_processor.rb', line 10

def process_implementation_glob_pattern_request(_request)
  implPath = Util.get_step_implementation_dir
  Messages::ImplementationFileGlobPatternResponse.new(globPatterns: ["#{implPath}/**/*.rb"])
end

#process_kill_processor_request(message) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



9
10
11
# File 'lib/processors/kill_request_processor.rb', line 9

def process_kill_processor_request(message)
  return message
end

#process_refactor_request(request) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/processors/refactor_step_request_processor.rb', line 10

def process_refactor_request(request)
  response = Messages::RefactorResponse.new(success: true)
  begin
    step_info = get_step request.oldStepValue.stepValue
    refactored_info = CodeParser.refactor step_info, request.paramPositions, request.newStepValue
    file = step_info[:locations][0][:file]
    File.write file, refactored_info[:content] if request.saveChanges
    response.filesChanged.push(file)
    changes = Messages::FileChanges.new(fileName: file, fileContent: refactored_info[:content], diffs: refactored_info[:diffs])
    response.fileChanges.push(changes)
  rescue Exception => e
    response.success = false
    response.error = e.message
  end
  response
end

#process_scenario_data_store_init_request(_request) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



20
21
22
23
# File 'lib/processors/datastore_init_processor.rb', line 20

def process_scenario_data_store_init_request(_request)
  DataStoreFactory.scenario_datastore.clear
  datastore_response
end

#process_scenario_execution_end_request(request) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



39
40
41
# File 'lib/processors/execution_hook_processors.rb', line 39

def process_scenario_execution_end_request(request)
  handle_hooks_execution(MethodCache.get_after_scenario_hooks,request.currentExecutionInfo)
end

#process_scenario_execution_start_request(request) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



34
35
36
# File 'lib/processors/execution_hook_processors.rb', line 34

def process_scenario_execution_start_request(request)
  handle_hooks_execution(MethodCache.get_before_scenario_hooks,request.currentExecutionInfo)
end

#process_spec_data_store_init_request(_request) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



15
16
17
18
# File 'lib/processors/datastore_init_processor.rb', line 15

def process_spec_data_store_init_request(_request)
  DataStoreFactory.spec_datastore.clear
  datastore_response
end

#process_spec_execution_end_request(request) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



30
31
32
# File 'lib/processors/execution_hook_processors.rb', line 30

def process_spec_execution_end_request(request)
  handle_hooks_execution(MethodCache.get_after_spec_hooks,request.currentExecutionInfo)
end

#process_spec_execution_start_request(request) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



26
27
28
# File 'lib/processors/execution_hook_processors.rb', line 26

def process_spec_execution_start_request(request)
  handle_hooks_execution(MethodCache.get_before_spec_hooks,request.currentExecutionInfo)
end

#process_step_execution_end_request(request) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



47
48
49
# File 'lib/processors/execution_hook_processors.rb', line 47

def process_step_execution_end_request(request)
  handle_hooks_execution(MethodCache.get_after_step_hooks,request.currentExecutionInfo)
end

#process_step_execution_start_request(request) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



43
44
45
# File 'lib/processors/execution_hook_processors.rb', line 43

def process_step_execution_start_request(request)
  handle_hooks_execution(MethodCache.get_before_step_hooks,request.currentExecutionInfo)
end

#process_step_name_request(request) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/processors/step_name_request_processor.rb', line 8

def process_step_name_request(request)
  step_value = request.stepValue
  unless MethodCache.valid_step?(step_value)
    return Messages::StepNameResponse.new(isStepPresent: false, stepName: [""], hasAlias: false, fileName: "", span: nil)
  end
  step_text = MethodCache.get_step_text(step_value)
  has_alias = MethodCache.has_alias?(step_text)
  loc = MethodCache.get_step_info(step_value)[:locations][0]
  span = Gauge::Messages::Span.new(start: loc[:span].begin.line, end: loc[:span].end.line, startChar: loc[:span].begin.column, endChar: loc[:span].end.column)
  Messages::StepNameResponse.new(isStepPresent: true, stepName: [step_text], hasAlias: has_alias, fileName: loc[:file], span: span)
end

#process_step_names_request(_request) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



8
9
10
# File 'lib/processors/step_names_request_processor.rb', line 8

def process_step_names_request(_request)
  Messages::StepNamesResponse.new(steps: MethodCache.all_steps)
end

#process_step_positions_request(request) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



8
9
10
11
12
13
# File 'lib/processors/step_positions_request_processor.rb', line 8

def process_step_positions_request(request)
  file = request.filePath
  positions = MethodCache.step_positions(file)
  p = create_step_position_messages(positions)
  Messages::StepPositionsResponse.new(:stepPositions => p)
end

#process_step_validation_request(request) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/processors/step_validation_request_processor.rb', line 8

def process_step_validation_request(request)
  response = Messages::StepValidateResponse.new(isValid: true)
  if !MethodCache.valid_step? request.stepText
    suggestion = request.stepValue.stepValue.empty? ? '' : create_suggestion(request.stepValue)
    response = Messages::StepValidateResponse.new(
      isValid: false,
      errorMessage: 'Step implementation not found',
      errorType: Messages::StepValidateResponse::ErrorType::STEP_IMPLEMENTATION_NOT_FOUND,
      suggestion: suggestion
    )
  elsif MethodCache.multiple_implementation?(request.stepText)
    response = Messages::StepValidateResponse.new(
      isValid: false,
      errorMessage: "Multiple step implementations found for => '#{request.stepText}'",
      errorType: Messages::StepValidateResponse::ErrorType::DUPLICATE_STEP_IMPLEMENTATION
    )
  end
  response
end

#process_stub_implementation_code_request(request) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/processors/stub_implementation_processor.rb', line 10

def process_stub_implementation_code_request(request)
  codes = request.codes
  file_path = request.implementationFilePath
  content = ''
  if File.file? file_path
    content = File.read(file_path)
  else
    file_path = Util.get_file_name
  end
  text_diffs = [Messages::TextDiff.new(span: create_span(content, codes), content: codes.join("\n"))]
  Messages::FileDiff.new(filePath: file_path, textDiffs: text_diffs)
end

#process_suite_data_store_init_request(_request) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



10
11
12
13
# File 'lib/processors/datastore_init_processor.rb', line 10

def process_suite_data_store_init_request(_request)
  DataStoreFactory.suite_datastore.clear
  datastore_response
end