Class: Lucid::ContextLoader::Orchestrator
- Includes:
- Factory
- Defined in:
- lib/lucid/orchestrator.rb
Defined Under Namespace
Classes: StepInvoker
Instance Method Summary collapse
- #around(scenario, block) ⇒ Object
- #configure(new_context) ⇒ Object
- #fire_hook(name, *args) ⇒ Object
-
#initialize(user_interface, context = {}) ⇒ 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(type) ⇒ 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
- #step_definitions ⇒ Object
- #step_match(step_name, name_to_report = nil) ⇒ Object
- #unknown_programming_language? ⇒ Boolean
- #unmatched_step_definitions ⇒ Object
Methods included from Factory
Constructor Details
#initialize(user_interface, context = {}) ⇒ Orchestrator
Returns a new instance of Orchestrator.
30 31 32 33 34 35 36 |
# File 'lib/lucid/orchestrator.rb', line 30 def initialize(user_interface, context={}) @context = Context.parse(context) @runtime_facade = ContextLoader::Facade.new(self, user_interface) @unsupported_languages = [] @supported_languages = [] @language_map = {} end |
Instance Method Details
#around(scenario, block) ⇒ Object
121 122 123 124 125 126 127 128 129 |
# File 'lib/lucid/orchestrator.rb', line 121 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_context) ⇒ Object
38 39 40 |
# File 'lib/lucid/orchestrator.rb', line 38 def configure(new_context) @context = Context.parse(new_context) end |
#fire_hook(name, *args) ⇒ Object
115 116 117 118 119 |
# File 'lib/lucid/orchestrator.rb', line 115 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
54 55 56 57 58 59 60 61 62 |
# File 'lib/lucid/orchestrator.rb', line 54 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
})
48 49 50 51 52 |
# File 'lib/lucid/orchestrator.rb', line 48 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(type) ⇒ 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.
70 71 72 73 74 75 76 77 |
# File 'lib/lucid/orchestrator.rb', line 70 def load_code_language(type) return @language_map[type] if @language_map[type] lucid_language = create_object_of("Lucid::Interface#{type.capitalize}::#{type.capitalize}Language") language = lucid_language.new(@runtime_facade) @supported_languages << language @language_map[type] = 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.
85 86 87 88 89 90 91 |
# File 'lib/lucid/orchestrator.rb', line 85 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
93 94 95 96 |
# File 'lib/lucid/orchestrator.rb', line 93 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
104 105 106 107 108 109 |
# File 'lib/lucid/orchestrator.rb', line 104 def matcher_text(step_keyword, step_name, multiline_arg_class) 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, @context.matcher_type) end.join("\n") end |
#step_definitions ⇒ Object
131 132 133 134 135 |
# File 'lib/lucid/orchestrator.rb', line 131 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
137 138 139 140 141 142 143 144 |
# File 'lib/lucid/orchestrator.rb', line 137 def step_match(step_name, name_to_report=nil) @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
111 112 113 |
# File 'lib/lucid/orchestrator.rb', line 111 def unknown_programming_language? @supported_languages.empty? end |
#unmatched_step_definitions ⇒ Object
98 99 100 101 102 |
# File 'lib/lucid/orchestrator.rb', line 98 def unmatched_step_definitions @supported_languages.map do |programming_language| programming_language.unmatched_step_definitions end.flatten end |