gauge-ruby 0.0.4.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.
@@ -0,0 +1,81 @@
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
+ require_relative 'configuration'
19
+ module Gauge
20
+ # @api private
21
+ class MethodCache
22
+ HOOKS.each { |hook|
23
+ define_singleton_method "add_#{hook}_hook" do |&block|
24
+ self.class_variable_get("@@#{hook}_hooks").push block
25
+ end
26
+ define_singleton_method "get_#{hook}_hooks" do
27
+ self.class_variable_get("@@#{hook}_hooks")
28
+ end
29
+ }
30
+
31
+ def self.add_step(parameterized_step_text, &block)
32
+ @@steps_map[parameterized_step_text] = block
33
+ end
34
+
35
+ def self.get_step(parameterized_step_text)
36
+ @@steps_map[parameterized_step_text]
37
+ end
38
+
39
+ def self.add_step_text(parameterized_step_text, step_text)
40
+ @@steps_text_map[parameterized_step_text] = step_text
41
+ end
42
+
43
+ def self.get_step_text(parameterized_step_text)
44
+ @@steps_text_map[parameterized_step_text]
45
+ end
46
+
47
+ def self.add_step_alias(*step_texts)
48
+ @@steps_with_aliases.push *step_texts if step_texts.length > 1
49
+ end
50
+
51
+ def self.has_alias?(step_text)
52
+ @@steps_with_aliases.include? step_text
53
+ end
54
+
55
+ def self.valid_step?(step)
56
+ @@steps_map.has_key? step
57
+ end
58
+
59
+ def self.all_steps
60
+ @@steps_map.keys
61
+ end
62
+
63
+ private
64
+ HOOKS = ["before_step", "after_step", "before_spec", "after_spec", "before_scenario", "after_scenario", "before_suite", "after_suite"]
65
+ @@steps_map = Hash.new
66
+ @@steps_text_map = Hash.new
67
+ @@steps_with_aliases = []
68
+ @@before_suite_hooks = []
69
+ @@after_suite_hooks = []
70
+ @@before_spec_hooks = []
71
+ @@after_spec_hooks = []
72
+ @@before_scenario_hooks = []
73
+ @@after_scenario_hooks = []
74
+ @@before_step_hooks = []
75
+ @@after_step_hooks = []
76
+ end
77
+
78
+ # hack : get the 'main' object and include the configured includes there.
79
+ # can be removed once we have scoped execution.
80
+ MethodCache.add_before_suite_hook { Configuration.include_configured_modules }
81
+ end
@@ -0,0 +1,36 @@
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
+ require_relative '../datastore'
19
+
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)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,37 @@
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
+ require_relative "execution_handler"
19
+
20
+ module Gauge
21
+ module Processors
22
+ include ExecutionHandler
23
+
24
+ def process_execute_step_request(message)
25
+ step_text = message.executeStepRequest.parsedStepText
26
+ parameters = message.executeStepRequest.parameters
27
+ args = create_param_values parameters
28
+ start_time= Time.now
29
+ begin
30
+ Executor.execute_step step_text, args
31
+ rescue Exception => e
32
+ return handle_failure message, e, time_elapsed_since(start_time)
33
+ end
34
+ handle_pass message, time_elapsed_since(start_time)
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,83 @@
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
+ require 'os'
19
+
20
+ module Gauge
21
+ module Processors
22
+ # @api private
23
+ module ExecutionHandler
24
+ def handle_hooks_execution(hooks, message, currentExecutionInfo)
25
+ start_time= Time.now
26
+ execution_error = Executor.execute_hooks(hooks, currentExecutionInfo)
27
+ if execution_error == nil
28
+ return handle_pass message, time_elapsed_since(start_time)
29
+ else
30
+ return handle_failure message, execution_error, time_elapsed_since(start_time)
31
+ end
32
+ end
33
+
34
+ def handle_pass(message, execution_time)
35
+ 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)
37
+ end
38
+
39
+ def handle_failure(message, exception, execution_time)
40
+ execution_status_response =
41
+ Messages::ExecutionStatusResponse.new(
42
+ :executionResult => Messages::ProtoExecutionResult.new(:failed => true,
43
+ :recoverableError => false,
44
+ :errorMessage => exception.message,
45
+ :stackTrace => exception.backtrace.join("\n")+"\n",
46
+ :executionTime => execution_time,
47
+ :screenShot => screenshot_bytes))
48
+ Messages::Message.new(:messageType => Messages::Message::MessageType::ExecutionStatusResponse,
49
+ :messageId => message.messageId, :executionStatusResponse => execution_status_response)
50
+ end
51
+
52
+ def screenshot_bytes
53
+ return nil if (ENV['screenshot_enabled'] || "").downcase == "false"
54
+ # todo: make it platform independent
55
+ if (OS.mac?)
56
+ file = File.open("#{Dir.tmpdir}/screenshot.png", "w+")
57
+ `screencapture #{file.path}`
58
+ file_content = File.binread(file.path)
59
+ File.delete file
60
+ return file_content
61
+ end
62
+ return nil
63
+ end
64
+
65
+ def time_elapsed_since(start_time)
66
+ ((Time.now-start_time) * 1000).round
67
+ end
68
+
69
+ def create_param_values parameters
70
+ params = []
71
+ parameters.each do |param|
72
+ if ((param.parameterType == Messages::Parameter::ParameterType::Table) ||(param.parameterType == Messages::Parameter::ParameterType::Special_Table))
73
+ gtable = Gauge::Table.new(param.table)
74
+ params.push gtable
75
+ else
76
+ params.push param.value
77
+ end
78
+ end
79
+ return params
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,56 @@
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
+ require_relative "execution_handler"
19
+
20
+ module Gauge
21
+ module Processors
22
+ include ExecutionHandler
23
+
24
+ def process_execution_start_request(message)
25
+ handle_hooks_execution(MethodCache.get_before_suite_hooks, message, message.executionStartingRequest.currentExecutionInfo)
26
+ end
27
+
28
+ def process_execution_end_request(message)
29
+ handle_hooks_execution(MethodCache.get_after_suite_hooks, message, message.executionEndingRequest.currentExecutionInfo)
30
+ end
31
+
32
+ def process_spec_execution_start_request(message)
33
+ handle_hooks_execution(MethodCache.get_before_spec_hooks, message, message.specExecutionStartingRequest.currentExecutionInfo)
34
+ end
35
+
36
+ def process_spec_execution_end_request(message)
37
+ handle_hooks_execution(MethodCache.get_after_spec_hooks, message, message.specExecutionEndingRequest.currentExecutionInfo)
38
+ end
39
+
40
+ def process_scenario_execution_start_request(message)
41
+ handle_hooks_execution(MethodCache.get_before_scenario_hooks, message, message.scenarioExecutionStartingRequest.currentExecutionInfo)
42
+ end
43
+
44
+ def process_scenario_execution_end_request(message)
45
+ handle_hooks_execution(MethodCache.get_after_scenario_hooks, message, message.scenarioExecutionEndingRequest.currentExecutionInfo)
46
+ end
47
+
48
+ def process_step_execution_start_request(message)
49
+ handle_hooks_execution(MethodCache.get_before_step_hooks, message, message.stepExecutionStartingRequest.currentExecutionInfo)
50
+ end
51
+
52
+ def process_step_execution_end_request(message)
53
+ handle_hooks_execution(MethodCache.get_after_step_hooks, message, message.stepExecutionEndingRequest.currentExecutionInfo)
54
+ end
55
+ end
56
+ end
@@ -0,0 +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
+
18
+ module Gauge
19
+ # @api private
20
+ module Processors
21
+ def process_kill_processor_request(message)
22
+ return message
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,36 @@
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
+ require_relative '../code_parser'
19
+
20
+ module Gauge
21
+ module Processors
22
+ def refactor_step(message)
23
+ oldStepValue = message.refactorRequest.oldStepValue.stepValue
24
+ newStep = message.refactorRequest.newStepValue
25
+ stepBlock = MethodCache.get_step oldStepValue
26
+ refactor_response = Messages::RefactorResponse.new(success: true)
27
+ begin
28
+ CodeParser.refactor stepBlock, message.refactorRequest.paramPositions, newStep.parameters, newStep.parameterizedStepValue
29
+ rescue Exception => e
30
+ refactor_response.success=false
31
+ refactor_response.error=e.message
32
+ end
33
+ Messages::Message.new(:messageType => Messages::Message::MessageType::RefactorResponse, :messageId => message.messageId, refactorResponse: refactor_response)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,29 @@
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
+ module Gauge
19
+ module Processors
20
+ def process_step_name_request(message)
21
+ parsed_step_text = message.stepNameRequest.stepValue
22
+ is_valid = MethodCache.valid_step?(parsed_step_text)
23
+ step_text = is_valid ? MethodCache.get_step_text(parsed_step_text) : ""
24
+ has_alias = MethodCache.has_alias?(step_text)
25
+ get_step_name_response = Messages::StepNameResponse.new(isStepPresent: is_valid, stepName: [step_text], hasAlias: has_alias)
26
+ Messages::Message.new(:messageType => Messages::Message::MessageType::StepNameResponse, :messageId => message.messageId, :stepNameResponse => get_step_name_response)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,26 @@
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
+ module Gauge
19
+ module Processors
20
+ def process_step_names_request(message)
21
+ step_names_response = Messages::StepNamesResponse.new(:steps => MethodCache.all_steps)
22
+ Messages::Message.new(:messageType => Messages::Message::MessageType::StepNamesResponse,
23
+ :messageId => message.messageId, :stepNamesResponse => step_names_response)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,30 @@
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
+ module Gauge
19
+ module Processors
20
+ def process_step_validation_request(message)
21
+ step_validate_request = message.stepValidateRequest
22
+ is_valid = MethodCache.valid_step?(step_validate_request.stepText)
23
+ step_validate_response = Messages::StepValidateResponse.new(:isValid => is_valid,
24
+ :errorMessage => is_valid ? "" : "Step implementation not found")
25
+ Messages::Message.new(:messageType => Messages::Message::MessageType::StepValidateResponse,
26
+ :messageId => message.messageId,
27
+ :stepValidateResponse => step_validate_response)
28
+ end
29
+ end
30
+ end