Class: Lucid::Runtime::Orchestrator
- Includes:
- ObjectFactory
- Defined in:
- lib/lucid/runtime/orchestrator.rb
Defined Under Namespace
Classes: StepInvoker
Instance Method Summary collapse
- #around(scenario, block) ⇒ Object
- #configure(new_configuration) ⇒ Object
- #fire_hook(name, *args) ⇒ Object
-
#initialize(user_interface, configuration = {}) ⇒ Orchestrator
constructor
A new instance of Orchestrator.
- #invoke(step_name, multiline_argument = nil) ⇒ Object
-
#invoke_steps(steps_text, i18n, file_colon_line) ⇒ Object
Invokes a series of steps
steps_text
. -
#load_code_language(code) ⇒ Object
The orchestrator will register the the code language and load up an implementation of that language.
-
#load_files(files) ⇒ Object
The orchestrator will load only the loadable execution context files.
- #load_files_from_paths(paths) ⇒ Object
-
#matcher_text(step_keyword, step_name, multiline_arg_class) ⇒ Object
:nodoc:.
- #step_definitions ⇒ Object
-
#step_match(step_name, name_to_report = nil) ⇒ Object
:nodoc:.
- #unknown_programming_language? ⇒ Boolean
- #unmatched_step_definitions ⇒ Object
Methods included from ObjectFactory
#create_object_of, #underscore
Constructor Details
#initialize(user_interface, configuration = {}) ⇒ Orchestrator
Returns a new instance of Orchestrator.
32 33 34 35 36 37 38 |
# File 'lib/lucid/runtime/orchestrator.rb', line 32 def initialize(user_interface, configuration={}) @configuration = Configuration.parse(configuration) @runtime_facade = Runtime::Facade.new(self, user_interface) @unsupported_languages = [] @supported_languages = [] @language_map = {} end |
Instance Method Details
#around(scenario, block) ⇒ Object
118 119 120 121 122 123 124 125 126 |
# File 'lib/lucid/runtime/orchestrator.rb', line 118 def around(scenario, block) @supported_languages.reverse.inject(block) do |blk, programming_language| proc do programming_language.around(scenario) do blk.call(scenario) end end end.call end |
#configure(new_configuration) ⇒ Object
40 41 42 |
# File 'lib/lucid/runtime/orchestrator.rb', line 40 def configure(new_configuration) @configuration = Configuration.parse(new_configuration) end |
#fire_hook(name, *args) ⇒ Object
112 113 114 115 116 |
# File 'lib/lucid/runtime/orchestrator.rb', line 112 def fire_hook(name, *args) @supported_languages.each do |programming_language| programming_language.send(name, *args) end end |
#invoke(step_name, multiline_argument = nil) ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/lucid/runtime/orchestrator.rb', line 56 def invoke(step_name, multiline_argument=nil) multiline_argument = Lucid::AST::MultilineArgument.from(multiline_argument) begin step_match(step_name).invoke(multiline_argument) rescue Exception => e e.nested! if Undefined === e raise e end end |
#invoke_steps(steps_text, i18n, file_colon_line) ⇒ Object
Invokes a series of steps steps_text
. Example:
invoke(%Q{
Given lucid exists
Then test specs can be executed
})
50 51 52 53 54 |
# File 'lib/lucid/runtime/orchestrator.rb', line 50 def invoke_steps(steps_text, i18n, file_colon_line) file, line = file_colon_line.split(':') parser = Gherkin::Parser::Parser.new(StepInvoker.new(self), true, 'steps', false, i18n.iso_code) parser.parse(steps_text, file, line.to_i) end |
#load_code_language(code) ⇒ Object
The orchestrator will register the the code language and load up an implementation of that language. There is a provision to make sure that the language is not already registered.
69 70 71 72 73 74 75 76 |
# File 'lib/lucid/runtime/orchestrator.rb', line 69 def load_code_language(code) return @language_map[code] if @language_map[code] lucid_language = create_object_of("Lucid::Interface#{code.capitalize}::#{code.capitalize}Language") language = lucid_language.new(@runtime_facade) @supported_languages << language @language_map[code] = language language end |
#load_files(files) ⇒ Object
The orchestrator will load only the loadable execution context files. This is how the orchestrator will, quite literally, orchestrate the execution of specs with the code logic that supports those specs.
82 83 84 85 86 87 88 |
# File 'lib/lucid/runtime/orchestrator.rb', line 82 def load_files(files) log.info("Orchestrator Load Files:\n") files.each do |file| load_file(file) end log.info("\n") end |
#load_files_from_paths(paths) ⇒ Object
90 91 92 93 |
# File 'lib/lucid/runtime/orchestrator.rb', line 90 def load_files_from_paths(paths) files = paths.map { |path| Dir["#{path}/**/*"] }.flatten load_files files end |
#matcher_text(step_keyword, step_name, multiline_arg_class) ⇒ Object
:nodoc:
101 102 103 104 105 106 |
# File 'lib/lucid/runtime/orchestrator.rb', line 101 def matcher_text(step_keyword, step_name, multiline_arg_class) #:nodoc: load_code_language('rb') if unknown_programming_language? @supported_languages.map do |programming_language| programming_language.matcher_text(step_keyword, step_name, multiline_arg_class, @configuration.matcher_type) end.join("\n") end |
#step_definitions ⇒ Object
128 129 130 131 132 |
# File 'lib/lucid/runtime/orchestrator.rb', line 128 def step_definitions @supported_languages.map do |programming_language| programming_language.step_definitions end.flatten end |
#step_match(step_name, name_to_report = nil) ⇒ Object
:nodoc:
134 135 136 137 138 139 140 141 |
# File 'lib/lucid/runtime/orchestrator.rb', line 134 def step_match(step_name, name_to_report=nil) #:nodoc: @match_cache ||= {} match = @match_cache[[step_name, name_to_report]] return match if match @match_cache[[step_name, name_to_report]] = step_match_without_cache(step_name, name_to_report) end |
#unknown_programming_language? ⇒ Boolean
108 109 110 |
# File 'lib/lucid/runtime/orchestrator.rb', line 108 def unknown_programming_language? @supported_languages.empty? end |
#unmatched_step_definitions ⇒ Object
95 96 97 98 99 |
# File 'lib/lucid/runtime/orchestrator.rb', line 95 def unmatched_step_definitions @supported_languages.map do |programming_language| programming_language.unmatched_step_definitions end.flatten end |