lib/henry/container.rb in henry-container-0.0.20 vs lib/henry/container.rb in henry-container-0.0.22

- old
+ new

@@ -18,12 +18,12 @@ # Executes the loaded tasks and stores their results. def execute self.before_execution - self.tasks_results = self.tasks.collect do |task| - task.execute(self.task_params(task.name)) + self.tasks.each do |task| + self.task_results << task.execute(self.task_params(task.name)) if task.enabled? end self.update_results self.dump_results @@ -57,36 +57,52 @@ # # @return [String] the output file path. def output_file_path "#{@opts[:"out-dir"]}/#{@opts[:out]}" end + + # Returns the task hints file path based on the given options. + # + # @return [String] the task hints file path. + def hints_file_path + "#{@opts[:"hints-dir"]}/#{@opts[:hints]}" + end # Executes required validations before execution. def before_execution - unless File.exists?(self.input_file_path) - abort "#{"'#{self.input_file_path}' file does not exist.".red}\n #{'*'.red} If running isolated make sure to create it first.\n #{'*'.red} If running from Henry contact us at henry@despegar.it." - end unless File.exists?('henry-context.yml') abort "'henry-context.yml' file does not exist. You need it in order to execute a Henry compatible test.".red end end - # Loads and parses the @opts[:in] params. + # Returns the execution params. # # @return [{String => String}] the execution params. def params - @params ||= JSON.parse(File.read(self.input_file_path)) + @params ||= self.load_params + + if File.exists?(self.input_file_path) + @params ||= JSON.parse(File.read(self.input_file_path)) end + # Loads and parses the @opts[:in] params, if they exists. + # + # @return [{String => String}] the execution params. + def load_params + return {} unless File.exists?(self.input_file_path) + + JSON.parse(File.read(self.input_file_path)) + end + # Returns the default params. # @note Custom task_params will overwrite the defaults. # # @return [Hash] the default params. def default_params - @default_params ||= self.params['all'] + @default_params ||= (self.params['all'] || {}) end # Returns the custom params for the given task. # @note default_params will be used for undefined keys. # @@ -94,10 +110,27 @@ # @return [Hash] the Task custom params. def task_params(task_name) self.default_params.merge(self.params[task_name] || {}) end + + # Returns de task hints (tasks to be executed) or an empty array if they are not defined. + # + # @return [<String>] the task hints + def task_hints + @task_hints ||= self.load_task_hints + end + + # Loads and parses the @opts[:hints] params, if they exists. + # + # @return [<String>] the execution params. + def load_task_hints + return [] unless File.exists?(self.hints_file_path) + + JSON.parse(File.read(self.hints_file_path)) + end + # Load and parses the henry-context.yml params. # # @return [{String => String}] the execution context. def context @context ||= OpenStruct.new(YAML.load_file('henry-context.yml')) @@ -105,10 +138,25 @@ # Returns the tasks to be executed based on the context. # # @return [<Task>] tasks to be executed. def tasks - @tasks ||= self.context.tasks.collect { |task_data| Task.create(task_data["name"], task_data) } + @tasks ||= self.build_tasks + end + + # Builds and disables the Tasks to be executed based on the context and hints. + # + # @return [<Task>] tasks to be executed. + def build_tasks + tasks = self.context.tasks.collect do |task_data| + Task.create(task_data["name"], task_data) + end + + return tasks if self.task_hints.empty? + + tasks.each do |task| + task.disable! unless self.task_hints.include? task.name + end end # Returns the execution's current results. # # @return [Hash] the execution's current resutls.